2023 Jun 22 11:44 AM
Hi, I am creating a program to upload users from a text file into SAP. The code is throwing up errors, and probably needs a little optimization. Your help appreciated. Here is the code, followed by the errors:
REPORT Z_USER_CREATE.
DATA: lv_filename TYPE string,
lv_file_content TYPE string,
lt_users TYPE TABLE OF sy-uname.
PARAMETERS: p_file TYPE rlgrap-filename.
START-OF-SELECTION.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = p_file
filetype = 'ASC'
CHANGING
data_tab = lt_users
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_users INTO DATA(ls_user).
CREATE OBJECT ls_user TYPE bapiuser.
ls_user-username = ls_user.
" Set additional user data if required
APPEND ls_user TO lt_users.
ENDLOOP.
CALL FUNCTION 'BAPI_USER_CREATE1'
EXPORTING
user_tab = lt_users
EXCEPTIONS
user_name_exist = 1
user_lock = 2
password_generation_failed = 3
profile_creation_failed = 4
parameter_error = 5
OTHERS = 6.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSE.
COMMIT WORK.
WRITE: 'Users uploaded successfully.'.
ENDIF.
Errors:
2023 Jun 22 6:47 PM
2023 Jun 23 4:35 AM
not sure what version is your sap, but some weird thing you have done
1. BAPI_USER_CREATE1 does not have the importing user_tab parameter, are you using the right FM?
2. code below is really weird,
- you have created the ls_user with the same type as lt_users, but you wanted to change the workarea into another type, then you wanted to append workarea into itab with different structure, why?
LOOP AT lt_users INTO DATA(ls_user).
CREATE OBJECT ls_user TYPE bapiuser.
ls_user-username = ls_user.
APPEND ls_user TO lt_users.
ENDLOOP.
2023 Jun 23 8:36 AM
Hi Guys
Thanks for the answers.... and questions....I am trying to upload a list of users from a text file and create them en masse in SAP. Kindly if you could rewrite the above code to optimize it for me, I would highly appreciate.
Thanks very much.
2023 Jun 23 12:42 PM
Some steps
2023 Jun 26 8:13 AM