欢迎来到萧静默的博客

书山有路勤为径,学海无涯苦作舟。

SAP-批量创建货源清单

对于SAP货源清单的批量创建,试用了很多网上的函数创建法,发现都不怎么好使。决定自己录一个BDC进行使用,

参考了网上了一些BDC的例子,注意到了一点这个货源清单使用的一些坑,如果发现当物料和工厂是一样的情况下,

不做任何处理,供应商不同时候,只能创建成功第一个。

针对上述这个问题,我合并了物料及工厂,并且用于物料及工厂只填入一次,供应商多次填入。

源码及模板如下:

*&---------------------------------------------------------------------*
*& Report  ZMMRP088A
*&---------------------------------------------------------------------*
*&PROGRAM NAME : <ZMMRP088A>
*---------------------------------------------------------------------*
* VERSION:            V1.0
* DATE CREATED :      20210519
* CREATED BY   :      Bruce King
* DESCRIPTION  :      Batch Maintain Source List

REPORT ZMMRP088A.
TYPE-POOLS:TRUXS.
TABLES:SSCRFIELDS,RLGRAP,MSEG,EORD.
"货源清单查询结构
TYPES : BEGIN OF LTYPE_INFOR,
          MATNR TYPE EORD-MATNR,
          WERKS TYPE EORD-WERKS,
          VDATU TYPE EORD-VDATU,
          BDATU TYPE EORD-BDATU,
          LIFNR TYPE EORD-LIFNR,
          EKORG TYPE EORD-EKORG,
        END OF LTYPE_INFOR.
DATA: IT_RAW TYPE TRUXS_T_TEXT_DATA,
      BEGIN OF RECORD OCCURS 0,
        MATNRWERKS TYPE STRING,
        WERKS      TYPE WERKS_D,
        MATNR      TYPE MATNR,
        LIFNR      LIKE EORD-LIFNR,
        VDATU      TYPE CHAR8, "ordab,
        BDATU      TYPE CHAR8, "bdatu,
        EKORG      LIKE EORD-EKORG,
        RESWK      LIKE EORD-RESWK,
        AUTET      TYPE AUTET, "mrp
        ZEORD      LIKE EORD-ZEORD,
        TIPS       TYPE STRING,
        CHECKBOX   TYPE CHAR1,
      END OF RECORD,
      IT_CREATE LIKE TABLE OF RECORD WITH HEADER LINE.
DATA:WA_CREATE LIKE LINE OF IT_CREATE.
DATA: GT_INFO TYPE STANDARD TABLE OF LTYPE_INFOR,
      GS_INFO TYPE    LTYPE_INFOR.
DATA:ITMP  LIKE TABLE OF EKPO WITH HEADER LINE,
     ITMP1 LIKE TABLE OF EKPO WITH HEADER LINE,
     ITMP2 LIKE TABLE OF EKPO WITH HEADER LINE.
DATA : LT_EORD TYPE STANDARD TABLE OF EORD,
       LS_EORD LIKE LINE OF LT_EORD.
DATA : GT_EORDU TYPE STANDARD TABLE OF EORDU,
       WA_EORDU LIKE LINE OF GT_EORDU.
DATA:ITAB_BDCTAB TYPE TABLE OF BDCDATA WITH HEADER LINE.
DATA:P_MODE TYPE CHAR1 VALUE 'N',
     P_UPDA TYPE CHAR1 VALUE 'L'.
DATA LV_MESS TYPE STRING.
DATA BEGIN OF MESSTAB OCCURS 10.
INCLUDE STRUCTURE BDCMSGCOLL.
DATA END OF MESSTAB.

*ALV显示参数定义
DATA :GS_LAYOUT TYPE LVC_S_LAYO."SLIS_LAYOUT_ALV.
DATA :GT_FIELDCAT TYPE LVC_T_FCAT, "SLIS_T_FIELDCAT_ALV.
      GS_FIELDCAT TYPE LVC_S_FCAT.
