Copy User mit RFC X-System

Nützliche Abap Codes und Code Fragmente

Copy User mit RFC X-System

Postby Tron » Sun Jan 26, 2020 2:58 pm

ZCOPY_USER
Code: [Select all] [Expand/Collapse] [Download] (Untitled.txt)
  1. *&---------------------------------------------------------------------*
  2. *& Report  ZCOPY_USER
  3. *&
  4. *&---------------------------------------------------------------------*
  5. *&
  6. *&
  7. *&---------------------------------------------------------------------*
  8.  
  9. REPORT  zcopy_user2.
  10. TABLES: sscrfields,usr02.
  11.  
  12. TYPE-POOLS: icon.
  13. * Info Destinationen
  14. DATA: des1_info TYPE rfcsi,
  15.       des2_info TYPE rfcsi.
  16.  
  17.  
  18.   SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.
  19.   PARAMETERS p_des1 TYPE rfcdes-rfcdest OBLIGATORY DEFAULT 'NONE'.
  20.   SELECTION-SCREEN END OF BLOCK b.
  21.  
  22.   SELECTION-SCREEN BEGIN OF BLOCK a WITH FRAME TITLE text-002.
  23.   PARAMETERS p_des2 TYPE rfcdes-rfcdest OBLIGATORY DEFAULT 'NONE'.
  24.   SELECTION-SCREEN END OF BLOCK a.
  25.  
  26.   SELECTION-SCREEN BEGIN OF BLOCK c WITH FRAME TITLE text-003.
  27.   PARAMETERS password TYPE bapipwd OBLIGATORY LOWER CASE DEFAULT 'Berlin4$'.
  28.   SELECT-OPTIONS bname FOR usr02-bname NO INTERVALS.
  29.   SELECTION-SCREEN END OF BLOCK c.
  30.  
  31.  
  32.  
  33.   CALL FUNCTION 'Y_BAL_LOG'
  34.     EXPORTING
  35.       i_display             = ' '
  36.       i_refresh             = 'X'
  37.       i_repid               = sy-repid
  38.     EXCEPTIONS
  39.       error_create          = 1
  40.       error_add_message     = 2
  41.       error_refresh         = 3
  42.       error_display_profile = 4
  43.       error_display         = 5
  44.       OTHERS                = 6.
  45.  
  46.   LOOP AT bname.
  47.     PERFORM copy_user USING bname-low.
  48.  
  49.   CALL FUNCTION 'Y_BAL_LOG'
  50.     EXPORTING
  51.       i_display             = 'X'
  52.       i_refresh             = 'X'
  53.       i_repid               = sy-repid
  54.     EXCEPTIONS
  55.       error_create          = 1
  56.       error_add_message     = 2
  57.       error_refresh         = 3
  58.       error_display_profile = 4
  59.       error_display         = 5
  60.       OTHERS                = 6.
  61.  
  62.   EXIT.
  63. *  PERFORM check_avail.
  64.  
  65. **&---------------------------------------------------------------------*
  66. **&      Form  Check_avail
  67. **&---------------------------------------------------------------------*
  68. **       text
  69. **----------------------------------------------------------------------*
  70. **      -->DEST       text
  71. **----------------------------------------------------------------------*
  72. *FORM check_avail.
  73. *  DATA:
  74. *"  info LIKE rfcsi,
  75. *  msg_text(80) TYPE c. "Message text
  76. *
  77. *  CALL FUNCTION 'RFC_SYSTEM_INFO'
  78. *    DESTINATION p_des1
  79. *    IMPORTING
  80. *      rfcsi_export          = des1_info
  81. *    EXCEPTIONS
  82. *      communication_failure = 1  MESSAGE msg_text
  83. *      system_failure        = 2  MESSAGE msg_text.
  84. *
  85. *  CALL FUNCTION 'RFC_SYSTEM_INFO'
  86. *    DESTINATION p_des2
  87. *    IMPORTING
  88. *      rfcsi_export          = des2_info
  89. *    EXCEPTIONS
  90. *      communication_failure = 1  MESSAGE msg_text
  91. *      system_failure        = 2  MESSAGE msg_text.
  92. *
  93. *ENDFORM.                    "Check_avail
  94. *&---------------------------------------------------------------------*
  95. *&      Form  write_for_display
  96. *&---------------------------------------------------------------------*
  97. *       text
  98. *----------------------------------------------------------------------*
  99. FORM write_for_display.
  100.   DATA: t1(80),t2(80).
  101.   DATA: info LIKE rfcsi,
  102.         msg_text(80) TYPE c. "Message text
  103.  
  104.   FORMAT COLOR COL_HEADING.
  105.   WRITE: / '*** STATUS RFC-Erreichbarkeit ***' , AT sy-linsz space.
  106.   ULINE.
  107.   FORMAT COLOR OFF.
  108.  
  109.   CLEAR msg_text.
  110.   CALL FUNCTION 'RFC_PING'
  111.     DESTINATION p_des2
  112.     EXCEPTIONS
  113.       communication_failure = 1  MESSAGE msg_text
  114.       system_failure        = 2  MESSAGE msg_text.
  115.  
  116.  
  117.   t1 = p_des2.
  118.   CONDENSE t1.
  119.  
  120.   IF msg_text IS INITIAL.
  121.     CONCATENATE 'Destination :' t1 'erreichbar.' INTO t2 SEPARATED BY space.
  122.     FORMAT INTENSIFIED OFF.
  123.  
  124.     WRITE: / icon_led_green AS ICON,
  125.                 t2 COLOR COL_POSITIVE.
  126.  
  127.   ELSE.
  128.     CONCATENATE 'Destination :' t1 'nicht erreichbar.' INTO t2 SEPARATED BY space.
  129.     FORMAT INTENSIFIED OFF.
  130.  
  131.     WRITE: /      icon_led_red AS ICON,
  132.                   t2 COLOR COL_NEGATIVE.
  133.  
  134.   ENDIF.
  135.  
  136.   CLEAR msg_text.
  137.   CALL FUNCTION 'RFC_PING'
  138.     DESTINATION p_des1
  139.     EXCEPTIONS
  140.       communication_failure = 1  MESSAGE msg_text
  141.       system_failure        = 2  MESSAGE msg_text.
  142.  
  143.  
  144.   t1 = p_des1.
  145.   CONDENSE t1.
  146.  
  147.   IF msg_text IS INITIAL.
  148.     CONCATENATE 'Destination :' t1 'erreichbar.' INTO t2 SEPARATED BY space.
  149.     FORMAT INTENSIFIED OFF.
  150.  
  151.     WRITE: / icon_led_green AS ICON,
  152.                 t2 COLOR COL_POSITIVE.
  153.  
  154.   ELSE.
  155.     CONCATENATE 'Destination :' t1 'nicht erreichbar.' INTO t2 SEPARATED BY space.
  156.     FORMAT INTENSIFIED OFF.
  157.  
  158.     WRITE: /      icon_led_red AS ICON,
  159.                   t2 COLOR COL_NEGATIVE.
  160.  
  161.   ENDIF.
  162.  
  163. ENDFORM.                    "write_for_display
  164.  
  165.  
  166.  
  167.   sscrfields-functxt_01 = '@38@ Check RFC-Desitinations'.
  168.  
  169. AT SELECTION-SCREEN.
  170.   IF sy-ucomm = 'FC01'." n = 1 up to 5
  171. * Teste Erreichbarkeit
  172.  
  173.     PERFORM write_for_display.
  174.  
  175.     CALL FUNCTION 'C14A_POPUP_LIST_DISPLAY'
  176.       EXPORTING
  177.         i_callback                    = 'WRITE_FOR_DISPLAY'
  178.         i_callback_program            = sy-repid
  179.         i_title                       = 'RFC-Verbindungen'
  180.         i_col                         = 4
  181.         i_row                         = 4
  182.         i_width                       = 84
  183.         i_height                      = 10
  184. *   I_TEXT_WIDTH                  =
  185. *   I_FLG_SHOW_PRINT_BUTTON       = ESP1_FALSE
  186.      EXCEPTIONS
  187.        no_callback_specified         = 1
  188.        OTHERS                        = 2.
  189.  
  190.     IF sy-subrc <> 0.
  191.       MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
  192.               WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  193.     ENDIF.
  194.   ENDIF.
  195.  
  196.  
  197. *&---------------------------------------------------------------------*
  198. *&      Form  copy_user
  199. *&---------------------------------------------------------------------*
  200. *       text
  201. *----------------------------------------------------------------------*
  202. FORM copy_user USING uname TYPE usr02-bname.
  203.   DATA  msg_text(80) TYPE c. "Message text
  204.   DATA  dummy(80) TYPE c. "Message text
  205.  
  206. * Input
  207.   DATA username TYPE bapibname-bapibname.
  208.  
  209. * Output
  210.   DATA:
  211.   logondata LIKE bapilogond,
  212.   defaults LIKE bapidefaul,
  213.   address LIKE bapiaddr3,
  214.   company LIKE bapiuscomp,
  215.   snc LIKE bapisncu,
  216.   ref_user LIKE bapirefus,
  217.   alias LIKE bapialias,
  218.   uclass TYPE bapiuclass,
  219.   lastmodified TYPE bapimoddat,
  220.   islocked TYPE bapislockd.
  221.  
  222. *Tables
  223.   DATA:
  224.   parameter TYPE TABLE OF bapiparam,
  225.   profiles TYPE TABLE OF bapiprof,
  226.   activitygroups TYPE TABLE OF bapiagr,
  227.   return TYPE TABLE OF bapiret2,
  228.   addtel TYPE TABLE OF bapiadtel,
  229.   addfax TYPE TABLE OF bapiadfax,
  230.   addttx TYPE TABLE OF bapiadttx,
  231.   addtlx TYPE TABLE OF bapiadtlx,
  232.   addsmtp TYPE TABLE OF bapiadsmtp,
  233.   addrml TYPE TABLE OF bapiadrml,
  234.   addx400 TYPE TABLE OF bapiadx400,
  235.   addrfc TYPE TABLE OF bapiadrfc,
  236.   addprt TYPE TABLE OF bapiadprt,
  237.   addssf TYPE TABLE OF bapiadssf,
  238.   adduri TYPE TABLE OF bapiaduri,
  239.   addpag TYPE TABLE OF bapiadpag,
  240.   addcomrem TYPE TABLE OF bapicomrem,
  241.   parameter1 TYPE TABLE OF bapiparam1,
  242.   groups TYPE TABLE OF bapigroups,
  243.   uclasssys TYPE TABLE OF bapiuclasssys,
  244.   extidhead TYPE TABLE OF bapiusextidhead,
  245.   extidpart TYPE TABLE OF bapiusextidpart,
  246.   systems TYPE TABLE OF bapircvsys.
  247.  
  248. * RC
  249.   DATA lret1 TYPE bapiret2.
  250.  
  251.   username = uname.
  252.  
  253.   CALL FUNCTION 'BAPI_USER_GET_DETAIL' DESTINATION p_des2
  254.     EXPORTING
  255.       username             = username
  256. *       CACHE_RESULTS        = 'X'
  257.    IMPORTING
  258.      logondata            = logondata
  259.      defaults             = defaults
  260.      address              = address
  261.      company              = company
  262.      snc                  = snc
  263.      ref_user             = ref_user
  264.      alias                = alias
  265.      uclass               = uclass
  266.      lastmodified         = lastmodified
  267.      islocked             = islocked
  268.     TABLES
  269.      parameter            = parameter
  270.      profiles             = profiles
  271.      activitygroups       = activitygroups
  272.      return               = return
  273.      addtel               = addtel
  274.      addfax               = addfax
  275.      addttx               = addttx
  276.      addtlx               = addtlx
  277.      addsmtp              = addsmtp
  278.      addrml               = addrml
  279.      addx400              = addx400
  280.      addrfc               = addrfc
  281.      addprt               = addprt
  282.      addssf               = addssf
  283.      adduri               = adduri
  284.      addpag               = addpag
  285.      addcomrem            = addcomrem
  286.      parameter1           = parameter1
  287.      groups               = groups
  288.      uclasssys            = uclasssys
  289.      extidhead            = extidhead
  290.      extidpart            = extidpart
  291.      systems              = systems
  292.   EXCEPTIONS
  293.     communication_failure = 1  MESSAGE msg_text
  294.     system_failure        = 2  MESSAGE msg_text.
  295.  
  296.   IF sy-subrc NE 0.
  297.     EXIT.
  298.   ENDIF.
  299.  
  300.   LOOP AT return INTO lret1.
  301.     lret1-number = '398'.
  302.     lret1-id = '00'.
  303.     lret1-message_v1 = username.
  304.     lret1-message_v2 = ' - '.
  305.     lret1-message_v3 = lret1-message.
  306.  
  307. *message i398(00) into dummy  with lret1-MESSAGE ' ' ' ' ' ' .
  308.  
  309. *MESSAGE ID lret1-id TYPE lret1-type NUMBER lret1-number
  310. *                INTO dummy
  311. *                WITH 'TEST' sy-msgv2 sy-msgv3 sy-msgv4.
  312.  
  313.     CALL FUNCTION 'Y_BAL_LOG'
  314.       EXPORTING
  315.         i_msgty               = lret1-type
  316.         i_msgid               = lret1-id
  317.         i_msgno               = lret1-number
  318.         i_msgv1               = lret1-message_v1
  319.         i_msgv2               = lret1-message_v2
  320.         i_msgv3               = lret1-message_v3
  321.         i_msgv4               = lret1-message_v4
  322. *    I_DISPLAY             = 'X'
  323. *    I_REFRESH             = 'X'
  324.         i_repid               = sy-repid
  325.       EXCEPTIONS
  326.         error_create          = 1
  327.         error_add_message     = 2
  328.         error_refresh         = 3
  329.         error_display_profile = 4
  330.         error_display         = 5
  331.         OTHERS                = 6.
  332.  
  333.  
  334.   CLEAR lret1.
  335.   LOOP AT return INTO lret1 WHERE type = 'E'.
  336.     EXIT.
  337.  
  338.   CHECK lret1 IS INITIAL.
  339.  
  340.  
  341.   CLEAR logondata-class.
  342.   DELETE parameter  WHERE parid(1) = 'Z' OR parid(1) = 'Y'.
  343.   DELETE parameter1 WHERE parid(1) = 'Z' OR parid(1) = 'Y'.
  344.  
  345.   CALL FUNCTION 'BAPI_USER_CREATE1' DESTINATION p_des1
  346.     EXPORTING
  347.       username                      = username
  348. *   NAME_IN                       =
  349.       logondata                     = logondata
  350.       password                      = password
  351.       defaults                      = defaults
  352.       address                       = address
  353.      company                       = company
  354.      snc                           = snc
  355.      ref_user                      = ref_user
  356.      alias                         = alias
  357. *   EX_ADDRESS                    =
  358.       uclass                        = uclass
  359.     force_system_assignment       = 'X'
  360. *   SELF_REGISTER                 = ' '
  361.    TABLES
  362.        parameter            = parameter
  363.        return               = return
  364.        addtel               = addtel
  365.        addfax               = addfax
  366.        addttx               = addttx
  367.        addtlx               = addtlx
  368.        addsmtp              = addsmtp
  369.        addrml               = addrml
  370.        addx400              = addx400
  371.        addrfc               = addrfc
  372.        addprt               = addprt
  373.        addssf               = addssf
  374.        adduri               = adduri
  375.        addpag               = addpag
  376.        addcomrem            = addcomrem
  377. *       groups               = groups
  378.        parameter1           = parameter1
  379.        extidhead            = extidhead
  380.        extidpart            = extidpart
  381.     EXCEPTIONS
  382.       communication_failure = 1  MESSAGE msg_text
  383.       system_failure        = 2  MESSAGE msg_text.
  384.  
  385.  
  386.   CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
  387.  
  388.   LOOP AT return INTO lret1.
  389.     lret1-number = '398'.
  390.     lret1-id = '00'.
  391.     lret1-message_v1 = username.
  392.     lret1-message_v2 = ' - '.
  393.     lret1-message_v3 = lret1-message.
  394.  
  395.     CALL FUNCTION 'Y_BAL_LOG'
  396.       EXPORTING
  397.         i_msgty               = lret1-type
  398.         i_msgid               = lret1-id
  399.         i_msgno               = lret1-number
  400.         i_msgv1               = lret1-message_v4
  401.         i_msgv2               = lret1-message_v1
  402.         i_msgv3               = lret1-message_v2
  403.         i_msgv4               = lret1-message_v3
  404. *    I_DISPLAY             = 'X'
  405. *    I_REFRESH             = 'X'
  406.         i_repid               = sy-repid
  407.       EXCEPTIONS
  408.         error_create          = 1
  409.         error_add_message     = 2
  410.         error_refresh         = 3
  411.         error_display_profile = 4
  412.         error_display         = 5
  413.         OTHERS                = 6.
  414.  
  415.  
  416. ENDFORM.                    "copy_user
GeSHi ©
Tron
.....
.....
 
Posts: 1098
Joined: Sat Aug 04, 2007 10:21 pm

Return to Code Snippets

Who is online

Users browsing this forum: No registered users and 0 guests

cron
  • Latest Topics