SAP-ABAP-简单的BDC代码模板

本文以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.

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值