DATA :GS_SETTINGS TYPE LVC_S_GLAY.
DATA :GT_SORT TYPE LVC_T_SORT,
      GS_SORT TYPE LVC_S_SORT.
DATA: GT_EVENT TYPE SLIS_T_EVENT WITH HEADER LINE.
DATA: GT_EVENT_EXIT TYPE SLIS_T_EVENT_EXIT WITH HEADER LINE.
DATA :G_GRID TYPE REF TO CL_GUI_ALV_GRID.

*&---------------------------------------------------------------------*
* 宏的定义
*&---------------------------------------------------------------------*
DEFINE ADDFIELDCAT.
  CLEAR gs_fieldcat.
  gs_fieldcat-fieldname = &1.         "字段名
  gs_fieldcat-scrtext_l = &2.         "字段描述
  gs_fieldcat-do_sum    = &3.         "汇总
  gs_fieldcat-EDIT      = &4.         "列可编辑
  gs_fieldcat-edit_mask = &5.         "隐藏前导零
  gs_fieldcat-outputlen = &6.         "输出长度
  gs_fieldcat-CHECKBOX  = &7.
  APPEND gs_fieldcat TO gt_fieldcat.
  CLEAR gs_fieldcat.
END-OF-DEFINITION.

SELECTION-SCREEN:FUNCTION KEY 1.

SELECTION-SCREEN BEGIN OF BLOCK BLK00 WITH FRAME TITLE TEXT-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN POSITION 3.
PARAMETERS A RADIOBUTTON GROUP RG1 DEFAULT 'X' USER-COMMAND DOWNLOAD.
SELECTION-SCREEN COMMENT 5(10)  TEXT-002 FOR FIELD A.
SELECTION-SCREEN POSITION 20.
PARAMETERS B RADIOBUTTON GROUP RG1.
SELECTION-SCREEN COMMENT 22(15) TEXT-003 FOR FIELD B.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK BLK00.
"上传文件界面
SELECTION-SCREEN BEGIN OF BLOCK BLK01 WITH FRAME TITLE TEXT-005.
PARAMETERS: P_FILE LIKE RLGRAP-FILENAME MODIF ID M1.
SELECTION-SCREEN END OF BLOCK BLK01.
"查询货源清单界面
SELECTION-SCREEN BEGIN OF BLOCK BLK02 WITH FRAME TITLE TEXT-006.
SELECT-OPTIONS:S_MATNR FOR EORD-MATNR MODIF ID M2,
               S_WERKS FOR EORD-WERKS MODIF ID M2,
               S_LIFNR FOR EORD-LIFNR MODIF ID M2,
               S_EKORG FOR EORD-EKORG MODIF ID M2.
SELECTION-SCREEN END OF BLOCK BLK02.

INITIALIZATION.
  DATA BUT_DOWN(255) TYPE C.
  CALL FUNCTION 'ICON_CREATE' " 给按钮添加图标和文本
    EXPORTING
      NAME   = ICON_XLS
      TEXT   = '下载货源清单导入模板'
    IMPORTING
      RESULT = BUT_DOWN
    EXCEPTIONS
      OTHERS = 0.
  SSCRFIELDS-FUNCTXT_01 = BUT_DOWN.

AT SELECTION-SCREEN OUTPUT.
  LOOP AT SCREEN.
    CASE SCREEN-GROUP1.
      WHEN 'M1'.
        IF  B = 'X' .
          SCREEN-ACTIVE = '0'.
        ENDIF.
      WHEN 'M2'.
        IF  A = 'X' .
          SCREEN-ACTIVE = '0'.
        ENDIF.
    ENDCASE.
    MODIFY SCREEN.
  ENDLOOP.


AT SELECTION-SCREEN.
  CASE SSCRFIELDS-UCOMM.
    WHEN 'FC01'.
      PERFORM DOWN_TEMPLATE."下载导入模板
  ENDCASE.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_FILE.
  PERFORM FRM_GET_FILE USING P_FILE."获得路径

