MM 计划协议批量导入

2021年6月21日 1点热度 0条评论 来源: 你说是什么就是什么

事务代码:ME31,输入抬头信息:供应商、协议类型、协议日期、采购组织、采购组。

输入协议日期、有效起始日期、有效截止日期、付款条件、目标价值、货比码。

输入项目、物料、短文本、目标数量、单位、净价、每、单位、物料组、工厂、存储:

实际业务中需要导入大量的计划协议数据,因此需要使用BAPI批量导入功能位置。可使用BAPI:BAPI_SAG_CREATE批量导入。

需要传入的数据数据:

抬头数据:

 

行项目数据:

导入BAPI

通过事务代码ME31,通过生成的号码查询导入信息。

 

代码:

DATA:BEGIN OF gt_input OCCURS 0,
       znum(3)      TYPE c,          "编号
       lifnr        TYPE ekko-lifnr, "供应商
       bsart        TYPE ekko-bsart, "订单类型
       ekorg        TYPE ekko-ekorg, "采购组织
       ekgrp        TYPE ekko-ekgrp, "采购组
       bedat        TYPE ekko-bedat, "协议日期
       kdatb        TYPE ekko-kdatb, "有效期起始日期
       kdate        TYPE ekko-kdate, "有效期截止日期
       zterm        TYPE ekko-zterm, "付款条件
       ktwrt        TYPE ekko-ktwrt, "目标值
       waers        TYPE ekko-waers, "货币码
       wkurs        TYPE ekko-wkurs, "汇率
       ebelp        TYPE ekpo-ebelp, "行项目号
       pstyp        TYPE ekpo-pstyp, "项目类别
       knttp        TYPE ekpo-knttp, "科目类别
       ematn        TYPE ekpo-ematn, "物料编码
       txz01        TYPE ekpo-txz01, "短文本
       ktmng        TYPE ekpo-ktmng, "目标数量
       meins        TYPE ekpo-meins, "OUN
       netpr        TYPE ekpo-netpr, "净价
       peinh        TYPE ekpo-peinh, "
       bprme        TYPE ekpo-bprme, "OPU
       matkl        TYPE ekpo-matkl, "物料组
       werks        TYPE ekpo-werks, "工厂
       lgort        TYPE ekpo-lgort, "库存地点

       status(20)   TYPE c,         "导入是否成功状态
       drjg         TYPE c,         "导入结果
       message(100) TYPE c,         "消息
     END OF gt_input.
DATA:gt_output LIKE gt_input OCCURS 0 WITH HEADER LINE.

DATA: gt_specific LIKE bapi_itob_fl_only OCCURS 0 WITH HEADER LINE,
      gt_general  LIKE bapi_itob OCCURS 0 WITH HEADER LINE,
      g_funcloc   TYPE bapi_itob_parms-funcloc,
      gt_return   LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
*      gt_return   TYPE TABLE OF bapiret2.

*----------------------------------------------------------------------*
*  定义alv数据对象
*----------------------------------------------------------------------*
DATA: t_fieldcat TYPE slis_t_fieldcat_alv,
      w_fieldcat TYPE slis_fieldcat_alv,
      w_layout   TYPE slis_layout_alv.

*----------------------------------------------------------------------*
*  定义选择屏幕
*----------------------------------------------------------------------*
SELECTION-SCREEN FUNCTION KEY 1.
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_infile TYPE rlgrap-filename OBLIGATORY MEMORY ID m01.
SELECTION-SCREEN END OF BLOCK b1.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_infile.
  PERFORM frm_get_path."获取路径

AT SELECTION-SCREEN.
  PERFORM frm_download_excel."下载模板

AT SELECTION-SCREEN OUTPUT.
  PERFORM frm_set_screen."屏幕设置

INITIALIZATION.
  PERFORM frm_screen_ini."初始化屏幕

START-OF-SELECTION.
  PERFORM frm_check_data1."上传文件校验

  PERFORM frm_upload_data."上载数据

  PERFORM frm_call_bapi."调用BAPI

  PERFORM frm_display_alv."ALV显示

END-OF-SELECTION.

*&---------------------------------------------------------------------*
*& Form FRM_GET_PATH
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_get_path .
  CALL FUNCTION 'TB_LIMIT_WS_FILENAME_GET'
    EXPORTING
