Moin.
Einen elgante Methode zum User kopieren/Ändern/Anlegen bieten eingentlich nur die BAPI Funktionsbausteine:
Man kann genau bestimmen, welche User kopiert werden sollen und das Ganze als Job laufen lassen.
Rollen kopieren ginge dann separat mit BAPI_USER_ACTGROUPS_ASSIGN.
Beispiel USER COPY System A nach System B per RFC ohne Rollen.
*&---------------------------------------------------------------------*
*& Report ZCOPY_USER
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zcopy_user2.
TABLES: sscrfields,usr02.
TYPE-POOLS: icon.
* Info Destinationen
DATA: des1_info TYPE rfcsi,
des2_info TYPE rfcsi.
START-OF-SELECTION.
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.
PARAMETERS p_des1 TYPE rfcdes-rfcdest OBLIGATORY DEFAULT 'NONE'.
SELECTION-SCREEN END OF BLOCK b.
SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-002.
PARAMETERS p_des2 TYPE rfcdes-rfcdest OBLIGATORY DEFAULT 'NONE'.
SELECTION-SCREEN END OF BLOCK a.
SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-003.
PARAMETERS password TYPE bapipwd OBLIGATORY LOWER CASE DEFAULT 'Berlin4$'.
SELECT-OPTIONS bname FOR usr02-bname NO INTERVALS.
SELECTION-SCREEN END OF BLOCK c.
END-OF-SELECTION.
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_display = ' '
i_refresh = 'X'
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
LOOP AT bname.
PERFORM copy_user USING bname-low.
ENDLOOP.
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_display = 'X'
i_refresh = 'X'
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
EXIT.
* PERFORM check_avail.
**&---------------------------------------------------------------------*
**& Form Check_avail
**&---------------------------------------------------------------------*
** text
**----------------------------------------------------------------------*
** -->DEST text
**----------------------------------------------------------------------*
*FORM check_avail.
* DATA:
*" info LIKE rfcsi,
* msg_text(80) TYPE c. "Message text
*
* CALL FUNCTION 'RFC_SYSTEM_INFO'
* DESTINATION p_des1
* IMPORTING
* rfcsi_export = des1_info
* EXCEPTIONS
* communication_failure = 1 MESSAGE msg_text
* system_failure = 2 MESSAGE msg_text.
*
* CALL FUNCTION 'RFC_SYSTEM_INFO'
* DESTINATION p_des2
* IMPORTING
* rfcsi_export = des2_info
* EXCEPTIONS
* communication_failure = 1 MESSAGE msg_text
* system_failure = 2 MESSAGE msg_text.
*
*ENDFORM. "Check_avail
*&---------------------------------------------------------------------*
*& Form write_for_display
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM write_for_display.
DATA: t1(80),t2(80).
DATA: info LIKE rfcsi,
msg_text(80) TYPE c. "Message text
FORMAT COLOR COL_HEADING.
WRITE: / '*** STATUS RFC-Erreichbarkeit ***' , AT sy-linsz space.
ULINE.
FORMAT COLOR OFF.
CLEAR msg_text.
CALL FUNCTION 'RFC_PING'
DESTINATION p_des2
EXCEPTIONS
communication_failure = 1 MESSAGE msg_text
system_failure = 2 MESSAGE msg_text.
t1 = p_des2.
CONDENSE t1.
IF msg_text IS INITIAL.
CONCATENATE 'Destination :' t1 'erreichbar.' INTO t2 SEPARATED BY space.
FORMAT INTENSIFIED OFF.
WRITE: / icon_led_green AS ICON,
t2 COLOR COL_POSITIVE.
ELSE.
CONCATENATE 'Destination :' t1 'nicht erreichbar.' INTO t2 SEPARATED BY space.
FORMAT INTENSIFIED OFF.
WRITE: / icon_led_red AS ICON,
t2 COLOR COL_NEGATIVE.
ENDIF.
CLEAR msg_text.
CALL FUNCTION 'RFC_PING'
DESTINATION p_des1
EXCEPTIONS
communication_failure = 1 MESSAGE msg_text
system_failure = 2 MESSAGE msg_text.
t1 = p_des1.
CONDENSE t1.
IF msg_text IS INITIAL.
CONCATENATE 'Destination :' t1 'erreichbar.' INTO t2 SEPARATED BY space.
FORMAT INTENSIFIED OFF.
WRITE: / icon_led_green AS ICON,
t2 COLOR COL_POSITIVE.
ELSE.
CONCATENATE 'Destination :' t1 'nicht erreichbar.' INTO t2 SEPARATED BY space.
FORMAT INTENSIFIED OFF.
WRITE: / icon_led_red AS ICON,
t2 COLOR COL_NEGATIVE.
ENDIF.
ENDFORM. "write_for_display
INITIALIZATION.
sscrfields-functxt_01 = '@38@ Check RFC-Desitinations'.
AT SELECTION-SCREEN.
IF sy-ucomm = 'FC01'." n = 1 up to 5
* Teste Erreichbarkeit
PERFORM write_for_display.
CALL FUNCTION 'C14A_POPUP_LIST_DISPLAY'
EXPORTING
i_callback = 'WRITE_FOR_DISPLAY'
i_callback_program = sy-repid
i_title = 'RFC-Verbindungen'
i_col = 4
i_row = 4
i_width = 84
i_height = 10
* I_TEXT_WIDTH =
* I_FLG_SHOW_PRINT_BUTTON = ESP1_FALSE
EXCEPTIONS
no_callback_specified = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
*&---------------------------------------------------------------------*
*& Form copy_user
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM copy_user USING uname TYPE usr02-bname.
DATA msg_text(80) TYPE c. "Message text
DATA dummy(80) TYPE c. "Message text
* Input
DATA username TYPE bapibname-bapibname.
* Output
DATA:
logondata LIKE bapilogond,
defaults LIKE bapidefaul,
address LIKE bapiaddr3,
company LIKE bapiuscomp,
snc LIKE bapisncu,
ref_user LIKE bapirefus,
alias LIKE bapialias,
uclass TYPE bapiuclass,
lastmodified TYPE bapimoddat,
islocked TYPE bapislockd.
*Tables
DATA:
parameter TYPE TABLE OF bapiparam,
profiles TYPE TABLE OF bapiprof,
activitygroups TYPE TABLE OF bapiagr,
return TYPE TABLE OF bapiret2,
addtel TYPE TABLE OF bapiadtel,
addfax TYPE TABLE OF bapiadfax,
addttx TYPE TABLE OF bapiadttx,
addtlx TYPE TABLE OF bapiadtlx,
addsmtp TYPE TABLE OF bapiadsmtp,
addrml TYPE TABLE OF bapiadrml,
addx400 TYPE TABLE OF bapiadx400,
addrfc TYPE TABLE OF bapiadrfc,
addprt TYPE TABLE OF bapiadprt,
addssf TYPE TABLE OF bapiadssf,
adduri TYPE TABLE OF bapiaduri,
addpag TYPE TABLE OF bapiadpag,
addcomrem TYPE TABLE OF bapicomrem,
parameter1 TYPE TABLE OF bapiparam1,
groups TYPE TABLE OF bapigroups,
uclasssys TYPE TABLE OF bapiuclasssys,
extidhead TYPE TABLE OF bapiusextidhead,
extidpart TYPE TABLE OF bapiusextidpart,
systems TYPE TABLE OF bapircvsys.
* RC
DATA lret1 TYPE bapiret2.
username = uname.
CALL FUNCTION 'BAPI_USER_GET_DETAIL' DESTINATION p_des2
EXPORTING
username = username
* CACHE_RESULTS = 'X'
IMPORTING
logondata = logondata
defaults = defaults
address = address
company = company
snc = snc
ref_user = ref_user
alias = alias
uclass = uclass
lastmodified = lastmodified
islocked = islocked
TABLES
parameter = parameter
profiles = profiles
activitygroups = activitygroups
return = return
addtel = addtel
addfax = addfax
addttx = addttx
addtlx = addtlx
addsmtp = addsmtp
addrml = addrml
addx400 = addx400
addrfc = addrfc
addprt = addprt
addssf = addssf
adduri = adduri
addpag = addpag
addcomrem = addcomrem
parameter1 = parameter1
groups = groups
uclasssys = uclasssys
extidhead = extidhead
extidpart = extidpart
systems = systems
EXCEPTIONS
communication_failure = 1 MESSAGE msg_text
system_failure = 2 MESSAGE msg_text.
IF sy-subrc NE 0.
EXIT.
ENDIF.
LOOP AT return INTO lret1.
lret1-number = '398'.
lret1-id = '00'.
lret1-message_v1 = username.
lret1-message_v2 = ' - '.
lret1-message_v3 = lret1-message.
*message i398(00) into dummy with lret1-MESSAGE ' ' ' ' ' ' .
*MESSAGE ID lret1-id TYPE lret1-type NUMBER lret1-number
* INTO dummy
* WITH 'TEST' sy-msgv2 sy-msgv3 sy-msgv4.
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_msgty = lret1-type
i_msgid = lret1-id
i_msgno = lret1-number
i_msgv1 = lret1-message_v1
i_msgv2 = lret1-message_v2
i_msgv3 = lret1-message_v3
i_msgv4 = lret1-message_v4
* I_DISPLAY = 'X'
* I_REFRESH = 'X'
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
ENDLOOP.
CLEAR lret1.
LOOP AT return INTO lret1 WHERE type = 'E'.
EXIT.
ENDLOOP.
CHECK lret1 IS INITIAL.
CLEAR logondata-class.
DELETE parameter WHERE parid(1) = 'Z' OR parid(1) = 'Y'.
DELETE parameter1 WHERE parid(1) = 'Z' OR parid(1) = 'Y'.
CALL FUNCTION 'BAPI_USER_CREATE1' DESTINATION p_des1
EXPORTING
username = username
* NAME_IN =
logondata = logondata
password = password
defaults = defaults
address = address
company = company
snc = snc
ref_user = ref_user
alias = alias
* EX_ADDRESS =
uclass = uclass
force_system_assignment = 'X'
* SELF_REGISTER = ' '
TABLES
parameter = parameter
return = return
addtel = addtel
addfax = addfax
addttx = addttx
addtlx = addtlx
addsmtp = addsmtp
addrml = addrml
addx400 = addx400
addrfc = addrfc
addprt = addprt
addssf = addssf
adduri = adduri
addpag = addpag
addcomrem = addcomrem
* groups = groups
parameter1 = parameter1
extidhead = extidhead
extidpart = extidpart
EXCEPTIONS
communication_failure = 1 MESSAGE msg_text
system_failure = 2 MESSAGE msg_text.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
LOOP AT return INTO lret1.
lret1-number = '398'.
lret1-id = '00'.
lret1-message_v1 = username.
lret1-message_v2 = ' - '.
lret1-message_v3 = lret1-message.
CALL FUNCTION 'Y_BAL_LOG'
EXPORTING
i_msgty = lret1-type
i_msgid = lret1-id
i_msgno = lret1-number
i_msgv1 = lret1-message_v4
i_msgv2 = lret1-message_v1
i_msgv3 = lret1-message_v2
i_msgv4 = lret1-message_v3
* I_DISPLAY = 'X'
* I_REFRESH = 'X'
i_repid = sy-repid
EXCEPTIONS
error_create = 1
error_add_message = 2
error_refresh = 3
error_display_profile = 4
error_display = 5
OTHERS = 6.
ENDLOOP.
ENDFORM. "copy_user