START-OF-SELECTION.
  IF A EQ 'X'.
    PERFORM FRM_IMPORT_DATA.
    PERFORM DISPLAY_ALV.
  ELSEIF B EQ 'X'.
    PERFORM EORD_DISPLAY.
  ENDIF.
FORM FRM_IMPORT_DATA.
  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      I_LINE_HEADER        = 'X'
      I_TAB_RAW_DATA       = IT_RAW
      I_FILENAME           = P_FILE
    TABLES
      I_TAB_CONVERTED_DATA = RECORD[].
  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.
  DELETE RECORD WHERE MATNR IS INITIAL.
  DELETE RECORD WHERE LIFNR IS INITIAL.
  LOOP AT RECORD.
    RECORD-MATNR = |{ RECORD-MATNR ALPHA = IN }|.
    RECORD-MATNR = RECORD-MATNR+22(18).
    RECORD-LIFNR = |{ RECORD-LIFNR ALPHA = IN }|.
    IF RECORD-VDATU IS INITIAL.
      RECORD-VDATU = SY-DATUM.
      MODIFY RECORD TRANSPORTING VDATU.
    ENDIF.
    IF RECORD-BDATU IS INITIAL.
      RECORD-BDATU = '99991231'.
      MODIFY RECORD TRANSPORTING BDATU.
    ENDIF.
    IF RECORD-WERKS IS INITIAL.
      RECORD-TIPS = '请输入工厂!'.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ENDIF.
    IF RECORD-MATNR IS INITIAL.
      RECORD-TIPS = '请输入物料编码!'.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ENDIF.
    IF RECORD-LIFNR IS INITIAL.
      RECORD-TIPS = '请输入供应商!'.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ENDIF.

    SELECT SINGLE * FROM MARC INTO @DATA(WA_MARC) WHERE MATNR = @RECORD-MATNR AND WERKS = @RECORD-WERKS.
    IF WA_MARC IS INITIAL.
      RECORD-TIPS = |物料{ RECORD-MATNR }在工厂{ RECORD-WERKS }中未维护!|.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ELSE.
      CLEAR WA_MARC.
    ENDIF.

    RECORD-LIFNR = |{ RECORD-LIFNR ALPHA = IN }|.
    SELECT SINGLE * FROM LFA1 INTO @DATA(WA_LFA1) WHERE LIFNR = @RECORD-LIFNR.
    IF WA_LFA1 IS INITIAL.
      RECORD-TIPS = |供应商{ RECORD-LIFNR }主数据不存在!|.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ELSE.
      CLEAR:WA_LFA1.
    ENDIF.

    SELECT SINGLE * FROM LFM1 INTO @DATA(WA_LFM1) WHERE LIFNR = @RECORD-LIFNR AND EKORG = @RECORD-EKORG.
    IF WA_LFM1 IS INITIAL.
      RECORD-TIPS = |采购组织{ RECORD-WERKS }未维护供应商{ RECORD-LIFNR }!|.
      MODIFY RECORD TRANSPORTING TIPS.
      CLEAR RECORD.
      CONTINUE.
    ELSE.
      CLEAR:WA_LFM1.
    ENDIF.
  ENDLOOP.
