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

Former Member
0 Likes
772

Hi Friends,

I have one query regarding BAPI.

My requirement is to check & update the G/L account.

For this I am using two Function Module BAPI_ACC_DOCUMENT_CHECK & BAPI_ACC_DOCUMENT_POST.

I would like to ask what are the mandatory parameters for this??

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
563

Hi,

Look at the sample code....................

data: it_hdr like standard table of bapiache09

with header line, "#EC NEEDED

it_gl like standard table of bapiacgl09 with header line,

it_curr like standard table of bapiaccr09 with header line,

t_result like standard table of bapiret2 with header line,

act_rec like standard table of bapiacar09 with header line.

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

The fields which I passed to the structure inside the loop are mandatory.

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

loop at podoc_it.

clear: offset_it, it_hdr, it_gl, it_curr.

refresh: it_hdr, it_gl, it_curr.

read table offset_it with key bukrs = podoc_it-bukrs

saknr = podoc_it-hkont.

  • Header Data

it_hdr-comp_code = podoc_it-bukrs.

it_hdr-doc_date = sy-datum.

it_hdr-pstng_date = sy-datum.

it_hdr-doc_type = podoc_it-blart.

it_hdr-ref_doc_no = bkpf_it-xblnr.

it_hdr-username = sy-uname.

it_hdr-bus_act = 'RFBU'.

IF podoc_it-shkzg = 'S'.

  • First Item

  • Account number

it_gl-itemno_acc = '1'.

it_gl-gl_account = podoc_it-hkont.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Second Item

  • Account number

it_gl-itemno_acc = '2'.

it_gl-gl_account = offset_it-osaknr.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Set amount

it_curr-itemno_acc = '1'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

APPEND it_curr.

it_curr-itemno_acc = '2'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

it_curr-amt_doccur = it_curr-amt_doccur * -1.

APPEND it_curr.

ELSE.

  • First Item

  • Account number

it_gl-itemno_acc = '1'.

it_gl-gl_account = podoc_it-hkont.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Second Item

  • Account number

it_gl-itemno_acc = '2'.

it_gl-gl_account = offset_it-osaknr.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Set amount

it_curr-itemno_acc = '1'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

it_curr-amt_doccur = it_curr-amt_doccur * -1.

APPEND it_curr.

it_curr-itemno_acc = '2'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

APPEND it_curr.

ENDIF.

  • check posting

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

EXPORTING

documentheader = it_hdr

TABLES

accountgl = it_gl

currencyamount = it_curr

return = t_result.

LOOP AT t_result WHERE ( type = 'E' OR

type = 'A' ).

EXIT.

ENDLOOP.

IF sy-subrc <> 0.

REFRESH t_result.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = it_hdr

TABLES

accountgl = it_gl

currencyamount = it_curr

return = t_result.

*

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

move: podoc_it-bukrs to doc_it-bukrs,

podoc_it-belnr to doc_it-belnr,

podoc_it-gjahr to doc_it-gjahr,

podoc_it-shkzg to doc_it-shkzg,

podoc_it-hkont to doc_it-hkont,

offset_it-osaknr to doc_it-osaknr.

ENDIF.

  • Print Message

LOOP AT t_result.

  • WRITE: t_result-message.

  • Get Number

IF t_result-id = 'RW' AND

t_result-number = '605'.

belnr = t_result-message_v2(10).

gjahr = t_result-message_v2+14(4).

ENDIF.

move: belnr to doc_it-obelnr,

gjahr to doc_it-ogjahr.

ENDLOOP.

append doc_it.

clear: doc_it, podoc_it.

endloop.

loop at doc_it.

write:/ doc_it-bukrs,

doc_it-belnr,

doc_it-gjahr,

doc_it-shkzg,

doc_it-hkont,

doc_it-osaknr,

doc_it-obelnr,

doc_it-ogjahr.

endloop.

Thanks.

If this helps you reward with points.

Message was edited by: KDeepak

5 REPLIES 5
Read only

Former Member
0 Likes
563

Hi AMit - Go to the transaction BAPI.

There locate the bapi ur using, and u can find all the necessary documentation - incl. the mandatory fields....

Hope it helps....

-Aarthi.

Read only

Former Member
0 Likes
564

Hi,

Look at the sample code....................

data: it_hdr like standard table of bapiache09

with header line, "#EC NEEDED

it_gl like standard table of bapiacgl09 with header line,

it_curr like standard table of bapiaccr09 with header line,

t_result like standard table of bapiret2 with header line,

