Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

BAPI for TCode F-02

Former Member
0 Likes
1,627

Hello.

I have been attempting to convert an ABAP BDC program (for Tcode F-02) to a BAPI using BAPI_ACC_GL_POSTING_CHECK and BAPI_ACC_GL_POSTING_POST.

I have succeded to the point that I get an error return from the "CHECK" with the following messages:

BAPI_ACC_GL_POSTING_CHECK return messages.

<b>609 Error in document: BKPFF $ ED1CLNT230

507 G/L account 8432200 is not defined in chart of accounts BTCA</b>

'BTCA' is our Chart of Accounts. This and other G/L's that I have attempted to use are in our Chart of Accounts. I can manually perform Tcode F-02 using the information that I send to the BAPI and generate a CO document.

Following is my ABAP Code:

LOOP AT g_tab_exp_d INTO g_wrk_exp_d.

***************************************************

    • Build the Account G/L table **

***************************************************

g_tab_account_gl-itemno_acc = sy-tabix.

g_tab_account_gl-gl_account = g_wrk_exp_d-hkont.

g_tab_account_gl-bus_area = ''.

g_tab_account_gl-comp_code = g_sav_bukrs.

g_tab_account_gl-pstng_date(4) = g_wrk_exp_h-bldat+4(4).

g_tab_account_gl-pstng_date+4(4) = g_wrk_exp_h-bldat(4).

g_tab_account_gl-fisc_year = g_wrk_exp_h-bldat+4(4).

g_tab_account_gl-item_text = g_wrk_exp_h-bktxt.

g_tab_account_gl-doc_type = 'SA'.

  • g_tab_account_gl-AC_DOC_NO

g_tab_account_gl-FIS_PERIOD = sy-datum+4(2).

  • g_tab_account_gl-STAT_CON

  • g_tab_account_gl-REF_KEY_1

  • g_tab_account_gl-REF_KEY_2

  • g_tab_account_gl-REF_KEY_3

  • g_tab_account_gl-CUSTOMER

  • g_tab_account_gl-VENDOR_NO

  • g_tab_account_gl-ALLOC_NMBR

g_tab_account_gl-costcenter = g_sav_kostl.

  • g_tab_account_gl-ACTTYPE

  • g_tab_account_gl-ORDERID

  • g_tab_account_gl-ORIG_GROUP

  • g_tab_account_gl-COST_OBJ

g_tab_account_gl-profit_ctr = g_wrk_exp_d-prctr.

  • g_tab_account_gl-PART_PRCTR

g_tab_account_gl-wbs_element = g_wrk_exp_d-posid.

  • g_tab_account_gl-NETWORK

  • g_tab_account_gl-ROUTING_NO

  • g_tab_account_gl-ORDER_ITNO

  • g_tab_account_gl-ACTIVITY

  • g_tab_account_gl-PLANT

  • g_tab_account_gl-SALES_ORD

  • g_tab_account_gl-S_ORD_ITEM

APPEND g_tab_account_gl TO g_tab_account_gl.

g_tab_currency_amount-itemno_acc = sy-tabix. "Accounting Document Line Item Number

g_tab_currency_amount-curr_type = '00'. "Currency type and valuation view

g_tab_currency_amount-currency = 'USD'. "Currency Key

  • g_tab_currency_amount-currency_iso = 'INR'. "ISO code currency

IF g_wrk_exp_d-bschl = '50'.

g_tab_currency_amount-amt_doccur = g_wrk_exp_d-wrbtr. "Amount in document currency

ELSE.

g_tab_currency_amount-amt_doccur = g_wrk_exp_d-wrbtr * -1. "Amount in document currency

ENDIF.

  • MOVE g_wrk_exp_d-wrbtr TO g_tab_currency_amount-amt_doccur. "Amount in document currency

  • g_tab_currency_amount-exch_rate = "Exchange rate

  • g_tab_currency_amount-exch_rate_v = "Indirect Quoted Exchange Rate

APPEND g_tab_currency_amount TO g_tab_currency_amount.

ENDLOOP.

*ITEMNO_ACC POSNR_ACC NUMC 10 0 Accounting Document Line Item Number

*CURR_TYPE CURTP CHAR 2 0 Currency type and valuation view

*CURRENCY WAERS CUKY 5 0 Currency Key

*CURRENCY_ISO WAERS_ISO CHAR 3 0 ISO code currency

*AMT_DOCCUR BAPIWRBTR DEC 23 4 Amount in document currency

*EXCH_RATE KURSF DEC 9 5 Exchange rate

*EXCH_RATE_V UKURSM DEC 9 5 Indirect Quoted Exchange Rate

CLEAR: g_wrk_message. REFRESH: g_tab_message.

***************************************************

    • Start of code to populate Tables for BAPI. **

    • **

    • First is the document header -> g_tab_doc_hdr **

    • BAPIACHE08 **

***************************************************

  • g_tab_doc_hdr-obj_type = 'RFBU'. "Reference Procedure

g_tab_doc_hdr-username = sy-uname. "User Name

g_tab_doc_hdr-comp_code = g_sav_bukrs.

g_tab_doc_hdr-doc_date = sy-datum. "Document Date in Document

g_tab_doc_hdr-pstng_date(04) = g_wrk_exp_h-bldat+4(04).

g_tab_doc_hdr-pstng_date+4(04) = g_wrk_exp_h-bldat(04).

g_tab_doc_hdr-fisc_year = sy-datum(4).