ENDFORM.                    "frm_import_data
FORM CREATE_ME01 .
  DATA L_ERR TYPE STRING.
  DATA: L_VDATU(20),
        L_BDATU(20),
        L_LIFNR(20),
        L_EKORG(20),
        L_FESKZ(20),
        L_AUTET(20).
  DATA: L_COUNT TYPE I.
  DATA:LT_RETURN TYPE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.
  CLEAR LT_EORD[].
  IF RECORD[] IS NOT INITIAL.
    SELECT *
    FROM EORD
    INTO CORRESPONDING FIELDS OF TABLE LT_EORD
    FOR ALL ENTRIES IN RECORD
    WHERE MATNR = RECORD-MATNR
    AND WERKS = RECORD-WERKS
    AND LIFNR = RECORD-LIFNR
    AND EKORG = RECORD-EKORG.
  ENDIF.
  SORT  LT_EORD BY MATNR WERKS LIFNR EKORG ASCENDING VDATU DESCENDING.
  CLEAR:LS_EORD,GT_EORDU,GT_EORDU[],RECORD.

  REFRESH ITAB_BDCTAB[].

  SORT RECORD BY MATNR WERKS ZEORD.
  LOOP AT RECORD.
    RECORD-MATNRWERKS = |{ RECORD-MATNR }{ RECORD-WERKS }|.
    MODIFY RECORD TRANSPORTING MATNRWERKS.
    CLEAR:RECORD.
  ENDLOOP.

  LOOP AT RECORD WHERE CHECKBOX EQ 'X'.
    READ TABLE LT_EORD INTO LS_EORD WITH KEY MATNR = RECORD-MATNR WERKS = RECORD-WERKS LIFNR = RECORD-LIFNR EKORG = RECORD-EKORG.
    IF LS_EORD-LIFNR <> RECORD-LIFNR. "创建货源清单.
      MOVE-CORRESPONDING RECORD TO WA_CREATE.
      APPEND WA_CREATE TO IT_CREATE.
    ENDIF.
    CLEAR:WA_CREATE.
  ENDLOOP.
  SORT IT_CREATE BY MATNRWERKS MATNR WERKS ZEORD.
  LOOP AT IT_CREATE ASSIGNING FIELD-SYMBOL(<FS_CREATE>).
    L_COUNT = L_COUNT + 1.
    <FS_CREATE>-ZEORD = L_COUNT.

    CONCATENATE 'EORD-VDATU(' <FS_CREATE>-ZEORD ')' INTO L_VDATU.
    CONCATENATE 'EORD-BDATU(' <FS_CREATE>-ZEORD ')' INTO L_BDATU.
    CONCATENATE 'EORD-LIFNR(' <FS_CREATE>-ZEORD ')' INTO L_LIFNR.
    CONCATENATE 'EORD-EKORG(' <FS_CREATE>-ZEORD ')' INTO L_EKORG.
    CONCATENATE 'EORD-AUTET(' <FS_CREATE>-ZEORD ')' INTO L_AUTET.
    CONCATENATE 'RM06W-FESKZ(' <FS_CREATE>-ZEORD ')' INTO L_FESKZ.

    AT NEW MATNRWERKS.

      PERFORM BDC_DYNPRO      USING 'SAPLMEOR' '0200'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
            'EORD-MATNR'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
            '/00'.
      PERFORM BDC_FIELD       USING 'EORD-MATNR'
            <FS_CREATE>-MATNR.
      PERFORM BDC_FIELD       USING 'EORD-WERKS'
            <FS_CREATE>-WERKS.
      PERFORM BDC_DYNPRO      USING 'SAPLMEOR' '0205'.
      PERFORM BDC_FIELD       USING 'BDC_CURSOR'
            'EORD-RESWK(01)'.
      PERFORM BDC_FIELD       USING 'BDC_OKCODE'
            'BU'.
    ENDAT.
    PERFORM BDC_FIELD       USING L_VDATU
          <FS_CREATE>-VDATU.
    PERFORM BDC_FIELD       USING L_BDATU
          <FS_CREATE>-BDATU.
    PERFORM BDC_FIELD       USING L_LIFNR
          <FS_CREATE>-LIFNR.
    PERFORM BDC_FIELD       USING L_EKORG
          <FS_CREATE>-EKORG.