act_rec like standard table of bapiacar09 with header line.

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

The fields which I passed to the structure inside the loop are mandatory.

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

loop at podoc_it.

clear: offset_it, it_hdr, it_gl, it_curr.

refresh: it_hdr, it_gl, it_curr.

read table offset_it with key bukrs = podoc_it-bukrs

saknr = podoc_it-hkont.

  • Header Data

it_hdr-comp_code = podoc_it-bukrs.

it_hdr-doc_date = sy-datum.

it_hdr-pstng_date = sy-datum.

it_hdr-doc_type = podoc_it-blart.

it_hdr-ref_doc_no = bkpf_it-xblnr.

it_hdr-username = sy-uname.

it_hdr-bus_act = 'RFBU'.

IF podoc_it-shkzg = 'S'.

  • First Item

  • Account number

it_gl-itemno_acc = '1'.

it_gl-gl_account = podoc_it-hkont.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Second Item

  • Account number

it_gl-itemno_acc = '2'.

it_gl-gl_account = offset_it-osaknr.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Set amount

it_curr-itemno_acc = '1'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

APPEND it_curr.

it_curr-itemno_acc = '2'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

it_curr-amt_doccur = it_curr-amt_doccur * -1.

APPEND it_curr.

ELSE.

  • First Item

  • Account number

it_gl-itemno_acc = '1'.

it_gl-gl_account = podoc_it-hkont.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Second Item

  • Account number

it_gl-itemno_acc = '2'.

it_gl-gl_account = offset_it-osaknr.

it_gl-item_text = podoc_it-sgtxt.

it_gl-fis_period = v_monat.

it_gl-fisc_year = v_gjahr.

it_gl-acct_key = 'A00'.

APPEND it_gl.

  • Set amount

it_curr-itemno_acc = '1'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

it_curr-amt_doccur = it_curr-amt_doccur * -1.

APPEND it_curr.

it_curr-itemno_acc = '2'.

it_curr-currency = podoc_it-waers.

it_curr-amt_doccur = podoc_it-wrbtr.

APPEND it_curr.

ENDIF.

  • check posting

CALL FUNCTION 'BAPI_ACC_DOCUMENT_CHECK'

EXPORTING

documentheader = it_hdr

TABLES

accountgl = it_gl

currencyamount = it_curr

return = t_result.

LOOP AT t_result WHERE ( type = 'E' OR

type = 'A' ).

EXIT.

ENDLOOP.

IF sy-subrc <> 0.

REFRESH t_result.

CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'

EXPORTING

documentheader = it_hdr

TABLES

accountgl = it_gl

currencyamount = it_curr

return = t_result.

*

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

move: podoc_it-bukrs to doc_it-bukrs,

podoc_it-belnr to doc_it-belnr,

podoc_it-gjahr to doc_it-gjahr,

podoc_it-shkzg to doc_it-shkzg,

podoc_it-hkont to doc_it-hkont,

offset_it-osaknr to doc_it-osaknr.

ENDIF.

  • Print Message

LOOP AT t_result.

  • WRITE: t_result-message.

  • Get Number

IF t_result-id = 'RW' AND

t_result-number = '605'.

belnr = t_result-message_v2(10).

gjahr = t_result-message_v2+14(4).

ENDIF.

move: belnr to doc_it-obelnr,

gjahr to doc_it-ogjahr.

ENDLOOP.

append doc_it.

clear: doc_it, podoc_it.

endloop.

loop at doc_it.

write:/ doc_it-bukrs,

doc_it-belnr,

doc_it-gjahr,

doc_it-shkzg,

doc_it-hkont,

doc_it-osaknr,

doc_it-obelnr,

doc_it-ogjahr.

endloop.

Thanks.

If this helps you reward with points.

Message was edited by: KDeepak

Read only

Former Member
0 Likes
563

Hi

For BAPI_ACC_DOCUMENT_CHECK,

DOCUMENTHEADER - Header

RETURN - Return Parameter

For BAPI_ACC_DOCUMENT_POST

DOCUMENTHEADER - Header

CURRENCYAMOUNT - Currency Items

RETURN - Return Parameter

Rgds,

Prakash

Read only

Former Member
0 Likes
563

Hi Amit,

For both BAPIs , import parameter <b>DOCUMENTHEADER</b> ( which is structure for header data) is a mandatory one.

Regds,

Akshay Bhagwat

Read only

Former Member
0 Likes
563

Hi Amit,

For both- > DOCUMENTHEADER is mandatory.

Regards,

HR