‎2008 Dec 09 9:40 AM
Hi all
I'm using BAPI_ACC_DOCUMENT_POST for FB01, I have some proble because I don't understand where I have to put the item data (the record which will be inserted in bseg)
which structur I have to use?
documentheader in only for the header data, is it right??
thanks in advance
‎2008 Dec 09 9:44 AM
Hi Ricardo,
Please check this program,
report ZTESTBAPI .
data:
obj_type like bapiache02-obj_type,
obj_key like bapiache02-obj_key,
obj_sys like bapiache02-obj_sys,
documentheader like bapiache08,
accountgl like bapiacgl08
occurs 0 with header line,
currencyamount like bapiaccr08
occurs 0 with header line,
return like bapiret2
occurs 0 with header line,
extension1 like bapiextc
occurs 0 with header line,
t_edidd like edidd occurs 0 with header line,
bapi_retn_info like bapiret2 occurs 0 with header line.
data: error_flag.
documentheader-username = sy-uname.
documentheader-header_txt = 'Test using BAPI'.
documentheader-comp_code = '1000'.
documentheader-doc_date = sy-datum.
documentheader-pstng_date = sy-datum.
documentheader-doc_type = 'SA'.
accountgl-itemno_acc = '1'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.
accountgl-itemno_acc = '2'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.
currencyamount-itemno_acc = '1'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '100.00'.
append currencyamount.
currencyamount-itemno_acc = '2'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '-100.00'.
append currencyamount.
call BAPI-function in this system *
call function 'BAPI_ACC_GL_POSTING_POST'
exporting
documentheader = documentheader
importing
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
tables
accountgl = accountgl
currencyamount = currencyamount
return = return
extension1 = extension1
exceptions
others = 1.
if sy-subrc <> 0.
message e999(re) with 'Error'.
else.
loop at return.
if not return is initial.
clear bapi_retn_info.
move-corresponding return to bapi_retn_info.
if return-type = 'A' or return-type = 'E'.
error_flag = 'X'.
endif.
append bapi_retn_info.
endif.
endloop.
if error_flag = 'X'.
message e999(re) with 'Error'.
rollback work.
else.
commit work.
endif.
endif.
‎2008 Dec 09 9:42 AM
You need tables ACCOUNTGL and CURRENCYAMOUNT to pass the line items. Also check the online documentation of that function module and its parameters.
Thomas
‎2008 Dec 09 9:44 AM
Hi Ricardo,
Please check this program,
report ZTESTBAPI .
data:
obj_type like bapiache02-obj_type,
obj_key like bapiache02-obj_key,
obj_sys like bapiache02-obj_sys,
documentheader like bapiache08,
accountgl like bapiacgl08
occurs 0 with header line,
currencyamount like bapiaccr08
occurs 0 with header line,
return like bapiret2
occurs 0 with header line,
extension1 like bapiextc
occurs 0 with header line,
t_edidd like edidd occurs 0 with header line,
bapi_retn_info like bapiret2 occurs 0 with header line.
data: error_flag.
documentheader-username = sy-uname.
documentheader-header_txt = 'Test using BAPI'.
documentheader-comp_code = '1000'.
documentheader-doc_date = sy-datum.
documentheader-pstng_date = sy-datum.
documentheader-doc_type = 'SA'.
accountgl-itemno_acc = '1'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.
accountgl-itemno_acc = '2'.
accountgl-gl_account = '0000160100'.
accountgl-comp_code = '1000'.
accountgl-pstng_date = sy-datum.
accountgl-doc_type = 'SA'.
accountgl-profit_ctr = '0000010000'.
append accountgl.
currencyamount-itemno_acc = '1'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '100.00'.
append currencyamount.
currencyamount-itemno_acc = '2'.
currencyamount-currency = 'GBP'.
currencyamount-amt_doccur = '-100.00'.
append currencyamount.
call BAPI-function in this system *
call function 'BAPI_ACC_GL_POSTING_POST'
exporting
documentheader = documentheader
importing
obj_type = obj_type
obj_key = obj_key
obj_sys = obj_sys
tables
accountgl = accountgl
currencyamount = currencyamount
return = return
extension1 = extension1
exceptions
others = 1.
if sy-subrc <> 0.
message e999(re) with 'Error'.
else.
loop at return.
if not return is initial.
clear bapi_retn_info.
move-corresponding return to bapi_retn_info.
if return-type = 'A' or return-type = 'E'.
error_flag = 'X'.
endif.
append bapi_retn_info.
endif.
endloop.
if error_flag = 'X'.
message e999(re) with 'Error'.
rollback work.
else.
commit work.
endif.
endif.
‎2008 Dec 09 10:01 AM
Thanks, I'll try this solution
After the call to this bapi, how can I know the BELNR value of the data inserted in BKPF??
‎2008 Dec 09 2:30 PM
‎2008 Dec 11 12:45 PM
I can't do test because i have this error: "balance in transaction currency" (I don't know if is the correct error message, because it is the translation from italian error message "saldo in divisa transazione") after execution of BAPI_ACC_DOCUMENT_POST
Someone have any suggestion?
Thanks in advance
‎2008 Dec 11 1:14 PM
the translation is right. it means that the sum of debit and sum of the credit amounts do not match. check the entries in table CURRENCYAMOUNT
‎2008 Dec 11 1:35 PM
HI,
Are u giving negative sign for credit amounts .
for credit entries currencyamount-amt_doccur = -xxxxx
and for debit, currencyamount-amt_doccur= xxxxx
regards
Arjun
‎2008 Dec 11 2:06 PM
if someone has the same problem:
when the registration is succesful the BELNR value of the document created is stored in the first 10 character of field RETURN-MESSAGE_V2
‎2008 Dec 11 2:10 PM
Hi
The number (company code and fyscal year) is stored in exporting parameter OBJ_KEY
Max