从老司机那了解到创建财务凭证就只有两个函数,
用的多的就是 BAPI_ACC_DOCUMENT_POST.
另外,今天发现下另外一个,
418-419 要完成F110 预付款功能的开发,得抓紧时间了。
以下转自[http://blog.csdn.net/trassion/article/details/8267953]
http://www.soujigu.com/blog_76943.html
http://blog.csdn.net/longgerr/article/details/5958210
http://scnblogs.techweb.com.cn/orangeboy/archives/149.html
http://blog.csdn.net/wren2004/article/details/5757565
http://blog.csdn.net/longgerr/article/details/5958210
sap 标准例子 SE38:ACC_BAPI_TEST_DOCUMENT
使用实例:
FUNCTION zrfc_document_post. *"---------------------------------------------------------------------- *"*"Local interface: *" EXPORTING *" REFERENCE(EP_DOCNO) TYPE BELNR_D *" TABLES *" T_DOCUMENT STRUCTURE ZDOCUMENT *" IT_RETURN STRUCTURE BAPIRET2 *"---------------------------------------------------------------------- DATA:wa_documentheader TYPEbapiache09, "待传凭证抬头 工作区 wa_accountgl TYPEbapiacgl09, "总帐科目项 工作区 it_accountgl TYPE STANDARD TABLE OF bapiacgl09, "总帐科目项内表 wa_accountreceivable TYPEbapiacar09, "客户项目 工作区 it_accountreceivable TYPE STANDARD TABLE OFbapiacar09, "客户项目 内表 wa_accountpayable TYPEbapiacap09, "供应商项目 工作区 it_accountpayable TYPE STANDARD TABLE OF bapiacap09, "供应商项目内表 wa_currencyamount TYPEbapiaccr09, "货币项目 工作区 it_currencyamount TYPE STANDARD TABLE OF bapiaccr09, "货币项目 内表 wa_extension2 TYPEbapiparex, "参考结构 工作区 it_extension2 TYPE STANDARD TABLE OFbapiparex, "参考结构 内表 wa_return TYPEbapiret2, "返回参数 工作区 ** it_return TYPE STANDARD TABLE OFbapiret2, "返回参数 内表 wa_zbkpf_send TYPEzbkpf_send, "已导凭证 工作区 it_zbkpf_send TYPE STANDARD TABLE OF zbkpf_send. "已导凭证 内表 DATA: w_document TYPEzdocument, "凭证头 工作区 lw_documentTYPEzdocument. "临时 凭证头 工作区 DATA: cns_dr_r TYPE char2 VALUE‘DR‘, "凭证借方标识 cns_cr_rTYPE char2 VALUE‘CR‘, "凭证贷方标识 cns_x TYPEchar1 VALUE‘X‘, "确认标识 cns_rfbuTYPE char4 VALUE ‘RFBU‘, "业务事务 cns_sa TYPE char2 VALUE‘SA‘, "总分类账凭证 cns_kr TYPE char2 VALUE‘KR‘, "供应商发票 cns_40 TYPE char2 VALUE‘40‘, "总账-借 cns_50 TYPE char2 VALUE‘50‘, "总账-贷 cns_01 TYPE char2 VALUE‘01‘, "应收-借 cns_11 TYPE char2 VALUE‘11‘, "应收-贷 cns_21 TYPE char2 VALUE‘21‘, "应付-借 cns_31 TYPE char2 VALUE‘31‘. "应付-贷 DATA: l_return_tabcount TYPE i. CHECK t_document IS NOT INITIAL. SORT t_document BY belnr ASCENDING. LOOP AT t_document INTO w_document. lw_document = w_document. *------------------------转换表头------------------------------------ AT NEWbelnr. wa_documentheader-bus_act =cns_rfbu. "业务事务 wa_documentheader-username =sy-uname. "系统当前用户 wa_documentheader-comp_code =lw_document-bukrs. "公司代码 wa_documentheader-doc_date =lw_document-bldat. "凭证中的凭证日期 wa_documentheader-pstng_date = lw_document-budat. "凭证中的记帐日期 wa_documentheader-fisc_year =lw_document-gjahr. "会计年度 wa_documentheader-fis_period = lw_document-monat. "会计期间 wa_documentheader-doc_type =lw_document-blart. "凭证类型 wa_documentheader-ref_doc_no = lw_document-xblnr. "参考凭证号 wa_documentheader-header_txt = lw_document-bktxt. "凭证抬头文本 ENDAT. CASElw_document-blart. *------------------------总账科目------------------------------------ WHEN cns_sa. *------------------------总帐科目项---------------------------------- wa_accountgl-itemno_acc =lw_document-buzei. "会计凭证中的行项目数 wa_accountgl-gl_account =lw_document-hkont. "总分类帐帐目 wa_accountgl-comp_code =lw_document-bukrs. "公司代码 wa_accountgl-costcenter =lw_document-kostl. "成本中心 wa_accountgl-profit_ctr =lw_document-prctr. "利润中心 APPEND wa_accountgl TO it_accountgl. CLEAR wa_accountgl. *------------------------供应商发票OR供应商贷项凭证---------------- WHEN cns_kr OR cns_kg. * 统驭科目 IF lw_document-mitkz = cns_x. *------------------------供应商项目---------------------------------- wa_accountpayable-itemno_acc =lw_document-buzei. "会计凭证中的行项目数 wa_accountpayable-vendor_no =lw_document-lifnr. "供应商 APPEND wa_accountpayable TO it_accountpayable. CLEAR wa_accountpayable. * 非统驭科目 ELSE. *------------------------总帐科目项---------------------------------- wa_accountgl-itemno_acc =lw_document-buzei. "会计凭证中的行项目数 wa_accountgl-gl_account =lw_document-hkont. "总分类帐帐目 wa_accountgl-comp_code =lw_document-bukrs. "公司代码 wa_accountgl-costcenter =lw_document-kostl. "成本中心 wa_accountgl-profit_ctr =lw_document-prctr. "利润中心 APPEND wa_accountgl TO it_accountgl. CLEAR wa_accountgl. ENDIF. ENDCASE. *------------------------增强字段----------------------------------- IFlw_document-brnch IS NOT INITIAL. wa_extension2-structure =‘BRNCH‘. "分支号 wa_extension2-valuepart1 =lw_document-buzei. "行项目数 wa_extension2-valuepart2 =lw_document-brnch. "分支号值 APPEND wa_extension2 TO it_extension2. CLEAR wa_extension2. ENDIF. IFlw_document-umskz IS INITIAL. “特别总/分类帐指示符 CASE lw_document-blart. WHEN cns_sa. IF lw_document-shkzg =cns_dr_r. "借贷方记账码 wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_40. ELSEIF lw_document-shkzg = cns_cr_r. wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_50. ENDIF. ENDCASE. APPEND wa_extension2 TO it_extension2. CLEAR wa_extension2. ELSE. wa_extension2-structure =‘UMSKZ‘. "特别总/分类帐指示符 wa_extension2-valuepart1 =lw_document-buzei. "行项目数 wa_extension2-valuepart2 =lw_document-umskz. "特别总/分类帐值 APPEND wa_extension2 TO it_extension2. CLEAR wa_extension2. CASE lw_document-blart. WHEN cns_kr OR cns_kg. IF lw_document-shkzg = cns_dr_r. wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_29. ELSEIF lw_document-shkzg = cns_cr_r. wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_39. ENDIF. WHEN cns_dr OR cns_dg. IF lw_document-shkzg = cns_dr_r. wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_09. ELSEIF lw_document-shkzg = cns_cr_r. wa_extension2-structure = ‘BSCHL‘. wa_extension2-valuepart1 = lw_document-buzei. wa_extension2-valuepart2 = cns_19. ENDIF. ENDCASE. APPEND wa_extension2 TO it_extension2. CLEAR wa_extension2. ENDIF. IFlw_document-sgtxt IS NOT INITIAL. wa_extension2-structure =‘SGTXT‘. "项目文本 wa_extension2-valuepart1 =lw_document-buzei. "行项目数 wa_extension2-valuepart2 =lw_document-sgtxt. "项目文本值 APPEND wa_extension2 TO it_extension2. CLEAR wa_extension2. ENDIF. AT END OFbelnr. CALL FUNCTION ‘BAPI_ACC_DOCUMENT_POST‘ EXPORTING documentheader =wa_documentheader "录入凭证头 TABLES accountgl =it_accountgl "总帐科目项 accountreceivable = it_accountreceivable "客户项目 accountpayable =it_accountpayable "供应商项目 currencyamount =it_currencyamount "货币项目 extension2 =it_extension2 "扩展字段 return =it_return. "返回值 DESCRIBE TABLE it_return LINES l_return_tabcount. IF l_return_tabcount =1. "凭证导入成功 CALL FUNCTION ‘BAPI_TRANSACTION_COMMIT‘. * 记录已导入的凭证号 READ TABLE it_return INTO wa_return INDEX 1. IF sy-subrc EQ 0. ep_docno = wa_return-message_v2+0(10). wa_return-type = ‘S‘. wa_return-message = text-001. APPEND wa_return TO it_return. ELSE. wa_return-type = ‘E‘. wa_return-message = text-002. APPEND wa_return TO it_return. ENDIF. ELSE. "凭证导入失败 ENDIF. CLEAR: l_return_tabcount, wa_zbkpf_send, wa_documentheader, it_accountgl, it_accountpayable, it_currencyamount, it_extension2, it_return. ENDAT. CLEAR:w_document,lw_document. ENDLOOP. ENDIF. ENDFUNCTION.
时间: 2024-10-12 20:07:47