本文以MSC2N修改批次主数据上的失效日期为例,来提供一个简单的BDC批导代码模板
定义
DATA: bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA: messtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
form 构造屏幕及字段表
* bdcdata-program:程序名
* bdcdata-dynpro:屏幕号
FORM bdc_dynpro USING program dynpro.
CLEAR bdcdata.
bdcdata-program = program.
bdcdata-dynpro = dynpro.
bdcdata-dynbegin = 'X'.
APPEND bdcdata.
ENDFORM.
* bdcdata-fnam:字段名
* bdcdata-fval:字段值
FORM bdc_field USING fnam fval.
CLEAR bdcdata.
bdcdata-fnam = fnam.
bdcdata-fval = fval.
APPEND bdcdata.
ENDFORM.
赋值并处理返回消息
DATA LV_MSEG TYPE C LENGTH 128 .
LOOP AT GT_GOODS_MVT INTO GS_GOODS_MVT.
PERFORM bdc_dynpro USING 'SAPLCHRG' '1000' .
PERFORM bdc_field USING 'BDC_OKCODE' '=ENTR' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 1111SUBSCR_BATCH_MASTER' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 1501SUBSCR_HEADER' .
PERFORM bdc_field USING 'BDC_CURSOR' 'DFBATCH-MATNR' .
PERFORM bdc_field USING 'DFBATCH-MATNR' GS_GOODS_MVT-MATNR .
PERFORM bdc_field USING 'DFBATCH-CHARG' GS_GOODS_MVT-CHARG .
PERFORM bdc_field USING 'DFBATCH-WERKS' GS_GOODS_MVT-WERKS .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 2000SUBSCR_TABSTRIP' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 2100SUBSCR_BODY' .
PERFORM bdc_dynpro USING 'SAPLCHRG' '1000' .
PERFORM bdc_field USING 'BDC_OKCODE' '=SAVE' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 1111SUBSCR_BATCH_MASTER' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 1501SUBSCR_HEADER' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 2000SUBSCR_TABSTRIP' .
PERFORM bdc_field USING 'BDC_SUBSCR' 'SAPLCHRG 2100SUBSCR_BODY' .
PERFORM bdc_field USING 'BDC_CURSOR' 'DFBATCH-MHD_IO' .
PERFORM bdc_field USING 'DFBATCH-MHD_IO' GS_GOODS_MVT-VERAB .
CALL TRANSACTION 'MSC2N' USING bdcdata MODE 'N' MESSAGES INTO messtab.
READ TABLE messtab WITH KEY MSGTYP = 'E' TRANSPORTING NO FIELDS .
IF SY-SUBRC = 0.
GS_RETURN-MTYPE = 'E' .
ELSE .
GS_RETURN-MTYPE = 'S' .
ENDIF.
LOOP AT messtab.
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = messtab-msgid
msgnr = messtab-msgnr
msgv1 = messtab-msgv1
msgv2 = messtab-msgv2
msgv3 = messtab-msgv3
msgv4 = messtab-msgv4
IMPORTING
message_text_output = LV_MSEG.
GS_RETURN-MESSA = GS_RETURN-MESSA && LV_MSEG .
CLEAR : LV_MSEG.
ENDLOOP.
GS_GOODS_MVT-MTYPE = GS_RETURN-MTYPE .
GS_GOODS_MVT-MESSAGE = GS_RETURN-MESSA .
MODIFY GT_GOODS_MVT FROM GS_GOODS_MVT .
CLEAR GS_RETURN .
ENDLOOP.