Reason Codes enhanced accounting documents

 

 

    Use BAPI_ACC_DOCUMENT_POST accounting documents created with the expansion BADI

Business need: bank and make an interface to produce accounting documents flowing through banks, accounting documents of the transaction code is F-02, found the BAPI method BAPI_ACC_DOCUMENT_POST. Yesterday, the test found that some parameters in BAPI_ACC_DOCUMENT_POST no input parameters and tables, such as billing code Posting Key, Reason Code Reason Code, then how the values of these fields pass into it? SDN checked in solutions related issues, find friends encountered this problem pretty much summed up what the solution roughly as follows:
   1, SE11 create a structure must include the line item number POSNR field, and the other to be expanded field, such as billing codes Posting Key, code reason code reason
   2, SE19 BADI achieve enhanced ACC_DOCUMENT, this enhancement is used to BAPI_ACC_DOCUMENT_POST EXTENSION2 into the system parameter table in table
   3, using the parameter table EXTENSION2 BAPI_ACC_DOCUMENT_POST, incoming extension field

Detail steps are as follows:
1, to create the structure, SE11, very simple, omitted, as shown below:

2, SE19 achieve BADI enhancement ACC_DOCUMENT
by ACC_DOCUMENT help document know, CHANGE method used to complete the extension field, there is a need for attention is a reference type of business, this must choose, when otherwise not perform BAPI call this BADI, I use BKPFF, as shown below:

Activate the BADI implementation.

Double-click way to create change, you can view ACC_DOCUMENT implementation example CL_EXM_IM_ACC_DOCUMENT (R / 3 4.7 version, other versions may be different names) ,, code change the method of this instance copy directly over the activation method, as follows

 

 

***********************************************************************
* 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前对相应字段赋值,就行了。

 

Guess you like

Origin www.cnblogs.com/rainysblog/p/11974273.html