*     DEF_FILENAME     = ' '
*     DEF_PATH         = ' '
      mask             = 'Excel Files,*.xlsx,*.*. '
*     MODE             = ' '
*     TITLE            = ' '
    IMPORTING
      filename         = p_infile
*     PATH             =
*     FILE             =
    EXCEPTIONS
      selection_cancel = 1
      selection_error  = 2
      OTHERS           = 3.
  IF sy-subrc <> 0.
*    MESSAGE '获取文件路径失败!' TYPE 'E'.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_EXCEL
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_download_excel .
  CASE sscrfields-ucomm .
    WHEN 'FC01'.
      DATA: l_filename   TYPE string,
            l_path       TYPE string,
            l_fullpath   TYPE string,
            l_filelength TYPE i.

      PERFORM frm_filesave_dialog USING '计划协议批量导入模板.xls'
                            CHANGING l_filename
                                     l_path
                                     l_fullpath.
      PERFORM frm_download_files USING l_fullpath .
      CLEAR sscrfields-ucomm .
    WHEN OTHERS .
  ENDCASE .
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_DOWNLOAD_FILES
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> L_FULLPATH
*&---------------------------------------------------------------------*
FORM frm_download_files USING p_fullpath.
  DATA:ls_key TYPE wwwdatatab,
       lv_rc  TYPE sy-subrc.
  DATA: l_destination LIKE  rlgrap-filename .

  l_destination = p_fullpath .

  SELECT SINGLE relid objid INTO CORRESPONDING FIELDS OF ls_key
         FROM wwwdata
         WHERE srtf2 EQ 0
           AND relid EQ 'MI'
           AND objid EQ 'ZMMB_004'.
*           AND objid EQ sy-cprog.
  IF sy-subrc NE 0.
    MESSAGE '模板文件不存在' TYPE 'E'.
    RETURN.
  ENDIF.

  CALL FUNCTION 'DOWNLOAD_WEB_OBJECT'
    EXPORTING
      key         = ls_key
      destination = l_destination
    IMPORTING
      rc          = lv_rc.
  IF lv_rc <> 0.
    MESSAGE '模板文件:下载失败,请与相关人员联系' TYPE 'E'.
    RETURN.
  ENDIF.

  DATA: application TYPE ole2_object,
        workbook    TYPE ole2_object,
        sheet       TYPE ole2_object.

*&& 打开模版 文件
  CREATE OBJECT application 'EXCEL.APPLICATION'.
  IF sy-subrc NE 0.
    MESSAGE '不能创建Excel对象' TYPE 'E'.
    RETURN.
  ENDIF.

  CALL METHOD OF
    application
      'WORKBOOKS' = workbook.
  CALL METHOD OF
    workbook
    'OPEN'
    EXPORTING
      #1 = l_destination.
  CALL METHOD OF
      application
      'WORKSHEETS' = sheet
    EXPORTING
      #1           = 1.
  GET PROPERTY OF  application 'ACTIVESHEET' = sheet.
  SET PROPERTY OF application 'VISIBLE' = 1.

  FREE sheet.
  FREE workbook.
  FREE application.
  CALL METHOD OF
    workbook
    'CLOSE'.
  CALL METHOD OF
    application
    'QUIT'.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_FILESAVE_DIALOG
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*&      --> P_
*&      <-- L_FILENAME
*&      <-- L_PATH
*&      <-- L_FULLPATH
*&---------------------------------------------------------------------*
FORM frm_filesave_dialog  USING    p_value
                          CHANGING p_filename
                                   p_path
                                   p_fullpath.
  CALL METHOD cl_gui_frontend_services=>file_save_dialog
    EXPORTING
      default_file_name    = p_value
      default_extension    = 'xls'
    CHANGING
      filename             = p_filename
      path                 = p_path
      fullpath             = p_fullpath
    EXCEPTIONS
      cntl_error           = 1
      error_no_gui         = 2
      not_supported_by_gui = 3
      OTHERS               = 4.

ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_SET_SCREEN
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_set_screen .
  LOOP AT SCREEN.
    IF screen-name = 'P_INFILE'.
      screen-required = '2'.
      MODIFY SCREEN.
    ENDIF.
  ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_SCREEN_INI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_screen_ini .
  sscrfields-functxt_01 = '模板下载'.           "模板下载
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_CHECK_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_check_data1 .
  IF p_infile IS INITIAL.
    MESSAGE '文件路径不能为空!' TYPE 'S' DISPLAY LIKE 'E'.
    LEAVE LIST-PROCESSING.
  ENDIF.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_UPLOAD_DATA
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_upload_data .
  DATA: l_infile TYPE string.
  l_infile = p_infile.
  DATA: t_raw_data TYPE  truxs_t_text_data.

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
    EXPORTING
