Skip to Content
avatar image
Former Member

How to use BAPI_ACC_GL_POSTING_POST for f-02 transaction.

Dear members,
I am New to ABAP.
I got a requirement of gl account posting using BAPI_ACC_GL_POSTING_POST .

I have a flat file with multiple Headers and each header will have multiple line items.

1.How to post these type of flat file using Bapi?

2.After posting through bapi_acc_gl_posting_post, i have to generate a report showing Detail of line item in which error has occured.
I have gone through many threads but could not find any answer...

I have the following field in flat file (Excel file )

Mandatory field : Document date,Posting date,Document type,Company code,Currency,Document header text, posting key, Account Number, Amount,Profit center. and I too have some optional fields.
I know how to do it using BDC recording because of the requirement i am forced to do it using bapi.

Regards,
Moin.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    May 14 at 07:00 AM

    Hi Mohamad,

    Please refer the below code this may be useful for you.

    1. DATA:
    2. * Structure for document header
    3. g_docheader LIKE bapiache08,
    4. * Table and header for G/L Account Line Items
    5. gi_accountgl TYPE STANDARD TABLE OF bapiacgl08,
    6. g_accountgl LIKE bapiacgl08,
    7. * Table and header for Line Item Currency Fields
    8. gi_amount TYPE STANDARD TABLE OF bapiaccr08,
    9. g_amount LIKE bapiaccr08,
    10. * Return
    11. gi_return TYPE STANDARD TABLE OF bapiret2,
    12. g_return LIKE bapiret2.
    13. START-OF-SELECTION.
    14. *---------------------------------------------------------
    15. * HEADER DATA
    16. *---------------------------------------------------------
    17. g_docheader-obj_type = 'BKPFF'.
    18. g_docheader-obj_key = '1'.
    19. g_docheader-obj_sys = 'B3TCLNT800'.
    20. g_docheader-username = sy-uname.
    21. g_docheader-header_txt = 'BAPI test'.
    22. g_docheader-comp_code = '1000'.
    23. g_docheader-doc_date = sy-datum.
    24. *---------------------------------------------------------
    25. * LINE ITEMS
    26. *---------------------------------------------------------
    27. * Item 1
    28. g_accountgl-itemno_acc = '0000000001'.
    29. g_accountgl-gl_account = '0000192600'.
    30. g_accountgl-pstng_date = sy-datum.
    31. APPEND g_accountgl TO gi_accountgl.
    32. * Item 2
    33. g_accountgl-itemno_acc = '0000000002'.
    34. g_accountgl-gl_account = '0000192600'.
    35. g_accountgl-pstng_date = sy-datum.
    36. APPEND g_accountgl TO gi_accountgl.
    37. *---------------------------------------------------------
    38. * CURRENCY AND AMOUNT
    39. *---------------------------------------------------------
    40. * Item 1
    41. g_amount-itemno_acc = '0000000001'.
    42. g_amount-currency = 'EUR'.
    43. g_amount-amt_doccur = 5000.
    44. APPEND g_amount TO gi_amount.
    45. * Item 2
    46. g_amount-itemno_acc = '0000000002'.
    47. g_amount-currency = 'EUR'.
    48. g_amount-amt_doccur = -5000.
    49. APPEND g_amount TO gi_amount.
    50. END-OF-SELECTION.
    51. * Call the BAPI function
    52. CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'
    53. EXPORTING
    54. documentheader = g_docheader
    55. * IMPORTING
    56. * OBJ_TYPE =
    57. * OBJ_KEY =
    58. * OBJ_SYS =
    59. TABLES
    60. accountgl = gi_accountgl
    61. currencyamount = gi_amount
    62. return = gi_return
    63. * EXTENSION1 =
    64. .
    65. LOOP AT gi_return INTO g_return.
    66. WRITE: / g_return-message.
    67. ENDLOOP.

    Regards

    Srujana

    Add comment
    10|10000 characters needed characters exceeded

  • May 24, 2017 at 01:54 PM

    Use any search tool (google, launchpad) there are already many blogs with sample codes on BAPI_ACC_DOCUMENT_POST and BAPI_ACC_GL_POSTING_POST, also read the BAPI documentation (suggestion: read for both BAPI). As for any BAPI after each call, one per document, build a protocol with the messages (Success, Error, etc.) returned in RETURN parameter, if no error use BAPI_TRANSACTION_COMMIT, else... etc.

    Add comment
    10|10000 characters needed characters exceeded