*      PERFORM BDC_FIELD       USING 'EORD-RESWK(01)'
*            RECORD-RESWK_01_007.
*      PERFORM BDC_TRANSACTION USING 'ME01'.
    AT END OF MATNRWERKS.
      CALL TRANSACTION 'ME01' USING ITAB_BDCTAB
            MODE      P_MODE
            UPDATE    P_UPDA
            MESSAGES INTO MESSTAB.

      CALL FUNCTION 'CONVERT_BDCMSGCOLL_TO_BAPIRET2'
        TABLES
          IMT_BDCMSGCOLL = MESSTAB
          EXT_RETURN     = LT_RETURN.

      READ TABLE MESSTAB WITH KEY MSGTYP = 'S'.

      IF SY-SUBRC EQ 0.
        LOOP AT RECORD WHERE MATNR = <FS_CREATE>-MATNR AND WERKS = <FS_CREATE>-WERKS AND CHECKBOX EQ 'X'.
          RECORD-TIPS = |货源清单创建成功|.
          MODIFY RECORD TRANSPORTING TIPS.
          CLEAR:RECORD,WA_CREATE.
        ENDLOOP.
      ELSE.
        LOOP AT RECORD WHERE MATNR = <FS_CREATE>-MATNR AND WERKS = <FS_CREATE>-WERKS AND CHECKBOX EQ 'X'.
          RECORD-TIPS = |货源清单创建失败|.
          MODIFY RECORD TRANSPORTING TIPS.
          CLEAR:RECORD,WA_CREATE.
        ENDLOOP.
      ENDIF.
      REFRESH ITAB_BDCTAB[].
      REFRESH MESSTAB[].
      CLEAR:L_COUNT,<FS_CREATE>.
    ENDAT.
  ENDLOOP.
ENDFORM.
FORM BDC_DYNPRO  USING   NAME VALUE.
  CLEAR ITAB_BDCTAB.
  ITAB_BDCTAB-PROGRAM = NAME.
  ITAB_BDCTAB-DYNPRO  = VALUE.
  ITAB_BDCTAB-DYNBEGIN = 'X'.
  APPEND ITAB_BDCTAB.
ENDFORM.                    "BDC_DYNPRO
FORM BDC_FIELD  USING    NAME VALUE.
  CLEAR ITAB_BDCTAB.
  ITAB_BDCTAB-FNAM = NAME.
  ITAB_BDCTAB-FVAL = VALUE.
  APPEND ITAB_BDCTAB.
ENDFORM.                    "BDC_FIELD
FORM DISPLAY_ALV .
  GS_LAYOUT-CWIDTH_OPT = 'X'.   "根据优化列宽度
  GS_LAYOUT-ZEBRA      = 'X'.   "ALV行的颜色间隔更换(间隔色带)
  GS_LAYOUT-SEL_MODE   = 'A'.   "A:行或列选择 B:单一选择 C:多条选择 D:单元格选择

  ADDFIELDCAT   'CHECKBOX' '选择'      SPACE  'X' SPACE SPACE  'X'.
  ADDFIELDCAT   'WERKS'    '工厂'      SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'MATNR'    '物料编码'  SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'LIFNR'    '供应商'    SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'VDATU'    '有效期起'  SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'BDATU'    '有效期止'  SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'EKORG'    '采购组织'  SPACE SPACE SPACE SPACE SPACE.
  ADDFIELDCAT   'TIPS'     '备注          '  SPACE SPACE SPACE '20' SPACE.

*---FUNCTION
  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'
    EXPORTING
      I_CALLBACK_PROGRAM       = SY-REPID                  "
      IT_FIELDCAT_LVC          = GT_FIELDCAT               "
      IS_LAYOUT_LVC            = GS_LAYOUT                 "
      I_SAVE                   = 'A'                       "
      I_CALLBACK_PF_STATUS_SET = 'FRM_PF_STATUS_SET'    "GUI STATUS
      I_CALLBACK_USER_COMMAND  = 'FRM_USER_COMMAND' "USER COMMAND
    TABLES
      T_OUTTAB                 = RECORD[]
    EXCEPTIONS
      PROGRAM_ERROR            = 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.
ENDFORM.

