首页 > 其他分享 >ABAP 用户批量导入

ABAP 用户批量导入

时间:2023-05-29 11:01:20浏览次数:44  
标签:批量 BDC SUID PERFORM FIELD ABAP 导入 USING DATA

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

相关文章

  • ABAP 用户权限查询报表
    *&---------------------------------------------------------------------**&REPORTZUSER*&---------------------------------------------------------------------**&*&--------------------------------------------------------------------......
  • ABAP 用户角色导入
    *&---------------------------------------------------------------------**&ReportZ_USER_ROLES_IMPORT*&---------------------------------------------------------------------**&*&------------------------------------------------------......
  • ABAP 通用自建表批到
    *&---------------------------------------------------------------------**&ReportZUPLOAD_TABLE*&---------------------------------------------------------------------**&*&------------------------------------------------------------......
  • Node模块导入规则总结
    @目录node模块总结node模块引入的步骤:模块分类node支持的模块系统ESModuleCommonJS模块加载CommonJS模块引入路径分析文件定位带扩展名的文件定位不带扩展名的文件定位ESM模块引入路径分析文件定位带路径不带路径(裸说明符)模块加载器总结对比CommonJS模块加载器ECMAScript模块加......
  • RefsUtil 是 Windows 下一款用于管理 REFS 文件系统的实用工具,它提供了丰富的功能和命
    RefsUtil是Windows下一款用于管理REFS文件系统的实用工具,它提供了丰富的功能和命令行界面,可用于创建、修改、检查和修复REFS分区,以及导出和导入数据等操作。以下是一些使用RefsUtil工具的示例:创建REFS分区要创建一个新的REFS分区,可以使用以下命令:CopyCoderef......
  • MKVToolNix工具批量修改MKV文件信息
    1.需求:有一部港剧,50集,mkv格式,国语和粤语双音轨,原文件默认播放国语音轨,现在要批量设置粤语为默认播放音轨,同时给视频轨道设置语言为中文。如果使用图形界面手动修改,则需要大量时间,现在寻求使用MKVToolNix的命令行工具,来进行批量操作,命令行工具mkvpropedit官方说明链接:https://mkvto......
  • 第一次写一篇与技术无关的博客-大批量数据处理
    上周接到了一个这样的需求,有几千个xml文件需要解析入库,每个文件里边有三万条数据。解析出来后要按表字段,重新组成需要的数据,不能直接将解析后的json入库。一开始我觉得这个事挺简单的,直接动手写了个demo,用随机选了两个xml文件测一下,没问题,成功入库。从解压xml到最后的数据入库,一......
  • linux 中 awk命令实现批量修改文件名
     001、[root@PC1test]#lsa.txtb.txtc.txt[root@PC1test]#find*.txta.txtb.txtc.txt[root@PC1test]#find*.txt|awk'{print"mv",$0,$0".bak"}'mva.txta.txt.bakmvb.txtb.txt.bakmvc.txtc.txt.bak[root@PC1t......
  • PowerShell在VC上批量创建虚拟机-for-Linux
    原创文档编写不易,未经许可请勿转载。文档中有疑问的可以邮件联系我。邮箱:[email protected]本文使用Powershell调用VMware-PowerCLI实现批量创建虚拟机的功能。环境说明软件名版本说明WindowsWindows10专业版21H2操作系统UbuntuUbuntu22.04.1LTS操作系统......
  • 批量ping-网段版
    原创文档编写不易,未经许可请勿转载。文档中有疑问的可以邮件联系我。邮箱:[email protected]说明shell脚本,适用于Linux操作系统中多个网段ping测。目前只能测试24位的网段。该脚本执行前需要操作系统已经具备timeout、ping命令。每个IP地址ping超时设置为2秒,脚本分为两个版本,基础......