Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

BAPI - - POINTS guarenteed !!!!

hi,

IAm uploading the fields of bkpf from excell sheet into internal table t_record using alsm_excel_to_internal_table. Now i want to post the fields of internal table into transaction f-02 using bapi :

BAPI_ACC_DOCUMENT_POST.

I need sample code which transfers data from t_record to bapi.

regards.

Message was edited by: amna

Tags:
replied

Hi,

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

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.

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question