*     I_FIELD_SEPERATOR    =
      i_line_header        = 'X'
      i_tab_raw_data       = t_raw_data
      i_filename           = p_infile
    TABLES
      i_tab_converted_data = gt_input
    EXCEPTIONS
      conversion_failed    = 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.

  LOOP AT gt_input.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = gt_input-lifnr
      IMPORTING
        output = gt_input-lifnr.

    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
      EXPORTING
        input  = gt_input-zterm
      IMPORTING
        output = gt_input-zterm.

    MODIFY gt_input.
  ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_CALL_BAPI
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_call_bapi .
  DATA: ls_header       TYPE bapimeoutheader,
        ls_headerx      TYPE bapimeoutheaderx,
        ls_item         TYPE bapimeoutitem,
        lt_item         TYPE bapimeout_t_item,
        ls_itemx        TYPE bapimeoutitemx,
        lt_itemx        TYPE bapimeout_t_itemx,
        l_ebeln         TYPE bapimeoutheader-number,
        extensionin     LIKE bapiparex OCCURS 0 WITH HEADER LINE,
        lt_extensionout TYPE bapiparex_t,
        lt_return       TYPE bapiret2_t,
        ls_return       TYPE bapiret2.
  DATA: l_line  TYPE i.

  LOOP AT gt_input.
    l_line = l_line + 1.
    AT NEW znum.
      READ TABLE gt_input INDEX l_line.
*--------------------------------------------------------------------*
*   Header赋值
*--------------------------------------------------------------------*
      CLEAR: ls_header,ls_headerx.

      ls_header-vendor      = gt_input-lifnr. "供应商
      ls_header-doc_type    = gt_input-bsart. "订单类型
      ls_header-purch_org   = gt_input-ekorg. "采购组织
      ls_header-pur_group   = gt_input-ekgrp. "采购组
      ls_header-doc_date    = gt_input-bedat. "协议日期
      ls_header-vper_start  = gt_input-kdatb. "有效期起始日期
      ls_header-vper_end    = gt_input-kdate. "有效期截止日期
      ls_header-pmnttrms    = gt_input-zterm. "付款条件
      ls_header-acum_value  = gt_input-ktwrt. "目标值
      ls_header-currency    = gt_input-waers. "货币

      ls_headerx-vendor     = 'X'.  "供应商
      ls_headerx-doc_type   = 'X'.  "订单类型
      ls_headerx-purch_org  = 'X'.  "采购组织
      ls_headerx-pur_group  = 'X'.  "采购组
      ls_headerx-doc_date   = 'X'.  "协议日期
      ls_headerx-vper_start = 'X'.  "协议起始日期
      ls_headerx-vper_end   = 'X'.  "协议截至日期
      ls_headerx-pmnttrms   = 'X'.  "付款条件
      ls_headerx-acum_value = 'X'.  "目标值
      ls_headerx-currency   = 'X'.  "货币
    ENDAT.

*--------------------------------------------------------------------*
*   Item赋值
*--------------------------------------------------------------------*
    ls_item-item_no         = gt_input-ebelp.  "行项目号
    ls_item-item_cat        = gt_input-pstyp.  "项目类别
    ls_item-acctasscat      = gt_input-knttp.  "科目类别
*    ls_item-ematerial_long  = gt_input-ematn.  "物料编码
    CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
      EXPORTING
        input        = gt_input-ematn
      IMPORTING
        output       = ls_item-ematerial_long
*       output       = ls_item-EMATERIAL
      EXCEPTIONS
        length_error = 1
        OTHERS       = 2.
    IF sy-subrc <> 0.
