SAP ABAP BDC的简单调用

文章目录

  • 需求
  • 代码如下(示例):
  • 总结


需求

使用BDC更改凭证抬头的参考码1


代码如下(示例):

执行后的结果消息会返回到GT_MESSAGE中,可检查

DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
DATA: gt_message TYPE STANDARD TABLE OF bdcmsgcoll WITH HEADER LINE.
  
  CONSTANTS:ctu    LIKE apqi-putactive VALUE 'X',
            mode   LIKE apqi-putactive VALUE 'N',
            update LIKE apqi-putactive VALUE 'L'.  

PERFORM bdc_dynpro      USING 'SAPMF05L' '0100'.
    PERFORM bdc_field_imp       USING 'BDC_CURSOR'
          'RF05L-BELNR'.
    PERFORM bdc_field_imp       USING 'BDC_OKCODE'
          '/00'.
    PERFORM bdc_field_imp       USING 'RF05L-BELNR'
          return-message_v2+(10).
    PERFORM bdc_field_imp       USING 'RF05L-BUKRS'
          generalpostingdata-comp_code.
    PERFORM bdc_field_imp       USING 'RF05L-GJAHR'
          generalpostingdata-pstng_date+(4).
    PERFORM bdc_dynpro      USING 'SAPMF05L' '0700'.
    PERFORM bdc_field_imp       USING 'BDC_CURSOR'
          'BKPF-BELNR'.
    PERFORM bdc_field_imp       USING 'BDC_OKCODE'
          '=VK'.
    PERFORM bdc_dynpro      USING 'SAPMF05L' '1710'.
    PERFORM bdc_field_imp       USING 'BDC_CURSOR'
          'BKPF-XREF1_HD'.
    PERFORM bdc_field_imp       USING 'BDC_OKCODE'
          '=ENTR'.
    PERFORM bdc_field_imp       USING 'BKPF-XREF1_HD'
          s_ext_field-xref1_hd.
    PERFORM bdc_dynpro      USING 'SAPMF05L' '0700'.
    PERFORM bdc_field_imp       USING 'BDC_CURSOR'
          'BKPF-BELNR'.
    PERFORM bdc_field_imp       USING 'BDC_OKCODE'
          '=AE'.
*    PERFORM bdc_transaction USING 'FB02'.
    PERFORM bdc_transaction TABLES gt_message
    USING  'FB02'
          ctu
          mode
          update.
    
    
    
*----------------------------------------------------------------------*
*        Start new screen                                              *
*----------------------------------------------------------------------*
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_IMP USING FNAM FVAL.
*  IF fval IS NOT INITIAL.
    CLEAR BDCDATA.
    BDCDATA-FNAM = FNAM.
    BDCDATA-FVAL = FVAL.
    APPEND BDCDATA.
*  ENDIF.
*  CLEAR  fval.
ENDFORM.    

FORM BDC_TRANSACTION TABLES P_MESSTAB
                     USING  P_TCODE
                            P_CTU
                            P_MODE
                            P_UPDATE.
CALL TRANSACTION P_TCODE USING BDCDATA[]
                     MODE   P_MODE
                     UPDATE P_UPDATE
                     MESSAGES INTO P_MESSTAB.
    ENDFORM.

如果要以session执行 可利用以下代码


*----------------------------------------------------------------------*
*   create batchinput session                                          *
*----------------------------------------------------------------------*
FORM OPEN_GROUP
     USING P_GROUP    LIKE APQI-GROUPID
           P_USER     LIKE APQI-USERID
           P_KEEP     LIKE APQI-QERASE
           P_HOLDDATE LIKE APQI-STARTDATE
           P_CTU      LIKE APQI-PUTACTIVE.

  IF P_CTU <> 'X'.
    CALL FUNCTION 'BDC_OPEN_GROUP'
      EXPORTING
        CLIENT   = SY-MANDT
        GROUP    = P_GROUP
        USER     = P_USER
        KEEP     = P_KEEP
        HOLDDATE = P_HOLDDATE.
  ENDIF.
ENDFORM.


*----------------------------------------------------------------------*
*   end batchinput session                                             *
*----------------------------------------------------------------------*
FORM CLOSE_GROUP USING P_CTU LIKE APQI-PUTACTIVE.
  IF P_CTU <> 'X'.
* close batchinput group
    CALL FUNCTION 'BDC_CLOSE_GROUP'.
  ENDIF.
ENDFORM.

*----------------------------------------------------------------------*
*        Start new transaction according to parameters                 *
*----------------------------------------------------------------------*
FORM BDC_TRANSACTION TABLES P_MESSTAB
                     USING  P_TCODE
                            P_CTU
                            P_MODE
                            P_UPDATE.
  DATA: L_SUBRC LIKE SY-SUBRC.

  IF P_CTU <> 'X'.
    CALL FUNCTION 'BDC_INSERT'
      EXPORTING
        TCODE     = P_TCODE
      TABLES
        DYNPROTAB = BDCDATA[]
      EXCEPTIONS
        OTHERS    = 1.
  ELSE.
    CALL TRANSACTION P_TCODE USING BDCDATA[]
                     MODE   P_MODE
                     UPDATE P_UPDATE
                     MESSAGES INTO P_MESSTAB.
  ENDIF.
  L_SUBRC = SY-SUBRC.
  REFRESH BDCDATA.
  SY-SUBRC = L_SUBRC.
  CLEAR BDCDATA[].
ENDFORM.


*        BATCH INPUT AUTO RUN  立即执行session
    SUBMIT rsbdcsub
      AND RETURN " return when finished
      WITH mappe = 'EVLYYMMK01A'   " batch session name
      WITH von = sy-datum
      WITH bis = sy-datum
      WITH z_verarb = 'X'      " To process
      WITH fehler = ' '        " not batch sessions in error
      WITH logall = 'X'.        " Extended log.

总结

使用BDC需要注意字段的配置属性,是否可输入等。

你可能感兴趣的:(ABAP小工具,SAP,ABAP,BDC)