g_tab_doc_hdr-header_txt = g_wrk_exp_h-bktxt. "Document Header Text

g_tab_doc_hdr-doc_type = 'SA'. "Document type

  • g_tab_doc_hdr-reason_rev = g_wrk_exp_h-stgrd. "Reason for Reversal

  • IF g_wrk_exp_h-blart_sa EQ 'SA' OR g_wrk_exp_h-blart_sa EQ 'ZI'.

  • g_tab_doc_hdr-doc_type = g_wrk_exp_h-blart_sa.

  • ELSE.

  • g_tab_doc_hdr-doc_type = g_wrk_exp_h-blart_za.

  • ENDIF.

  • g_tab_doc_hdr-obj_key = ''. "'010000125910002007'."Object Key

  • g_tab_doc_hdr-obj_sys = sy-host. "Logical System of source doc.

  • g_tab_doc_hdr-OBJ_KEY_R = "Cancel: object key (AWREF_REV and AWORG_REV)

  • g_tab_doc_hdr-AC_DOC_NO = "Accounting Document Number

  • g_tab_doc_hdr-TRANS_DATE = "Translation date

g_tab_doc_hdr-fis_period = sy-datum+4(2). "Fiscal period

  • g_tab_doc_hdr-REF_DOC_NO = "Reference Document Number

  • g_tab_doc_hdr-COMPO_ACC = "Component in ACC Interface

  • g_tab_doc_hdr-REF_DOC_NO_LONG = "Reference Document Number (for Dependencies see Long Text)

  • g_tab_doc_hdr-ACC_PRINCIPLE = "Accounting Principle

APPEND g_tab_doc_hdr TO g_tab_doc_hdr.

CALL FUNCTION 'BAPI_ACC_GL_POSTING_CHECK'

EXPORTING

documentheader = g_tab_doc_hdr

TABLES

accountgl = g_tab_account_gl

currencyamount = g_tab_currency_amount

return = g_tab_return.

IF NOT g_tab_return IS INITIAL.

WRITE:/ 'BAPI_ACC_GL_POSTING_CHECK return messages.'.

LOOP AT g_tab_return.

WRITE:/ g_tab_return-number, '|',

g_tab_return-message(80).

ENDLOOP.

SKIP 1.

ENDIF.

IF g_tab_return IS INITIAL.

CALL FUNCTION 'BAPI_ACC_GL_POSTING_POST'

EXPORTING

documentheader = g_tab_doc_hdr

  • IMPORTING

  • obj_type = g_tab_obj_type "AWTYP

  • obj_key = g_tab_obj_key "AWKEY

  • obj_sys = g_tab_obj_sys "AWSYS

TABLES

accountgl = g_tab_account_gl

currencyamount = g_tab_currency_amount

return = g_tab_return

extension1 = g_tab_extension.

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = ' '

IMPORTING

return = g_commit_return.

ENDIF.

IF sy-subrc = 0.

IF NOT g_tab_return IS INITIAL.

WRITE:/ 'BAPI_ACC_GL_POSTING_POST return messages.'.

LOOP AT g_tab_return.

WRITE:/ g_tab_return-number, '|',

g_tab_return-message(80).

ENDLOOP.

SKIP 1.

ENDIF.

ENDIF.

ENDIF.

-


I apolygize for the length of this message, but thought it best to include code 'as is'.

Any guidance would be very much appreciated. I have reviewed other posting for FBs1, FB01 and F-02 BAPI's, which have really been helpful, but now I seem to be stuck on this error condition.

g_tab_doc_hdr data - one entry

BFISHER May Recon Open Items Adj

g_tab_account_gl data - two entrys

0000000001 8432200 1000 07/05/2007 SA 2007 11

80000 0000000000 0000

0000000002 8432900 1000 07/05/2007 SA 2007 11

80000 0000000000 0000

g_tab_currency_amount - two entrys

item_acc curr_type currency currency_iso amt_doccur exch_rate exch_rate_v

0000000001 00 USD 1,326.6400 0.00000 -

0000000002 00 USD 1,326.6400- 0.00000 -

Thanks,

Bill Fisher

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,245

Two things - run your account through CONVERSION_EXIT_ALPHA_INPUT:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = g_wrk_exp_d-hkont
  IMPORTING
    output = g_wrk_exp_d-hkont.

before assigning it to the bapi structure.

Also, do not check sy-subrc after the BAPI calls. They do not raise exceptions, so the return code will generally be zero. You have to check the contents of g_tab_return to see what happenned.

Rob

3 REPLIES 3
Read only

Former Member
0 Likes
1,245

Hi Bill,

Can you please try this

IF sy-subrc = 0.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

<b>wait = 'X'</b>

IMPORTING

return = g_commit_return.

ENDIF

and let us know the result.

Regards,

Atish

Read only

Former Member
0 Likes
1,246

Two things - run your account through CONVERSION_EXIT_ALPHA_INPUT:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input  = g_wrk_exp_d-hkont
  IMPORTING
    output = g_wrk_exp_d-hkont.

before assigning it to the bapi structure.

Also, do not check sy-subrc after the BAPI calls. They do not raise exceptions, so the return code will generally be zero. You have to check the contents of g_tab_return to see what happenned.

Rob

Read only

0 Likes
1,245

The conversion of the G/L number as suggested by Rob, led to my discovery that I also needed to do the same with Cost Center and Profit Center. I am now getting valid postings!

Many thanks to Rob Burbank and Atish Sarda for the help.