* Implement suitable error handling here
    ENDIF.
    ls_item-short_text      = gt_input-txz01.  "短文本
    ls_item-target_qty      = gt_input-ktmng.  "目标数量
    ls_item-po_unit         = gt_input-meins.  "OUN
    ls_item-net_price       = gt_input-netpr.  "净价
    ls_item-price_unit      = gt_input-peinh.  "价格单位
    ls_item-orderpr_un      = gt_input-bprme.  "OPU
    ls_item-matl_group      = gt_input-matkl.  "物料组
    ls_item-plant           = gt_input-werks.  "工厂
    ls_item-stge_loc        = gt_input-lgort.  "库存地点
    APPEND ls_item TO lt_item.
    CLEAR ls_item.

    ls_itemx-item_no         = gt_input-ebelp.  "行项目号
    ls_itemx-item_cat        = 'X'.  "项目类别
    ls_itemx-acctasscat      = 'X'.  "科目类别
    ls_itemx-ematerial_long  = 'X'.  "物料编码
*    ls_itemx-EMATERIAL  = 'X'.  "物料编码
    ls_itemx-short_text      = 'X'.  "短文本
    ls_itemx-target_qty      = 'X'.  "目标数量
    ls_itemx-po_unit         = 'X'.  "OUN
    ls_itemx-net_price       = 'X'.  "净价
    ls_itemx-price_unit      = 'X'.  "价格单位
    ls_itemx-orderpr_un      = 'X'.  "OPU
    ls_itemx-matl_group      = 'X'.  "物料组
    ls_itemx-plant           = 'X'.  "工厂
    ls_itemx-stge_loc        = 'X'.  "库存地点
    APPEND ls_itemx TO lt_itemx.
    CLEAR ls_itemx.

    AT END OF znum.
      READ TABLE gt_input INDEX l_line.
*      CALL FUNCTION 'BAPI_CONTRACT_CREATE'
*        EXPORTING
*          header             = ls_header
*          headerx            = ls_headerx
*        IMPORTING
*          purchasingdocument = l_ebeln
*        TABLES
*          return             = lt_return
*          item               = lt_item
*          itemx              = lt_itemx
*          extensionin        = extensionin.
      CALL FUNCTION 'BAPI_SAG_CREATE'
        EXPORTING
          header      = ls_header
          headerx     = ls_headerx
*         VENDOR_ADDRESS              =
*         HEAD_EXPORT_IMPORT          =
*         HEAD_EXPORT_IMPORTX         =
*         TESTRUN     =
*         TECHNICAL_DATA              =
*       IMPORTING
*         PURCHASINGDOCUMENT          =
*         EXP_HEADER  =
        TABLES
          return      = lt_return
          item        = lt_item
          itemx       = lt_itemx
*         ACCOUNT     =
*         ACCOUNTPROFITSEGMENT        =
*         ACCOUNTX    =
*         SCHEDULE    =
*         SCHEDULEX   =
*         SC_COMPONENT                =
*         SC_COMPONENTX               =
*         SHIPPING    =
*         SHIPPINGX   =
*         SHIPPING_EXP                =
*         DELIVERY_ADDRESS            =
*         ITEM_COND_VALIDITY          =
*         ITEM_COND_VALIDITYX         =
*         ITEM_CONDITION              =
*         ITEM_CONDITIONX             =
*         ITEM_COND_SCALE_VALUE       =
*         ITEM_COND_SCALE_QUAN        =
*         EXPORT_IMPORT               =
*         EXPORT_IMPORTX              =
*         ITEM_TEXT   =
*         HEADER_TEXT =
*         HEAD_COND_VALIDITY          =
*         HEAD_COND_VALIDITYX         =
*         HEAD_CONDITION              =
*         HEAD_CONDITIONX             =
*         HEAD_COND_SCALE_VAL         =
*         HEAD_COND_SCALE_QUAN        =
*         PARTNER     =
*         PARTNERX    =
          extensionin = extensionin
