Problem solve Get help with specific problems with your technologies, process and projects.

Copy existing users to temporary user 'ZZZ' using BDC

Here's a way to copy existing users to temporary user 'ZZZ' using BDC.

Here's a way to copy existing users to temporary user 'ZZZ' using BDC. The code was written in 4.6C, but should...

work for other versions as well with slight modification.


* Version 0001                             Date: 20-Jan-2003
report zsu01_copy_user message-id 01.

include zbdcincl.

data: v_passw(8) type c.

parameters:
  p_bname1 like usr02-bname default sy-uname
, p_bname2 like usr02-bname default 'ZZZ'
.

initialization.
  write sy-datum to v_passw.

at selection-screen.
  if p_bname1 is initial or p_bname2 is initial.
    message e264.
  endif.
  call function 'SUSR_USER_CHECK_EXISTENCE'
       exporting  user_name            = p_bname2
       exceptions user_name_not_exists = 1
                  others               = 2.
  if sy-subrc = 0.
    message e224 with p_bname2.
  endif.

start-of-selection.
  dyn 'SAPLSUU5'         '0050'.
  fld 'BDC_CURSOR'       'USR02-BNAME'.
  fld 'BDC_OKCODE'       '=COPY'.
  fld 'USR02-BNAME'       p_bname1.

  dyn 'SAPLSUU5'         '0200'.
  fld 'BDC_CURSOR'       'CHECK_ADDRESS'.
  fld 'BDC_OKCODE'       '=COPY'.
  fld 'USR01-BNAME'       p_bname1.
  fld 'USR02-BNAME'       p_bname2.
  fld 'CHECK_ADDRESS'    'X'.
  fld 'CHECK_DEFAULTS'   'X'.
  fld 'CHECK_PARAMETERS' 'X'.
  fld 'CHECK_ACTGRP'     'X'.
  fld 'CHECK_PROFILES'   'X'.
  fld 'CHECK_USERGROUPS' 'X'.
  fld 'CHECK_PERS'       'X'.

  dyn 'SAPLSUU5'         '0100'.
  fld 'BDC_OKCODE'       '=UPD'.
  fld 'BDC_CURSOR'       'G_PASSWORD2'.
  fld 'G_PASSWORD1'       v_passw.
  fld 'G_PASSWORD2'       v_passw.
  fld 'USLOGOND-CLASS'    space.
  fld 'USERTYPE1'        'X'.

  tra 'SU01'.


***INCLUDE ZBDCINCL .
* Version 0003                         Date: 20-Dec-2002
TABLES: T100.

*     Batchinputdata of single transaction
DATA: BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.

*     messages of call transaction
DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.

*     message texts
DATA: NODATA VALUE '/'.          "nodata

*-Display mode
DATA: CTUMODE LIKE CTU_PARAMS-DISMODE VALUE 'E'.
*             A: show all dynpros (default) 'A'
*             E: show dynpro on error only  'E'
*             N: do not display dynpro      'N'

*-Update mode
DATA: CUPDATE LIKE CTU_PARAMS-UPDMODE VALUE 'L'.
*             S: synchronously              'S'
*             A: asynchronously             'A'
*             L: local                      'L'

DATA: V_DATE1(10),                          "Start date as string
      V_DATE2 LIKE V_DATE1,                 "End   date as string
      V_DATUM LIKE SY-DATUM.

*-----------------------------------------------------------------------
FORM BDC_DYNPRO USING PROGRAM DYNPRO.       "Start new screen
  CLEAR BDCDATA.
  BDCDATA-PROGRAM  =  PROGRAM.
  BDCDATA-DYNPRO   =  DYNPRO.
  BDCDATA-DYNBEGIN = 'X'.
  APPEND BDCDATA.
ENDFORM. "BDC_DYNPRO
*-----------------------------------------------------------------------
FORM BDC_FIELD USING FNAM FVAL.             "Insert field
  IF FVAL <> NODATA.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
  ENDIF.
ENDFORM. "BDC_FIELD
*-----------------------------------------------------------------------
FORM CALL_TRANSACTION USING TCODE.          "Start new transaction
  DATA: L_MSTRING(480).
  REFRESH MESSTAB.
  CALL TRANSACTION TCODE USING         BDCDATA
                         MODE          CTUMODE
                         UPDATE        CUPDATE
                         MESSAGES INTO MESSTAB.
  LOOP AT MESSTAB.
    SELECT SINGLE * FROM T100 WHERE SPRSL = MESSTAB-MSGSPRA
                              AND   ARBGB = MESSTAB-MSGID
                              AND   MSGNR = MESSTAB-MSGNR.
    IF SY-SUBRC = 0.
      L_MSTRING = T100-TEXT.
      IF L_MSTRING CS '&1'.
        REPLACE '&1' WITH MESSTAB-MSGV1 INTO L_MSTRING.
        REPLACE '&2' WITH MESSTAB-MSGV2 INTO L_MSTRING.
        REPLACE '&3' WITH MESSTAB-MSGV3 INTO L_MSTRING.
        REPLACE '&4' WITH MESSTAB-MSGV4 INTO L_MSTRING.
      ELSE.
        REPLACE '&'  WITH MESSTAB-MSGV1 INTO L_MSTRING.
        REPLACE '&'  WITH MESSTAB-MSGV2 INTO L_MSTRING.
        REPLACE '&'  WITH MESSTAB-MSGV3 INTO L_MSTRING.
        REPLACE '&'  WITH MESSTAB-MSGV4 INTO L_MSTRING.
      ENDIF.
      CONDENSE L_MSTRING.
      WRITE: / MESSTAB-MSGTYP, L_MSTRING(250).
    ELSE.
      WRITE: / MESSTAB.
    ENDIF.
  ENDLOOP.
  SKIP.
ENDFORM. "CALL_TRANSACTION
*-----------------------------------------------------------------------
FORM RUN USING VALUE(V_TCODE) LIKE SY-TCODE.
  CALL TRANSACTION V_TCODE USING BDCDATA MODE CTUMODE.
ENDFORM. "RUN
*-----------------------------------------------------------------------
DEFINE DYN.
  PERFORM BDC_DYNPRO USING &1 &2.
END-OF-DEFINITION. "DYN
*-----------------------------------------------------------------------
DEFINE FLD.
  PERFORM BDC_FIELD  USING &1 &2.
END-OF-DEFINITION. "FLD
*-----------------------------------------------------------------------
DEFINE TRA.
  PERFORM RUN        USING &1.
END-OF-DEFINITION. "TRA
*-----------------------------------------------------------------------

This was last published in February 2003

Dig Deeper on SAP ABAP

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchHRSoftware

Close