BAPI_ACC_DOCUMENT_POST 字段增强

 

    1、se11创建结构,必须包含行项目号POSNR字段,和其他需要扩展的字段,如记账码Posting Key、原因代码Reason Code
    2、SE19实现BADI增强,这个增强是用来将BAPI_ACC_DOCUMENT_POST参数表EXTENSION2传入系统表
    3、使用BAPI_ACC_DOCUMENT_POST参数表EXTENSION2,将扩展字段传入

详细步骤如下:
1、创建结构,se11,很简单,不再赘述,如下图:

2、SE19实现BADI增强ACC_DOCUMENT
通过ACC_DOCUMENT help文档知道,方法CHANGE用来完成字段的扩展,还有一个需要注意的是参考业务类型,这个一定要选对,不然执行BAPI的时候不会调用这个BADI,我用的是BKPFF,如下图:

激活这个BADI实现。

双击change方法创建,可以查看ACC_DOCUMENT的实现例子CL_EXM_IM_ACC_DOCUMENT(R/3 4.7版本,其他版本可能名称不一样),,将这个实例的change方法的代码直接copy过来,激活方法,代码如下

***********************************************************************
* Example to move fields from BAPI parameter EXTENSION2 to structure  *
* ACCIT (accounting document line items).                             *
* The dictionary structure (content for EXTENSION2-STRUCTURE) must    *
* contain field POSNR, (TYPE POSNR_ACC) to indentify the correct line *
* item of the internal table ACCIT.                                   *
***********************************************************************

  DATA: wa_extension   TYPE bapiparex,
        ext_value(960) TYPE c,
        wa_accit       TYPE accit,
        l_ref          TYPE REF TO data.

  FIELD-SYMBOLS: <l_struc> TYPE ANY,
                 <l_field> TYPE ANY.

  SORT c_extension2 BY structure.

  LOOP AT c_extension2 INTO wa_extension.
    AT NEW structure.
      CREATE DATA l_ref TYPE (wa_extension-structure).
      ASSIGN l_ref->* TO <l_struc>.
    ENDAT.
    CONCATENATE wa_extension-valuepart1 wa_extension-valuepart2
                wa_extension-valuepart3 wa_extension-valuepart4
           INTO ext_value.
    MOVE ext_value TO <l_struc>.
    ASSIGN COMPONENT 'POSNR' OF STRUCTURE <l_struc> TO <l_field>.
    READ TABLE c_accit WITH KEY posnr = <l_field>
          INTO wa_accit.
    IF sy-subrc IS INITIAL.
      MOVE-CORRESPONDING <l_struc> TO wa_accit.
      MODIFY c_accit FROM wa_accit INDEX sy-tabix.
    ENDIF.
  ENDLOOP.

3、使用BAPI_ACC_DOCUMENT_POST参数表EXTENSION2,将扩展字段传入
**********************************************************************
*INTERNAL TABLE DECLARATION
**********************************************************************

*&—-G/L ACCOUNT ITEM
DATA: ACCOUNTGL TYPE STANDARD TABLE OF BAPIACGL09.

*&—CURRENCY ITEMS
DATA: CURRENCY_AMOUNT TYPE STANDARD TABLE OF BAPIACCR09.

*&—-RETURN PARAMETER
DATA: RETURN TYPE STANDARD TABLE OF BAPIRET2 WITH HEADER LINE.

*&—-it_extension2 ITEMS
DATA: IT_EXTENSION2 TYPE STANDARD TABLE OF BAPIPAREX WITH HEADER LINE.

*&—WORKAREA FOR ZEXTEN
DATA: WA_ZEXTEN LIKE ZEXTEN. ”ZEXTEN就是刚才SE11创建的那个结构

**********************************************************************
*赋值
**********************************************************************

*& EXTENSION2扩展字段增强部分

  WA_ZEXTEN-POSNR = '0000000010'. "凭证行项目
  WA_ZEXTEN-RSTGR = '171'. "凭证行项目原因代码

  IT_EXTENSION2-STRUCTURE  = 'ZEXTEN'.
  IT_EXTENSION2-VALUEPART1 = WA_ZEXTEN.
  APPEND IT_EXTENSION2.

*其他参数表的字段赋值如下例

HEADER-HEADER_TXT = 'TEST HEADER'."凭证抬头文本
  HEADER-USERNAME = SY-UNAME.  "用户名
  HEADER-COMP_CODE = '1000'."公司代码
  HEADER-DOC_DATE = '20090618'."凭证中的凭证日期
  HEADER-PSTNG_DATE = '20090618'."凭证中的记帐日期
  HEADER-DOC_TYPE = 'S1'."凭证类型
*  HEADER-BUS_ACT = 'RFBU'."交易业务

  WA_ACCOUNTGL-ITEMNO_ACC = '0000000010'. "会计凭证行项目编号
  WA_ACCOUNTGL-GL_ACCOUNT = '1002010105'. "总分类帐帐目
*  WA_ACCOUNTGL-ITEM_TEXT = .
  WA_ACCOUNTGL-BUS_AREA = '8000'. "业务范围
  APPEND WA_ACCOUNTGL TO ACCOUNTGL.
  CLEAR WA_ACCOUNTGL.

  WA_ACCOUNTGL-ITEMNO_ACC = '0000000020'. "会计凭证行项目编号
  WA_ACCOUNTGL-GL_ACCOUNT = '1301040000'. "总分类帐帐目
  WA_ACCOUNTGL-BUS_AREA = '8000'. "业务范围
*WA_ACCOUNTGL-ITEM_TEXT = .
*wa_accountgl-ACCT_TYPE = 'R'.
  APPEND WA_ACCOUNTGL TO ACCOUNTGL.
  CLEAR WA_ACCOUNTGL.

  WA_CURRENCY_AMOUNT-ITEMNO_ACC = '0000000010'. "行项目编号
  WA_CURRENCY_AMOUNT-AMT_DOCCUR = '500'. "金额
  WA_CURRENCY_AMOUNT-CURRENCY = 'RMB'.
  APPEND WA_CURRENCY_AMOUNT TO CURRENCY_AMOUNT.
  CLEAR WA_CURRENCY_AMOUNT.

  WA_CURRENCY_AMOUNT-ITEMNO_ACC = '0000000020'.
  WA_CURRENCY_AMOUNT-AMT_DOCCUR = '-500'.
  WA_CURRENCY_AMOUNT-CURRENCY = 'RMB'.
  APPEND WA_CURRENCY_AMOUNT TO CURRENCY_AMOUNT.
  CLEAR WA_CURRENCY_AMOUNT.

  *执行BAPI
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
  EXPORTING
  DOCUMENTHEADER = HEADER
*CUSTOMERCPD =
*CONTRACTHEADER =
*IMPORTING
*OBJ_TYPE =
*OBJ_KEY =
*OBJ_SYS =
  TABLES
  ACCOUNTGL = ACCOUNTGL

*ACCOUNTRECEIVABLE =
*ACCOUNTPAYABLE =
*ACCOUNTTAX =
  CURRENCYAMOUNT = CURRENCY_AMOUNT

*CRITERIA =
*VALUEFIELD =
*EXTENSION1 =
  RETURN = RETURN
*PAYMENTCARD =
*CONTRACTITEM =
  EXTENSION2 = IT_EXTENSION2
*REALESTATE =
  .

  IF RETURN-TYPE NA 'EA'.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT = 'X'.
  ENDIF.
如果还需要扩展其他字段,在结构ZEXTEN加入,然后在调用BAPI前对相应字段赋值,就行了。

posted @ 2016-10-20 13:19  Eric.su  阅读(465)  评论(0编辑  收藏  举报