FORM FRM_USER_COMMAND USING R_UCOMM LIKE SY-UCOMM RS_SELFIELD TYPE SLIS_SELFIELD.
  DATA: REF TYPE REF TO CL_GUI_ALV_GRID.
  CALL FUNCTION 'GET_GLOBALS_FROM_SLVC_FULLSCR'
    IMPORTING
      E_GRID = REF.
  CALL METHOD REF->CHECK_CHANGED_DATA.
  "响应事件
  CASE R_UCOMM.
    WHEN '&SEL'.
      LOOP AT RECORD WHERE CHECKBOX NE 'X' AND TIPS IS INITIAL.
        RECORD-CHECKBOX = 'X'.
        MODIFY RECORD TRANSPORTING CHECKBOX.
        CLEAR RECORD.
      ENDLOOP.
    WHEN '&DESEL'.
      LOOP AT RECORD WHERE CHECKBOX EQ 'X'.
        RECORD-CHECKBOX = ' '.
        MODIFY RECORD TRANSPORTING CHECKBOX.
        CLEAR RECORD.
      ENDLOOP.
    WHEN '&IC1'.
      READ TABLE RECORD INDEX RS_SELFIELD-TABINDEX.
      "单击选择按钮时触发
      IF  RS_SELFIELD-FIELDNAME = 'CHECKBOX'.
        IF RECORD-CHECKBOX = 'X'.
          RECORD-CHECKBOX = ''.
        ELSE.
          RECORD-CHECKBOX = 'X'.
        ENDIF.
        MODIFY RECORD INDEX RS_SELFIELD-TABINDEX.
      ENDIF.
      CLEAR RECORD.
    WHEN '&CREATE'."
      PERFORM CREATE_ME01.
    WHEN '&DEL'."
      PERFORM DEL_ME01.
  ENDCASE.
  "刷新ALV
  RS_SELFIELD-ROW_STABLE = 'X'.
  RS_SELFIELD-COL_STABLE = 'X'.
  RS_SELFIELD-REFRESH    = 'X'.
ENDFORM.                    "FR

FORM FRM_PF_STATUS_SET USING EXTAB TYPE SLIS_T_EXTAB..
  SET  PF-STATUS  'T001'.
ENDFORM.

FORM DOWN_TEMPLATE ."用的自己封装的模板下载类
  CALL METHOD ZCL_BC_EXCEL=>DOWNLOAD_TEMPLATE
    EXPORTING
      NAME_OF_TEMPLATE = '货源清单导入模板'
      IV_RELID         = 'MI'
      IV_OBJID         = 'ZMM088A'.

  IF SY-SUBRC <> 0.
*   Implement suitable error handling here
  ENDIF.
ENDFORM.

FORM EORD_DISPLAY ."用的SALV显示类
  DATA: GR_FUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS,
        LR_DISPLAY   TYPE REF TO CL_SALV_DISPLAY_SETTINGS.
  SELECT *
  FROM EORD
  INTO CORRESPONDING FIELDS OF TABLE GT_INFO
  WHERE MATNR IN  S_MATNR
  AND WERKS IN  S_WERKS
  AND LIFNR IN  S_LIFNR
  AND EKORG IN  S_EKORG.
  TRY.
      CL_SALV_TABLE=>FACTORY( IMPORTING R_SALV_TABLE = DATA(S_ALV) CHANGING T_TABLE = GT_INFO ).
    CATCH CX_SALV_MSG.
  ENDTRY.
  "首先我们要取得类CL_SALV_FUNCTIONS的实例,根据类CL_SALV_TABLE的方法get_functions可以取得功能实例。
  GR_FUNCTIONS = S_ALV->GET_FUNCTIONS( ).
  GR_FUNCTIONS->SET_ALL( ABAP_TRUE ).
  LR_DISPLAY = S_ALV->GET_DISPLAY_SETTINGS( ).
  LR_DISPLAY->SET_STRIPED_PATTERN( 'X' )."设置颜色间隔显示
  LR_DISPLAY->SET_LIST_HEADER( '货源清单展示报表' ). "设置ALV的抬头
  LR_DISPLAY->SET_HORIZONTAL_LINES( '' ).  "设置水平线是否显示
  LR_DISPLAY->SET_VERTICAL_LINES( '' ).   "设置垂直线是否显示
  LR_DISPLAY->SET_FIT_COLUMN_TO_TABLE_SIZE( 'X')."列自适应表格宽度
  "3、取得实例之后再调用方法Display()显示列表
  S_ALV->DISPLAY( ).
