REPORT Z_USER_IMPORT. TABLES:E070. DATA: BDCDATA LIKE BDCDATA OCCURS 0 WITH HEADER LINE. DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE. DATA: P_SN TYPE I. **** DATA: W_DOCID TYPE DSVASDOCID, W_EXTENSION TYPE DSVASDOCID, W_FIELDNAME TYPE STRING, *** * p_file LIKE rlgrap-filename, "???? IT_FILE TYPE FILETABLE, * p_file TYPE string, "???? P_FLAG(1), W_FILE_RC TYPE I. DATA:BEGIN OF IT_DATA OCCURS 0, BNAME(12), " ??ID PW(15), "?? NAME_FIRST(40), " ? NAME_LAST(40), " ? TITLE(20), "?? DEPARTMENT(20), " ?? TEL(12), "?? ADD_MAIL(50), "?? COSTNUMBER(8), "cost center OAID(20), END OF IT_DATA. DATA: GET_DATA TYPE ALSMEX_TABLINE OCCURS 0 WITH HEADER LINE. SELECTION-SCREEN BEGIN OF BLOCK SELE1 WITH FRAME TITLE TEXT-001. PARAMETERS: CTUMODE LIKE CTU_PARAMS-DISMODE DEFAULT 'E', " BDC???? "p_pw(12) DEFAULT 'abc@123', " ???? P_LANGU TYPE XULANGU DEFAULT SY-LANGU, " ?????? P_DCPFM TYPE XUDCPFM AS LISTBOX VISIBLE LENGTH 20 DEFAULT 'X', " ???????? P_DATFM TYPE XUDATFM AS LISTBOX VISIBLE LENGTH 20 DEFAULT '4', " ?????? P_TIMEFM TYPE XUTIMEFM AS LISTBOX VISIBLE LENGTH 20 DEFAULT '0', " ?????? P_SPLD LIKE USDEFAULTS-SPLD DEFAULT 'LP01', " ?????? P_SPDB AS CHECKBOX DEFAULT 'X', " ???? P_SPDA AS CHECKBOX . " ????? PARAMETERS: P_FILE LIKE RLGRAP-FILENAME DEFAULT '选择导入的文件'. SELECTION-SCREEN END OF BLOCK SELE1. SELECTION-SCREEN BEGIN OF BLOCK SELE2. PARAMETERS: S_ROW_B TYPE I DEFAULT 1, S_ROW_E TYPE I DEFAULT 1000. SELECTION-SCREEN END OF BLOCK SELE2. AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE. PERFORM FRM_OPEN_FILE. START-OF-SELECTION. *& ???? PERFORM FRM_TIDY_DATA. *& ??BDC?? PERFORM FRM_BDC_DATA. *&---------------------------------------------------------------------* *& Form frm_open_file *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* FORM FRM_OPEN_FILE. CALL FUNCTION 'WS_FILENAME_GET' EXPORTING DEF_FILENAME = 'xxx.xlsx' DEF_PATH = 'D:\' MODE = 'O' IMPORTING FILENAME = P_FILE EXCEPTIONS INV_WINSYS = 1 NO_BATCH = 2 SELECTION_CANCEL = 3 SELECTION_ERROR = 4 OTHERS = 5. IF SY-SUBRC <> 0. EXIT. ENDIF. * CALL METHOD cl_gui_frontend_services=>file_open_dialog * EXPORTING * window_title = 'Select the File' * default_filename = '*.XlSX' * initial_directory = 'C:\' * multiselection = ' ' "No multiple selection * CHANGING * file_table = it_file * rc = w_file_rc ** USER_ACTION = * EXCEPTIONS * file_open_dialog_failed = 1 * cntl_error = 2 * error_no_gui = 3 * not_supported_by_gui = 4 * OTHERS = 5. * IF sy-subrc <> 0. * MESSAGE s398(00) WITH 'Error Opening File' . * STOP. * ELSE . * READ TABLE it_file INDEX 1 INTO p_file . * ENDIF. ENDFORM. "frm_open_file *&---------------------------------------------------------------------* *& Form FRM_TIDY_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_TIDY_DATA . * REFRESH it_data. * IF p_file = ''. * MESSAGE s398(00) WITH '???????'. * STOP. * ENDIF. CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' *??EXCEL????? EXPORTING FILENAME = P_FILE I_BEGIN_COL = 1 I_BEGIN_ROW = S_ROW_B I_END_COL = 10 I_END_ROW = S_ROW_E TABLES INTERN = GET_DATA. DELETE GET_DATA WHERE ROW = 1. SORT GET_DATA BY ROW COL VALUE. ENDFORM. " FRM_TIDY_DATA *&---------------------------------------------------------------------* *& Form FRM_BDC_DATA *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * --> p1 text * <-- p2 text *----------------------------------------------------------------------* FORM FRM_BDC_DATA . "SORT it_data BY bname. DATA:LV_BNAME LIKE USR01-BNAME, LV_CHAN TYPE C. LOOP AT GET_DATA. CASE GET_DATA-COL. WHEN 1. IT_DATA-BNAME = GET_DATA-VALUE. WHEN 2. IT_DATA-PW = GET_DATA-VALUE. WHEN 3. IT_DATA-NAME_FIRST = GET_DATA-VALUE. WHEN 4. IT_DATA-NAME_LAST = GET_DATA-VALUE. WHEN 5. IT_DATA-TITLE = GET_DATA-VALUE. WHEN 6. IT_DATA-DEPARTMENT = GET_DATA-VALUE. WHEN 7. IT_DATA-COSTNUMBER = GET_DATA-VALUE. WHEN 8. IT_DATA-TEL = GET_DATA-VALUE. WHEN 9. IT_DATA-ADD_MAIL = GET_DATA-VALUE. WHEN 10. IT_DATA-OAID = GET_DATA-VALUE. ENDCASE. AT END OF ROW. APPEND IT_DATA. CLEAR IT_DATA. ENDAT. ENDLOOP. "loop at it_data. "write: it_data-bname,it_data-pw,it_data-name_first,it_data-name_last,it_data-title,it_data-department,it_data-tel,it_data-add_mail,it_data-agr_name. "write /. "endloop. LOOP AT IT_DATA. AT NEW BNAME. CLEAR LV_CHAN. *&--> ???? READ TABLE IT_DATA INDEX SY-TABIX. PERFORM BDC_DYNPRO USING 'SAPLSUID_MAINTENANCE' '1050'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'SUID_ST_BNAME-BNAME'. SELECT SINGLE BNAME INTO LV_BNAME FROM USR01 WHERE BNAME = IT_DATA-BNAME. IF SY-SUBRC = 0. LV_CHAN = 'X'. ENDIF. IF LV_CHAN = 'X'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=CHAN'. ELSE. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=CREA'. ENDIF. PERFORM BDC_FIELD USING 'SUID_ST_BNAME-BNAME' IT_DATA-BNAME. *& ?? PERFORM BDC_DYNPRO USING 'SAPLSUID_MAINTENANCE' '1100'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=LOGO'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'SUID_ST_NODE_COMM_DATA-SMTP_ADDR'. PERFORM BDC_FIELD USING 'SUID_ST_NODE_PERSON_NAME-NAME_LAST'"? IT_DATA-NAME_LAST. PERFORM BDC_FIELD USING 'SUID_ST_NODE_PERSON_NAME-NAME_FIRST' " ? IT_DATA-NAME_FIRST. PERFORM BDC_FIELD USING 'SUID_ST_NODE_WORKPLACE-FUNCTION' " ???? IT_DATA-TITLE. PERFORM BDC_FIELD USING 'SUID_ST_NODE_WORKPLACE-DEPARTMENT' " ?? IT_DATA-DEPARTMENT. PERFORM BDC_FIELD USING 'SUID_ST_NODE_COMM_DATA-TEL_NUMBER' " ?? IT_DATA-TEL. PERFORM BDC_FIELD USING 'SUID_ST_NODE_COMM_DATA-SMTP_ADDR' " ?? IT_DATA-ADD_MAIL. PERFORM BDC_FIELD USING 'SUID_ST_NODE_WORKPLACE-ROOMNUMBER' " ?? IT_DATA-OAID. *& ???? PERFORM BDC_DYNPRO USING 'SAPLSUID_MAINTENANCE' '1100'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=DEFA'. IF LV_CHAN = ' '. PERFORM BDC_FIELD USING 'SUID_ST_NODE_LOGONDATA-USTYP' 'A'. PERFORM BDC_FIELD USING 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD' " ???? IT_DATA-PW. PERFORM BDC_FIELD USING 'SUID_ST_NODE_PASSWORD_EXT-PASSWORD2' IT_DATA-PW. ENDIF. PERFORM BDC_FIELD USING 'SUID_ST_NODE_LOGONDATA-KOSTL' IT_DATA-COSTNUMBER. *& ??? PERFORM BDC_DYNPRO USING 'SAPLSUID_MAINTENANCE' '1100'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=ACTG'. PERFORM BDC_FIELD USING 'BDC_CURSOR' 'SUID_ST_NODE_DEFAULTS-SPDA'. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-LANGU' P_LANGU. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-DCPFM' P_DCPFM. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-DATFM' P_DATFM. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-TIMEFM' P_TIMEFM. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-SPLD' P_SPLD. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-SPDB' P_SPDB. PERFORM BDC_FIELD USING 'SUID_ST_NODE_DEFAULTS-SPDA' P_SPDA. ENDAT. *&--> ???? * PERFORM bdc_dynpro USING 'SAPLSDH4' '0200'. * PERFORM bdc_field USING 'BDC_OKCODE' * '=GOON'. * PERFORM bdc_field USING 'BDC_CURSOR' * 'G_SELFLD_TAB-LOW(01)'. * PERFORM bdc_field USING 'DDSHF4CTRL-MAXRECORDS' * '500'. * PERFORM bdc_field USING 'G_SELFLD_TAB-LOW(01)' * 'z:0000_Base_SI_001'. * * PERFORM bdc_dynpro USING 'SAPMSSY0' '0120'. * PERFORM bdc_field USING 'BDC_CURSOR' * '04/03'. * PERFORM bdc_field USING 'BDC_OKCODE' * '=ENTR'. * * PERFORM bdc_dynpro USING 'SAPLSUID_MAINTENANCE' '1100'. * PERFORM bdc_field USING 'BDC_OKCODE' * '=ENTER'. *& ???? AT END OF BNAME. PERFORM BDC_DYNPRO USING 'SAPLSUID_MAINTENANCE' '1100'. PERFORM BDC_FIELD USING 'BDC_OKCODE' '=UPD'. CALL TRANSACTION 'SU01' USING BDCDATA MODE CTUMODE MESSAGES INTO MESSTAB. READ TABLE MESSTAB WITH KEY MSGTYP = 'S' MSGID = '01' MSGNR = '226'. IF SY-SUBRC = 0. WRITE:/ MESSTAB-MSGV1, '??????'. ENDIF. CLEAR:BDCDATA[],BDCDATA,MESSTAB[],MESSTAB. ENDAT. ENDLOOP. ENDFORM. " FRM_BDC_DATA *&---------------------------------------------------------------------* *& Form bdc_dynpro *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->PROGRAM text * -->DYNPRO text *----------------------------------------------------------------------* FORM BDC_DYNPRO USING PROGRAM DYNPRO. CLEAR BDCDATA. BDCDATA-PROGRAM = PROGRAM. BDCDATA-DYNPRO = DYNPRO. BDCDATA-DYNBEGIN = 'X'. APPEND BDCDATA. ENDFORM. "BDC_DYNPRO *&---------------------------------------------------------------------* *& Form bdc_field *&---------------------------------------------------------------------* * text *----------------------------------------------------------------------* * -->FNAM text * -->FVAL text *----------------------------------------------------------------------* FORM BDC_FIELD USING FNAM FVAL. CLEAR BDCDATA. BDCDATA-FNAM = FNAM. BDCDATA-FVAL = FVAL. APPEND BDCDATA. ENDFORM. "BDC_FIELD
标签:批量,BDC,SUID,PERFORM,FIELD,ABAP,导入,USING,DATA From: https://www.cnblogs.com/ZJY-1314/p/17439843.html