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_ACC_DOCUMENT_POST ?

Former Member
0 Likes
1,923

hi,

i was using BAPI_ACC_DOCUMENT_POST to do document posting, but should it give me a document number when successfully posted ? for example, when using f-43 and press save button, it'll said "Document XXXX was posted to.....".

i wander to know if BAPI_ACC_DOCUMENT_POST do same things as f-43, and if so, how to get the document XXXX number ? there's no such number in the return parameter.

(Note i a do commit it using BAPI_TRANSACTION_COMMIT )

thank you !

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,348

Hello Zhang

Have you checked the value in EXPORTING parameter <b>OBJ_KEY</b>?

Assuming that you post a FI document the object key should look like:

- <company code><document number>

Example:

- Company code = '1000'

- Document number -> internal number when new document is created ('1234567890'

=> obj_key= '10001234567890'

Regards

Uwe

4 REPLIES 4
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,349

Hello Zhang

Have you checked the value in EXPORTING parameter <b>OBJ_KEY</b>?

Assuming that you post a FI document the object key should look like:

- <company code><document number>

Example:

- Company code = '1000'

- Document number -> internal number when new document is created ('1234567890'

=> obj_key= '10001234567890'

Regards

Uwe

Read only

Sougata
Active Contributor
0 Likes
1,348

Hi Zhang,

After you call the BAPI_ACC_DOCUMENT_POST with correct parameters, the FI document (in your case vendor invoice) should be successfully posted and return table RETURN filled with system messages. Now loop at/read table RETURN with field TYPE = 'S' and ID = 'RW' and NUMBER = '605'. (These values have been hard-coded within the BAPI code by SAP - so you need not worry). <b>If the read was successful, the document number posted will be the first 10 characters in the field MESSAGE_V2 in table RETURN.</b>

Don't forget to reward points.

Cheers,

Sougata.

Read only

Former Member
0 Likes
1,348

Hi ,

Can you send me thr program to post document through BAPI_ACC_DOCUMENT_POST.I have a scenerio to post document through Transaction Code : f-43.

Regards,

L Srikanthan

Read only

0 Likes
1,348

hi,

code part my place

data:

documentheader like bapiache09,

accountgl like table of bapiacgl09 with header line,

accountpayable like table of bapiacap09 with header line,

currencyamount like table of bapiaccr09 with header line,

return like table of bapiret2 with header line,

obj_type like bapiache09-obj_type,

obj_key like bapiache09-obj_key,

obj_sys like bapiache09-obj_sys.

form main_bapi.

loop at it_data into wa_data.

" prepare posting code for items

case wa_data-bschl.

when '22' or '25' or '26'. " &#20511;

flag = 'D'.

when '31' or '35' or '36'.

flag = 'C'.

endcase.

" fill document header

documentheader-doc_date = wa_data-bldat. " &#20973;&#35777;&#26085;&#26399;

documentheader-pstng_date = p_budat. " &#35760;&#24080;&#26085;&#26399;

documentheader-doc_type = wa_data-blart. " &#20973;&#35777;&#31867;&#22411;

documentheader-fis_period = p_monat. " &#36807;&#36134;&#26399;&#38388;

documentheader-comp_code = '3100'. " &#20844;&#21496;&#20195;&#30721;

" &#36135;&#24065;

documentheader-ref_doc_no = wa_data-xblnr. " &#21442;&#29031;

documentheader-header_txt = wa_data-bktxt. " &#20973;&#35777;&#25260;&#22836;&#25991;&#26412;

documentheader-username = sy-uname.

documentheader-bus_act = 'RFBU'. " &#24635;&#24080;&#20107;&#21153;&#31867;&#22411;

" fill line items

if wa_data-blart = 'KZ'.

clear accountpayable.

accountpayable-itemno_acc = 1.

accountpayable-vendor_no = wa_data-lifnr. " &#20379;&#24212;&#21830;

accountpayable-bline_date = wa_data-zfbdt. " &#22522;&#20934;&#26085;&#26399;

accountpayable-alloc_nmbr = '310100'. " &#20998;&#37197;

accountpayable-item_text = wa_data-sgtxt. " &#39033;&#30446;&#25991;&#26412;

append accountpayable.

clear accountgl.

accountgl-itemno_acc = 2.

accountgl-gl_account = '9999999999'.

accountgl-item_text = wa_data-sgtxt.

accountgl-doc_type = 'S'.

accountgl-alloc_nmbr = '0000310100'.

accountgl-profit_ctr = '0000310100'.

accountgl-funds_ctr = '0000310100'.

append accountgl.

clear currencyamount.

currencyamount-itemno_acc = 1. " &#34892;&#39033;&#30446;&#32534;&#21495;

currencyamount-currency = 'CNY'. " &#36135;&#24065;

if flag = 'C'.

currencyamount-amt_doccur = wa_data-wrbtr * ( -1 ).

else.

currencyamount-amt_doccur = wa_data-wrbtr.

endif.

currencyamount-disc_base = currencyamount-amt_doccur.

append currencyamount.

clear currencyamount.

currencyamount-itemno_acc = 2. " &#34892;&#39033;&#30446;&#32534;&#21495;

currencyamount-currency = 'CNY'. " &#36135;&#24065;

if flag = 'C'.

currencyamount-amt_doccur = wa_data-wrbtr .

else.

currencyamount-amt_doccur = wa_data-wrbtr * ( -1 ).

endif.

currencyamount-disc_base = currencyamount-amt_doccur.

append currencyamount.

endif.

if wa_data-blart = 'RE'.

clear it_bseg.

refresh it_bseg.

" line items table IT_BSEG

select bukrs belnr buzei gjahr koart lifnr

zuonr wrbtr ebeln ebelp bschl projk

sgtxt zterm zfbdt

from bseg

into corresponding fields of table it_bseg

where bukrs = wa_data-bukrs

and belnr = wa_data-belnr

and gjahr = wa_data-gjahr.

loop at it_bseg where koart = 'K'.

t_lifnr = it_bseg-lifnr.

endloop.

" loop through line items

index = 1.

loop at it_bseg.

if it_bseg-koart = 'K'.

t_lifnr = it_bseg-lifnr.

" if vendor item, generate a G/L item accordingly

clear accountgl.

accountgl-gl_account = '9999999999'. " &#24635;&#20998;&#31867;&#24080;&#24080;&#30446;

accountgl-acct_type = 'S'. " &#24080;&#25143;&#31867;&#22411;

accountgl-itemno_acc = index. " &#34892;&#39033;&#30446;&#32534;&#21495;

accountgl-profit_ctr = '0000310100'. " &#21033;&#28070;&#20013;&#24515;

accountgl-alloc_nmbr = '0000310100'. " &#20998;&#37197;

accountgl-funds_ctr = '0000310100'. " &#22522;&#37329;&#20013;&#24515;

accountgl-item_text = it_bseg-sgtxt." &#39033;&#30446;&#25991;&#26412;

append accountgl.

" fill currency item in each loop of it_bseg

clear currencyamount.

currencyamount-itemno_acc = index. " &#34892;&#39033;&#30446;&#32534;&#21495;

currencyamount-currency = 'CNY'. " &#36135;&#24065;

if flag = 'C'.

currencyamount-amt_doccur = it_bseg-wrbtr. " &#20973;&#35777;&#36135;&#24065;&#37329;&#39069;

else.

currencyamount-amt_doccur = it_bseg-wrbtr * ( -1 ).

endif.

currencyamount-disc_base = currencyamount-amt_doccur.

append currencyamount.

else.

" if not vendor items, generate vendor items

if flag = 'C' and it_bseg-bschl(1) = '8'. " &#36151;&#20511;

flag2 = -1.

endif.

if flag = 'C' and it_bseg-bschl(1) = '9'. " &#36151;&#36151;

flag2 = 1.

endif.

if flag = 'D' and it_bseg-bschl(1) = '8'. " &#20511;&#20511;

flag2 = -1.

endif.

if flag = 'D' and it_bseg-bschl(1) = '9'. " &#20511;&#36151;

flag2 = 1.

endif.

call function 'CONVERSION_EXIT_ALPHA_OUTPUT'

exporting

input = it_bseg-ebelp

importing

output = it_bseg-ebelp.

concatenate

wa_data-gjahr(4) ' + ' wa_data-belnr ' + ' it_bseg-ebeln ' + ' it_bseg-ebelp

into it_bseg-sgtxt.

clear accountpayable.

accountpayable-itemno_acc = index. " &#34892;&#39033;&#30446;&#32534;&#21495;

accountpayable-vendor_no = t_lifnr. " &#20379;&#24212;&#21830;

accountpayable-bline_date = wa_data-zfbdt. " &#22522;&#20934;&#26085;&#26399;

accountpayable-alloc_nmbr = '310100'. " &#20998;&#37197;

accountpayable-item_text = it_bseg-sgtxt. " &#39033;&#30446;&#25991;&#26412;

append accountpayable.

" fill currency item in each loop of it_bseg

clear currencyamount.

currencyamount-itemno_acc = index. " &#34892;&#39033;&#30446;&#32534;&#21495;

currencyamount-currency = 'CNY'. " &#36135;&#24065;

currencyamount-amt_doccur = it_bseg-wrbtr * flag2 .

currencyamount-disc_base = currencyamount-amt_doccur.

append currencyamount.

endif.

index = index + 1.

endloop.

endif.

call function 'BAPI_ACC_DOCUMENT_CHECK'

exporting

documentheader = documentheader

  • CUSTOMERCPD =

  • CONTRACTHEADER =

tables

accountgl = accountgl

  • ACCOUNTRECEIVABLE =

accountpayable = accountpayable

  • ACCOUNTTAX =

currencyamount = currencyamount

  • CRITERIA =

  • VALUEFIELD =

  • EXTENSION1 =

return = return

  • PAYMENTCARD =

  • CONTRACTITEM =

  • EXTENSION2 =

  • REALESTATE =

.

call function 'BAPI_ACC_DOCUMENT_REV_POST'

exporting

reversal =

bus_act =

tables

return =

.

loop at return.

if return-type = 'E' or return-type = 'A'.

bapiflag = 'E'.

endif.

write:/ return-message.

endloop.

refresh return.

if bapiflag <> 'E'.

call function 'BAPI_ACC_DOCUMENT_POST'

exporting

documentheader = documentheader

importing

obj_type = obj_type

obj_key = obj_key

obj_sys = obj_sys

tables

accountgl = accountgl

accountpayable = accountpayable

currencyamount = currencyamount

return = return.

loop at return.

if return-type = 'E' or return-type = 'A'.

bapiflag = 'E'.

endif.

write:/ return-message.

endloop.

refresh return.

endif.

if bapiflag <> 'E'.

call function 'BAPI_TRANSACTION_COMMIT'

  • EXPORTING

  • WAIT =

importing

return = return.

.

loop at return.

if return-type = 'E' or return-type = 'A'.

bapiflag = 'E'.

endif.

write:/ return-message.

endloop.

refresh return.

if bapiflag <> 'E'.

wa_data-belnr2 = obj_key(10) .

modify it_data from wa_data.

endif.

endif.

refresh: accountgl, accountpayable, currencyamount .

clear: documentheader, obj_key.

clear bapiflag.

endloop.

endform. "main_bapi