[原创]BAPI: BAPI_ACC_DOCUMENT_POST
——生成总账\应收\应付会计凭证的源程序
关于BAPI的查找: 事务代码 BAPI.
该事务码中包括了全部BAPI.
** 以下是生成总账会计凭证的源码:
REPORT zfb01_bapi.
*****声明变量和内表
DATA: gs_docheader LIKE bapiache09, "会计凭证抬头内表
gt_accountgl LIKE TABLE OF bapiacgl09 WITH HEADER LINE, "一般总账行项目表
gt_acccustar LIKE TABLE OF bapiacar09 WITH HEADER LINE, "客户应收行项目表
gt_accvendap LIKE TABLE OF bapiacap09 WITH HEADER LINE, "供应商应付行项表
gt_accounttax LIKE TABLE OF bapiactx09 WITH HEADER LINE, "税科目内表
gt_curramount LIKE TABLE OF bapiaccr09 WITH HEADER LINE, "行项货币金额内表
gt_extension LIKE TABLE OF bapiacextc WITH HEADER LINE, "出口内表
gt_return LIKE TABLE OF bapiret2 WITH HEADER LINE. "值返回内表
DATA: gv_post_doc LIKE bapiache09-obj_key. "凭证号变量
*****调用过程
PERFORM fill_header.
PERFORM fill_gl. "一般总账(GL), 本例为凭证行项目0001行
PERFORM fill_ar. "客户(应收AR), 本例为凭证行项目0002行
PERFORM fill_ap. "供应商(应付AP), 本例为凭证行项目0003行
*perform fill_accounttax."税TAX科目
PERFORM fill_curramount. "行项货币和金额1~3行项
*****调用会计凭证记账前的检查
CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'
EXPORTING
documentheader = gs_docheader
* CUSTOMERCPD =
* CONTRACTHEADER =
TABLES
accountgl = gt_accountgl
accountreceivable = gt_acccustar
accountpayable = gt_accvendap
* accounttax =
currencyamount = gt_curramount
* CRITERIA =
* VALUEFIELD =
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
extension1 = gt_extension
return = gt_return.
*****调用会计凭证的记账
READ TABLE gt_return WITH KEY type = 'E'.
IF sy-subrc <> 0. "找不到错误
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = gs_docheader
* CUSTOMERCPD =
* CONTRACTHEADER =
IMPORTING
* OBJ_TYPE =
obj_key = gv_post_doc
* OBJ_SYS =
TABLES
accountgl = gt_accountgl
accountreceivable = gt_acccustar
accountpayable = gt_accvendap
* ACCOUNTTAX =
* CRITERIA =
* VALUEFIELD =
* PAYMENTCARD =
* CONTRACTITEM =
* EXTENSION2 =
* REALESTATE =
currencyamount = gt_curramount
extension1 = gt_extension
return = gt_return.
COMMIT WORK AND WAIT.
WRITE: 'Posting Document: ', gv_post_doc.
ELSE.
WRITE: 'Error!'.
ENDIF.
*&--------------------------------------------------------------------*
*& Form fill_header
*&--------------------------------------------------------------------*
FORM fill_header .
CLEAR gs_docheader.
gs_docheader-comp_code = '1100'. "公司代码,必输
gs_docheader-doc_date = sy-datum. "凭证日期,必输
gs_docheader-pstng_date = sy-datum. "记帐日期,必输
gs_docheader-fis_period = sy-datum+4(2). "凭证的会计期间, 必输
gs_docheader-fisc_year = sy-datum(4). "凭证的会计年度
gs_docheader-doc_type = 'SA'. "凭证类型,必输
gs_docheader-trans_date = sy-datum. "凭证的换算日期
* gS_docheader-obj_type = 'IDOC'.
* gS_docheader-obj_key = '$'.
* gS_docheader-obj_sys = 'BGS1'.
gs_docheader-bus_act = 'RFBU'. "交易业务,必输
gs_docheader-username = sy-uname. "用户名,必输
gs_docheader-header_txt = 'Header Text'. "凭证抬头文本
gs_docheader-ref_doc_no = 'Reference Doc No'. "参考凭证编号
gs_docheader-reason_rev = ''. "凭证的冲销原因
ENDFORM. " fill_header
*&--------------------------------------------------------------------*
*& Form fill_curramount
*&--------------------------------------------------------------------*
FORM fill_curramount .
gt_curramount-itemno_acc = 1. "行项目编号0001行
* gt_curramount-curr_type = '25'. "货币类型和评估视图
gt_curramount-currency = 'CNY'. "货币代码
gt_curramount-amt_doccur = '500'. "凭证货币金额
gt_curramount-exch_rate = 0. "汇率
APPEND gt_curramount.
gt_curramount-itemno_acc = 2. "行项目编号0002行
* gt_curramount-curr_type = '25'. "货币类型和评估视图
gt_curramount-currency = 'CNY'. "货币代码
gt_curramount-amt_doccur = '-300'. "凭证货币金额
gt_curramount-exch_rate = 0. "汇率
APPEND gt_curramount.
gt_curramount-itemno_acc = 3. "行项目编号0003行
* gt_curramount-curr_type = '25'. "货币类型和评估视图
gt_curramount-currency = 'CNY'. "货币代码
gt_curramount-amt_doccur = '-200'. "凭证货币金额
gt_curramount-exch_rate = 0. "汇率
APPEND gt_curramount.
ENDFORM. " fill_curramount
*&--------------------------------------------------------------------*
*& Form fill_gl
*&--------------------------------------------------------------------*
FORM fill_gl .
CLEAR gt_accountgl.
gt_accountgl-itemno_acc = 1. "行项目编号0001行, 必输
gt_accountgl-gl_account = '0010010101'. "总分类帐帐目, 必输
gt_accountgl-comp_code = '1100'. "公司代码, 必输
gt_accountgl-acct_type = 'S'. "帐户类型, 必输
gt_accountgl-costcenter = ''. "成本中心
gt_accountgl-profit_ctr = ''. "利润中心
gt_accountgl-bus_area = ''. "业务范围
gt_accountgl-customer = ''. "客户编号
gt_accountgl-vendor_no = ''. "供应商编号
gt_accountgl-alloc_nmbr = '分配1'. "分配
gt_accountgl-item_text = '行项目文本1'. "行项目文本
APPEND gt_accountgl.
ENDFORM. " fill_gl
*&---------------------------------------------------------------------*
*& Form fill_ar
*&---------------------------------------------------------------------*
FORM fill_ar .
CLEAR gt_acccustar.
gt_acccustar-itemno_acc = 2. "行项目编号0002行, 必输
gt_acccustar-customer = 'A10001'. "客户编码,必输
gt_acccustar-gl_account = ''. "统驭总帐科目,自动默认
gt_acccustar-comp_code = '1100'. "公司代码,必输
gt_acccustar-pmnttrms = '0001'. "付款条件代码
gt_acccustar-bline_date = sy-datum. "到期日计算的基限日期
gt_acccustar-sp_gl_ind = ''. "特殊总分类帐标志
gt_acccustar-tax_code = ''. "销售/购买税代码
gt_acccustar-bus_area = ''. "业务范围
gt_acccustar-alloc_nmbr = '分配2'. "分配号
gt_acccustar-item_text = '行项目文本2'. "行项目文本
APPEND gt_acccustar.
ENDFORM. " fill_ar
*&---------------------------------------------------------------------*
*& Form fill_ap
*&---------------------------------------------------------------------*
FORM fill_ap .
CLEAR gt_accvendap.
gt_accvendap-itemno_acc = 3. "行项目编号0003行, 必输
gt_accvendap-vendor_no = '0000020025'. "供应商编码,必输
gt_accvendap-gl_account = ''. "统驭总帐科目,自动默认
gt_accvendap-comp_code = '1100'. "公司代码,必输
gt_accvendap-pmnttrms = '0001'. "付款条件代码
gt_accvendap-bline_date = sy-datum. "到期日计算的基限日期
gt_accvendap-sp_gl_ind = ''. "特殊总分类帐标志
gt_accvendap-tax_code = ''. "销售/购买税代码
gt_accvendap-bus_area = ''. "业务范围
gt_accvendap-alloc_nmbr = '分配3'. "分配号
gt_accvendap-item_text = '行项目文本3'. "行项目文本
APPEND gt_accvendap.
ENDFORM. " fill_ap
*&---------------------------------------------------------------------*
*& Form fill_accounttax
*&---------------------------------------------------------------------*
FORM fill_accounttax .
CLEAR gt_accounttax.
gt_accounttax-itemno_acc = 4.
gt_accounttax-gl_account = '0000154000'.
gt_accounttax-tax_code = 'V1'.
gt_accounttax-acct_key = 'VST'.
* GT_ACCOUNTTAX-TAXJURCODE =
* Gt_accounttax-cond_key =
* GT_ACCOUNTTAX-TAX_RATE =
* GT_ACCOUNTTAX-TAX_DATE =
* GT_ACCOUNTTAX-STAT_CON =
* GT_ACCOUNTTAX-taxjurcode_deep
* GT_ACCOUNTTAX-taxjurcode_level
APPEND gt_accounttax.
ENDFORM. " fill_accounttax
* OVER *
关于记账码还待研究...
阅读(3199) | 评论(0) | 转发(3) |