[reprint] Generate general Ledger accounting voucher of the source program

Source: Internet
Author: User

Transferred from: http://blog.chinaunix.net/uid-22490185-id-75722.html

BAPI: Bapi_acc_gl_posting_post

source program for generating general ledger accounting vouchers

1. BAPI fields without a billing code

BAPI is generally called to other systems, so BAPI's parameter field names and SAP fields are different, for other systems easier to understand, in addition to SAP, other systems have the accounting code to say?!

2. BAPI does not return SAP voucher number after successful creation

Obj_ reference Transaction, Obj_key field reference key These 2 parameters, if assigned, will not have the credential number information for SAP in the return message.

3. About Extension1 Parameters

Extension storage can be borrowed when the user's accounting voucher information is not supported in BAPI. SAP provides enhancements to operate on this parameter.

Bapi_acc_gl_posting_post:user Exit ACBAPI01

Bapi_acc_document_post:badi Acc_document~change

4. Return returned information was created successfully, but no credentials were found in the SAP system

Did you forget the commit work?!

**  The following is the source code for generating general Ledger accounting documents:

Report zbapi_gl_posting.

**** Sound variable and inner table

Data:obj_type like Bapiache02-obj_type, "reference process

Obj_key like Bapiache02-obj_key, "Object keyword

Obj_sys like Bapiache02-obj_sys, "logical system of Source credentials

Gs_dochead like Bapiache08, "Credential header structure

GT_ACCOUNTGL like bapiacgl08 occurs 0 with HEADER lines, "line Item table

Gt_curramount like bapiaccr08 occurs 0 with HEADER line," Currency Amount

Gt_return like Bapiret2 occurs 0 with HEADER line, "post-accounting value returned

Gt_extension like BAPIEXTC occurs 0 with HEADER line, " Customer exit parameters

Bapi_retn_info like Bapiret2 occurs 0 with HEADER line.

Data:v_error_flag.

****  The rise of accounting vouchers corresponding BKPF table

Gs_dochead-comp_code = ' 1100 '. "Certificate of the company code, must lose

Gs_dochead-doc_date = Sy-datum. "Voucher date, must lose

Gs_dochead-pstng_date = Sy-datum. "The voucher is dated and must be lost.

Gs_dochead-fis_period = Sy-datum+4 (2). "The accounting period of the voucher must be lost.

Gs_dochead-doc_type = ' SA '. Voucher type of voucher, must lose

Gs_dochead-username = Sy-uname. "Voucher entry user, must lose

Gs_dochead-header_txt = ' Test using BAPI '. The header text of the voucher

Gs_dochead-trans_date = Sy-datum. The conversion date of the voucher

Gs_dochead-fisc_year = Sy-datum (4). The fiscal year of the voucher

Gs_dochead-reason_rev = ' 03 '. "Reason for reversal of voucher

Gs_dochead-ref_doc_no = '. The reference voucher number of the voucher

The line item Correspondence bseg table of Accounting voucher

GT_ACCOUNTGL-ITEMNO_ACC = 1. "Voucher line item number, must lose

Gt_accountgl-gl_account = ' 0010010113 '. "G/L account, must lose

Gt_accountgl-comp_code = ' 1100 '. "Company code, must lose

Gt_accountgl-costcenter = '. The cost center

Gt_accountgl-bus_area = ' 1103 '. "Business scope

Gt_accountgl-customer = ' A10003 '. The customer number

Gt_accountgl-vendor_no = ' 20025 '. The vendor number

GT_ACCOUNTGL-ALLOC_NMBR = ' Allocate 1 '. The Assign

Gt_accountgl-item_text = ' line item text 1 '. The line item text

APPEND GT_ACCOUNTGL.

GT_ACCOUNTGL-ITEMNO_ACC = 2.

Gt_accountgl-gl_account = ' 0055020129 '.

Gt_accountgl-comp_code = ' 1100 '.

Gt_accountgl-costcenter = ' xx 11010107 '.

Gt_accountgl-bus_area = ' 1103 '.

Gt_accountgl-customer = ' A10003 '.

Gt_accountgl-vendor_no = ' 20025 '.

GT_ACCOUNTGL-ALLOC_NMBR = ' Allocate 2 '.

Gt_accountgl-item_text = ' line Item Text 2 '.

APPEND GT_ACCOUNTGL.

***** the currency of the line item / Gold Amount

GT_CURRAMOUNT-ITEMNO_ACC = 1. "Line item number, must lose

gt_curramount-currency = ' CNY '. "Line item voucher currency, must lose

gt_curramount-amt_doccur = ' 100.00 '. "Line item amount, must lose

Gt_curramount-exch_rate = 0. The line item exchange rate

APPEND Gt_curramount.

GT_CURRAMOUNT-ITEMNO_ACC = ' 2 '.

gt_curramount-currency = ' CNY '.

Gt_curramount-amt_doccur = '-100.00 '.

Gt_curramount-exch_rate = 0.

APPEND Gt_curramount.

**** calling function functions: Posting of general Ledger vouchers

Call FUNCTION ' Bapi_acc_gl_posting_post '

Exporting

Documentheader = gs_dochead "Credential header

* Importing

* Obj_type = Obj_type

* Obj_key = Obj_key

* Obj_sys = Obj_sys

TABLES

ACCOUNTGL = GT_ACCOUNTGL "Voucher line item

Currencyamount = Gt_curramount "Voucher currency and amount

return = Gt_return "value returned

Extension1 = gt_extension "Exception exit

EXCEPTIONS

OTHERS = 1.

IF SY-SUBRC <> 0. "[[[

MESSAGE ' problem occured ' TYPE ' I '.

ELSE. "|||

LOOP at Gt_return.

CLEAR Bapi_retn_info.

Move-corresponding Gt_return to Bapi_retn_info.

IF gt_return-type = ' A ' OR gt_return-type = ' E '.

V_error_flag = ' X '.

ENDIF.

APPEND Bapi_retn_info.

Endloop.

IF v_error_flag = ' X '.

MESSAGE ' problem occured ' TYPE ' I '.

ROLLBACK work.

ELSE.

COMMIT work.

MESSAGE ' DOCUMENT is created! ' TYPE ' I '.

ENDIF.

ENDIF. "]]]

[reprint] Generate general Ledger accounting voucher of the source program

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.