*         EXTENSIONOUT                =
        .

      LOOP AT lt_return INTO ls_return.
        IF ls_return-type = 'E' OR ls_return-type = 'A'.
          gt_input-status = icon_led_red.
          gt_input-drjg = 'E'.
          CONCATENATE gt_input-message ls_return-message INTO gt_input-message SEPARATED BY '/'.
          CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
        ENDIF.
        IF ls_return-type = 'S'.
          gt_input-status = icon_led_green.
          gt_input-drjg = 'S'.
          gt_input-message = ls_return-message.
          CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
          WAIT UP TO '0.1' SECONDS.
        ENDIF.
      ENDLOOP.
      MODIFY gt_input.
      CLEAR:ls_header,ls_headerx,lt_return,lt_item,lt_itemx.
    ENDAT.

    LOOP AT gt_input INTO DATA(lw_msg) WHERE znum = gt_input-znum.
      lw_msg-status  = gt_input-status.
      lw_msg-message = gt_input-message.
      MODIFY gt_input FROM lw_msg.
    ENDLOOP.
  ENDLOOP.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_DISPLAY_ALV
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_display_alv .
  PERFORM frm_fill_fieldcat.
  PERFORM frm_alv_layout.

  CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
    EXPORTING
      i_buffer_active    = 'X'
      i_callback_program = sy-repid
      is_layout          = w_layout
      it_fieldcat        = t_fieldcat
*     i_callback_pf_status_set = 'SET_PF_STATUS'
*     i_callback_user_command  = 'USER_COMMAND'
    TABLES
      t_outtab           = gt_input
    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_FILL_FIELDCAT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_fill_fieldcat .
  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'STATUS'.
  w_fieldcat-seltext_m = '指示灯'.
  w_fieldcat-icon = 'X'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'DRJG'.
  w_fieldcat-seltext_m = '导入结果'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'MESSAGE'.
  w_fieldcat-seltext_m = '消息'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'LIFNR'.
  w_fieldcat-seltext_m = '供应商'.
  w_fieldcat-no_zero = 'X'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'BSART'.
  w_fieldcat-seltext_m = '订单类型'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'EKORG'.
  w_fieldcat-seltext_m = '采购组织'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'EKGRP'.
  w_fieldcat-seltext_m = '采购组'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'BEDAT'.
  w_fieldcat-seltext_m = '协议日期'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'KDATB'.
  w_fieldcat-seltext_m = '有效期起始日期'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'KDATE'.
  w_fieldcat-seltext_m = '有效期截止日期'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'ZTERM'.
  w_fieldcat-seltext_m = '付款条件'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'KTWRT'.
  w_fieldcat-seltext_m = '目标值'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'WAERS'.
  w_fieldcat-seltext_m = '货币码'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'WKURS'.
  w_fieldcat-seltext_m = '汇率'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'EBELP'.
  w_fieldcat-seltext_m = '行项目号'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'PSTYP'.
  w_fieldcat-seltext_m = '项目类别'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'KNTTP'.
  w_fieldcat-seltext_m = '科目类别'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'EMATN'.
  w_fieldcat-seltext_m = '物料编码'.
  w_fieldcat-no_zero = 'X'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'TXZ01'.
  w_fieldcat-seltext_m = '短文本'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'KTMNG'.
  w_fieldcat-seltext_m = '目标数量'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'MEINS'.
  w_fieldcat-seltext_m = 'OUN'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'NETPR'.
  w_fieldcat-seltext_m = '净价'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'PEINH'.
  w_fieldcat-seltext_m = '每'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'BPRME'.
  w_fieldcat-seltext_m = 'OPU'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'MATKL'.
  w_fieldcat-seltext_m = '物料组'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'WERKS'.
  w_fieldcat-seltext_m = '工厂'.
  APPEND w_fieldcat TO t_fieldcat.

  CLEAR w_fieldcat.
  w_fieldcat-fieldname = 'LGORT'.
  w_fieldcat-seltext_m = '库存地点'.
  APPEND w_fieldcat TO t_fieldcat.
ENDFORM.

*&---------------------------------------------------------------------*
*& Form FRM_ALV_LAYOUT
*&---------------------------------------------------------------------*
*& text
*&---------------------------------------------------------------------*
*& -->  p1        text
*& <--  p2        text
*&---------------------------------------------------------------------*
FORM frm_alv_layout .
  w_layout-colwidth_optimize = 'X'.
ENDFORM.

    原文作者:你说是什么就是什么
    原文地址: https://blog.csdn.net/z_x_xing_/article/details/90231751
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。