根据前台需要输入参数,在bapi里面传值,不同业务所需参数不同。
dome1:
"bapi结构赋值
LOOP AT lt_item INTO lw_item.
wa_documentheader-comp_code = lw_item-bukrs. "公司代码
wa_documentheader-doc_date = p_date. "凭证日期
wa_documentheader-pstng_date = p_date. "过账日期
wa_documentheader-doc_type = 'Z4'.
wa_documentheader-username = sy-uname.
wa_documentheader-fisc_year = p_date+0(4).
wa_documentheader-header_txt = '合同税率计算过账'.
wa_documentheader-fis_period = sy-datum+4(2).
CLEAR :wa_accountgl.
lv_i = lv_i + 1.
wa_accountgl-itemno_acc = lv_i. "会计凭证行项目编号
wa_accountgl-gl_account = '6051060000'. "总分类帐帐目
wa_accountgl-item_text = '合同税率计算过账'.
wa_accountgl-profit_ctr = lw_item-prctr. "利润中心
APPEND wa_accountgl TO lt_accountgl.
CLEAR wa_currency_amount.
wa_currency_amount-itemno_acc = lv_i. "行项目编号
wa_currency_amount-amt_doccur = lw_item-taxamount. "金额
wa_currency_amount-currency = 'CNY'.
APPEND wa_currency_amount TO lt_currency_amount.
CLEAR:wa_zbapi_acc01,wa_extension2.
wa_zbapi_acc01-posnr = lv_i.
wa_zbapi_acc01-xnegp = 'X'. "反记账
wa_zbapi_acc01-bschl = '40'.
wa_extension2-structure = 'ZBAPI_ACC01'.
wa_extension2-valuepart1 = wa_zbapi_acc01.
APPEND wa_extension2 TO lt_extension2.
CLEAR :wa_accountgl.
lv_i = lv_i + 1.
wa_accountgl-itemno_acc = lv_i. "会计凭证行项目编号
wa_accountgl-gl_account = lw_item-acctcode. "总分类帐帐目
wa_accountgl-item_text = '合同税率计算过账'.
wa_accountgl-profit_ctr = lw_item-prctr. "利润中心
APPEND wa_accountgl TO lt_accountgl.
CLEAR wa_currency_amount.
wa_currency_amount-itemno_acc = lv_i. "行项目编号
wa_currency_amount-amt_doccur = - lw_item-taxamount. "金额
wa_currency_amount-currency = 'CNY'.
APPEND wa_currency_amount TO lt_currency_amount.
CLEAR:wa_zbapi_acc01,wa_extension2.
wa_zbapi_acc01-posnr = lv_i.
wa_zbapi_acc01-bschl = '50'.
wa_extension2-structure = 'ZBAPI_ACC01'.
wa_extension2-valuepart1 = wa_zbapi_acc01.
APPEND wa_extension2 TO lt_extension2.
"财务凭证为999行,到900行时,进行财务凭证拆分;调用bapi生成凭证
IF lv_i >= 999.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = wa_documentheader
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
currencyamount = lt_currency_amount
return = lt_return
extension2 = lt_extension2.
CLEAR wa_return.
READ TABLE lt_return INTO wa_return WITH KEY type = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'. "失败
LOOP AT lt_return