BAPI_ACC_DOCUMENT_POST的extension2扩展结构
扩展结构的创建
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/33d96db4d3f9b72bcb4759146b3aa276.png)
扩展结构的使用
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/e2cfe7a0fe1bf1c045f78c7745d78a0e.png)
完整代码
*&---------------------------------------------------------------------*
*& Report Z_BAPI_ACC_DOCUMENT_LHY
*&---------------------------------------------------------------------*
*& Type:Report
*& Creator:LiuHongyu
*& Create On:2024.2.2
*& Description:创建会计凭证的BAPI:BAPI_ACC_DOCUMENT_POST
*&---------------------------------------------------------------------*
REPORT z_bapi_acc_document_lhy.
DATA documentheader TYPE bapiache09.
*DATA CUSTOMERCPD TYPE BAPIACPA09.
*DATA CONTRACTHEADER TYPE BAPIACCAHD.
*DATA OBJ_TYPE TYPE BAPIACHE09-OBJ_TYPE.
*DATA OBJ_KEY TYPE BAPIACHE09-OBJ_KEY.
*DATA OBJ_SYS TYPE BAPIACHE09-OBJ_SYS.
DATA accountgl TYPE STANDARD TABLE OF bapiacgl09 WITH HEADER LINE.
*DATA ACCOUNTRECEIVABLE TYPE STANDARD TABLE OF BAPIACAR09.
*DATA ACCOUNTPAYABLE TYPE STANDARD TABLE OF BAPIACAP09.
*DATA ACCOUNTTAX TYPE STANDARD TABLE OF BAPIACTX09.
DATA currencyamount TYPE STANDARD TABLE OF bapiaccr09 WITH HEADER LINE.
*DATA CRITERIA TYPE STANDARD TABLE OF BAPIACKEC9.
*DATA VALUEFIELD TYPE STANDARD TABLE OF BAPIACKEV9.
*DATA EXTENSION1 TYPE STANDARD TABLE OF BAPIACEXTC.
DATA return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
*DATA PAYMENTCARD TYPE STANDARD TABLE OF BAPIACPC09.
*DATA CONTRACTITEM TYPE STANDARD TABLE OF BAPIACCAIT.
DATA extension2 TYPE STANDARD TABLE OF bapiparex WITH HEADER LINE.
*DATA REALESTATE TYPE STANDARD TABLE OF BAPIACRE09.
*DATA ACCOUNTWT TYPE STANDARD TABLE OF BAPIACWT09.
DATA lv_datum TYPE d.
DATA ls_zsacc_document TYPE zsacc_document.
lv_datum = sy-datum.
documentheader-comp_code = 1000. "公司代码
documentheader-doc_date = lv_datum. "凭证中的凭证日期
documentheader-pstng_date = lv_datum. "凭证的过账日期
documentheader-doc_type = 'SA'. "凭证日期
documentheader-username = sy-uname. "用户
documentheader-header_txt = '产线报销费用凭证测试-lhy'.
IF accountgl-costcenter IS INITIAL.
"accountgl-costcenter = lt_data-kostl.
"accountgl-costcenter = |{ '17101301' ALPHA = IN }|. "成本中心,这个要有
ENDIF.
accountgl-itemno_acc = '1'. "会计凭证行项目编号
accountgl-material = |{ '5913' ALPHA = IN }|."物料号
accountgl-plant = '1000'. "工厂
"accountgl-orderid = |{ '1001754' ALPHA = IN }|. "订单号
accountgl-gl_account = |{ '1001010000' ALPHA = IN }|. "借方总账科目
"accountgl-gl_account = |{ '11001010' ALPHA = IN }|. "总账科目11001010,用这个试试
accountgl-value_date = sy-datum. "起息日,一定要有
APPEND accountgl.
CLEAR: accountgl.
accountgl-itemno_acc = '2'. "会计凭证行项目编号
accountgl-material = |{ '5913' ALPHA = IN }|."物料号
accountgl-plant = '1000'. "工厂
"accountgl-orderid = |{ '1001754' ALPHA = IN }|. "订单号
accountgl-gl_account = |{ '1001010001' ALPHA = IN }|. "贷方科目
"accountgl-costcenter = |{ '17101301' ALPHA = IN }|. "成本中心,这个要有
"accountgl-gl_account = '10010000' . "总账科目
accountgl-value_date = sy-datum."起息日,一定要有
APPEND accountgl.
CLEAR: accountgl.
currencyamount-itemno_acc = '1'.
currencyamount-curr_type = '00'."评估视图
currencyamount-currency = 'CNY'. "申请币别
currencyamount-amt_doccur = 9999. "金额
APPEND currencyamount.
CLEAR:currencyamount.
currencyamount-itemno_acc = '2'.
currencyamount-curr_type = '00'."评估视图
currencyamount-currency = 'CNY'. "申请币别
currencyamount-amt_doccur = -9999. "金额
APPEND currencyamount.
CLEAR:currencyamount.
"--------------借贷方过账码增强相关的信息------------------------------
CLEAR ls_zsacc_document.
ls_zsacc_document-posnr = 1. "凭证行项目
ls_zsacc_document-bschl = '40'."记账码
CLEAR extension2.
APPEND extension2.
CLEAR ls_zsacc_document.
ls_zsacc_document-posnr = 2. "贷方行项目
ls_zsacc_document-bschl = '50'. "记账码
CLEAR extension2.
extension2-structure = 'ZSACC_DOCUMENT'.
extension2-valuepart1 = ls_zsacc_document.
APPEND extension2.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = documentheader
* CUSTOMERCPD = CUSTOMERCPD
* CONTRACTHEADER = CONTRACTHEADER
* IMPORTING
* OBJ_TYPE = OBJ_TYPE
* OBJ_KEY = OBJ_KEY
* OBJ_SYS = OBJ_SYS
TABLES
accountgl = accountgl
* ACCOUNTRECEIVABLE = ACCOUNTRECEIVABLE
* ACCOUNTPAYABLE = ACCOUNTPAYABLE
* ACCOUNTTAX = ACCOUNTTAX
currencyamount = currencyamount
* CRITERIA = CRITERIA
* VALUEFIELD = VALUEFIELD
* EXTENSION1 = EXTENSION1
return = return
* PAYMENTCARD = PAYMENTCARD
* CONTRACTITEM = CONTRACTITEM
extension2 = extension2
* REALESTATE = REALESTATE
* ACCOUNTWT = ACCOUNTWT
.
IF line_exists( return[ type = 'E'] ). "如果有E的错误行
cl_demo_output=>write( '错误消息:' ).
cl_demo_output=>write( return ).
cl_demo_output=>display( ).
ELSE.
"DATA wait TYPE bapita-wait.
DATA return_transaction TYPE bapiret2.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = return_transaction
.
cl_demo_output=>display( return ).
ENDIF.