ENDFORM.

FORM FRM_GET_FILE  USING    P_P_FILE.
  CALL FUNCTION 'WS_FILENAME_GET'
    EXPORTING
      DEF_FILENAME     = P_FILE
      MASK             = ',*.xlsx,*.XLSX,*.xls,*.XLS,*.txt,*.TXT'
*'',*.xls,*.XLS.'如果读入txt文件,在后边就需要用函数
      MODE             = 'O'
      TITLE            = 'File Name'
    IMPORTING
      FILENAME         = P_FILE
    EXCEPTIONS
      INV_WINSYS       = 1
      NO_BATCH         = 2
      SELECTION_CANCEL = 3
      SELECTION_ERROR  = 4
      OTHERS           = 5.
ENDFORM.

FORM DEL_ME01 .
  DATA: BEGIN OF LT_DEL OCCURS 0,
          MATNR LIKE EORD-MATNR,
          WERKS LIKE EORD-WERKS,
        END OF LT_DEL.
  LOOP AT RECORD WHERE CHECKBOX EQ 'X'.
    MOVE-CORRESPONDING RECORD TO LT_DEL.
    APPEND LT_DEL.
    CLEAR:RECORD,LT_DEL.
  ENDLOOP.
  SORT LT_DEL BY MATNR WERKS.
  DELETE ADJACENT DUPLICATES FROM LT_DEL COMPARING ALL FIELDS.
  LOOP AT LT_DEL.

    PERFORM BDC_DYNPRO      USING 'SAPLMEOR'    '0200'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'EORD-WERKS'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '/00'.

    PERFORM BDC_FIELD       USING 'EORD-MATNR' LT_DEL-MATNR.
    PERFORM BDC_FIELD       USING 'EORD-WERKS' LT_DEL-WERKS.

    PERFORM BDC_DYNPRO      USING 'SAPLMEOR'    '0205'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'EORD-WERKS'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=SA'.

    PERFORM BDC_DYNPRO      USING 'SAPLMEOR'    '0205'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'EORD-WERKS'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=LOES'.

    PERFORM BDC_DYNPRO      USING 'SAPLSPO1'    '0200'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=YES'.

    PERFORM BDC_DYNPRO      USING 'SAPLMEOR'    '0205'.
    PERFORM BDC_FIELD       USING 'BDC_CURSOR'  'EORD-WERKS'.
    PERFORM BDC_FIELD       USING 'BDC_OKCODE'  '=BU'.


    CALL TRANSACTION 'ME01' USING ITAB_BDCTAB
          MODE      P_MODE
          UPDATE    P_UPDA
          MESSAGES INTO MESSTAB.
    READ TABLE MESSTAB WITH KEY MSGTYP = 'S'.

    IF SY-SUBRC EQ 0.
      LOOP AT RECORD WHERE MATNR = LT_DEL-MATNR AND WERKS = LT_DEL-WERKS AND CHECKBOX EQ 'X'.
        RECORD-TIPS = |关于物料{ LT_DEL-MATNR }在工厂{ LT_DEL-WERKS }的货源清单删除成功|.
        MODIFY RECORD TRANSPORTING TIPS.
        CLEAR:RECORD.
      ENDLOOP.
    ELSE.
      LOOP AT RECORD WHERE MATNR = LT_DEL-MATNR AND WERKS = LT_DEL-WERKS AND CHECKBOX EQ 'X'.
        RECORD-TIPS = |关于物料{ LT_DEL-MATNR }在工厂{ LT_DEL-WERKS }的货源清单删除失败|.
        MODIFY RECORD TRANSPORTING TIPS.
        CLEAR:RECORD.
      ENDLOOP.
    ENDIF.
    REFRESH ITAB_BDCTAB[].
    REFRESH MESSTAB[].
  ENDLOOP.
ENDFORM.

 

posted @ 2021-05-24 10:09  萧静默  阅读(1180)  评论(1编辑  收藏  举报