*&---------------------------------------------------------------------*
*& ZXXL_MM02_01
*&---------------------------------------------------------------------*
REPORT ZXXL_MM02_01.
INCLUDE ZXXL_MM02_01HEAD .
INCLUDE ZXXL_MM02_01FROM .
START-OF-SELECTION.
PERFORM GET_DATE .
END-OF-SELECTION.
"转换
PERFORM APPEND_BDCDATA .
ZXXL_MM02_01HEAD 程序:
*&---------------------------------------------------------------------*
*& 包含 ZXXL_MM02_01HEAD
*&---------------------------------------------------------------------*
TYPES: BEGIN OF gty_material ,
matnr TYPE c LENGTH 18 , "物料代码
maktx TYPE c LENGTH 40 , "物料描述
brgew TYPE c LENGTH 20 , "毛重量
ntgew TYPE c LENGTH 20 , "净重量
gewei TYPE c LENGTH 3 , "单位
END OF gty_material .
DATA gt_material TYPE TABLE OF gty_material .
DATA gs_material TYPE gty_material .
*BDCDATA定义带有表头行的内表
DATA bdcdata TYPE BDCDATA OCCURS 0 WITH HEADER LINE.
ZXXL_MM02_01FROM程序:
*&---------------------------------------------------------------------*
*& 包含 ZXXL_MM02_01FROM
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*& Form APPEND_BDCDATA
*&---------------------------------------------------------------------*
* 执行DBC
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM append_bdcdata .
LOOP AT gt_material INTO gs_material.
CLEAR bdcdata .
CLEAR bdcdata[].
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR' 'RMMG1-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'RMMG1-MATNR' gs_material-matnr.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'.
PERFORM bdc_field USING 'BDC_CURSOR' 'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR'.
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)' 'X'.
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE' '=BU'.
PERFORM bdc_field USING 'MAKT-MAKTX' gs_material-maktx.
PERFORM bdc_field USING 'BDC_CURSOR' 'MARA-GEWEI'.
PERFORM bdc_field USING 'MARA-BRGEW' gs_material-brgew.
PERFORM bdc_field USING 'MARA-GEWEI' gs_material-gewei.
PERFORM bdc_field USING 'MARA-NTGEW' gs_material-ntgew.
"PERFORM bdc_transaction USING 'MM02'.
CALL TRANSACTION 'MM02' USING bdcdata
MODE 'N' . "显示模式:A ;N 后台 ;E:
"此处需记录是否成功
if SY-SUBRC <> 0.
"记录错误信息,备查
endif .
ENDLOOP.
ENDFORM.
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM bdc_field USING fnam fval.
IF fval <> nodata.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDIF.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DATE
*&---------------------------------------------------------------------*
* 初始化数据
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM get_date .
PERFORM add_material USING '301020015252' '物料描述A' '230' '170' 'G' .
PERFORM add_material USING '301020015261' '物料描述B' '200' '260' 'G' .
PERFORM add_material USING '301020015262' '物料描述C' '200' '160' 'G' .
ENDFORM.
FORM add_material USING VALUE(p_matnr)
VALUE(p_maktx)
VALUE(p_brgew)
VALUE(p_ntgew)
VALUE(p_gewei).
CLEAR gs_material .
gs_material-matnr = p_matnr .
gs_material-maktx = p_maktx .
gs_material-brgew = p_brgew .
gs_material-ntgew = p_ntgew .
gs_material-gewei = p_gewei .
APPEND gs_material TO gt_material.
ENDFORM.