‎2021 Oct 18 5:13 AM
I have a requirement like , I need to post multiple documents at once .
Is that possible ?
If possible , then what should be item number be for each document , and how can I retrieve the object key for each document?
Have anyone come across this requirement ?
‎2021 Oct 18 5:39 AM
Hi Nivetha,
Yes, this is very much possible.
Please refer to the below code snippets:
Header structure:
ls_header-bus_act = 'RFBU'.
ls_header-username = sy-uname.
ls_header-comp_code = gfs_record-bukrs.
ls_header-doc_date = pn-endda.
ls_header-pstng_date = pn-endda.
ls_header-doc_type = gfs_record-blart.
ls_header-fis_period = pn-pabrp.
ls_header-fisc_year = pn-pabrj.
ls_header-header_txt = 'Bonus Entries'.
ls_header-ref_doc_no = gfs_record-xblnr.
Item Tables to be filled, you can loop the internal table and append all the entries in BAPI Account GL & currency amount Table, here item will be incremented like counter starting from 1,2,3....and so on.
LOOP AT git_record INTO gfs_record WHERE blart = 'BO'.
CLEAR: ls_accountgl, ls_currencyamount.
SHIFT gfs_record-newko LEFT DELETING LEADING '0'.
lv_itemno = lv_itemno + 1.
ls_accountgl-itemno_acc = lv_itemno.
ls_accountgl-gl_account = gfs_record-newko.
ls_accountgl-item_text = gfs_record-sgtxt.
ls_accountgl-comp_code = gfs_record-bukrs.
ls_accountgl-doc_type = gfs_record-blart.
ls_accountgl-pstng_date = pn-endda.
ls_accountgl-value_date = pn-endda.
ls_accountgl-fis_period = pn-pabrp.
ls_accountgl-fisc_year = pn-pabrj.
IF gfs_record-newbs EQ '40'.
ls_accountgl-de_cre_ind = 'S'.
ls_accountgl-costcenter = gfs_record-kostl.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_accountgl-costcenter
IMPORTING
output = ls_accountgl-costcenter.
ELSEIF gfs_record-newbs EQ '50'.
ls_accountgl-de_cre_ind = 'H'.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_accountgl-gl_account
IMPORTING
output = ls_accountgl-gl_account.
APPEND ls_accountgl TO lt_accountgl.
ls_currencyamount-itemno_acc = lv_itemno.
ls_currencyamount-curr_type = '00'.
IF gfs_record-newbs EQ '40'.
ls_currencyamount-amt_doccur = gfs_record-wrbtr / 10.
ELSEIF gfs_record-newbs EQ '50'.
ls_currencyamount-amt_doccur = ( gfs_record-wrbtr * -1 ) / 10.
ENDIF.
ls_currencyamount-currency = gfs_record-waers.
APPEND ls_currencyamount TO lt_currencyamount.
ENDLOOP.
"""" Post Bonus
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_header
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
currencyamount = lt_currencyamount
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
ls_msg-doc_type = gfs_record-blart. "'BO'.
ls_msg-type = 'S'.
CONCATENATE 'Document No.' lv_obj_key+0(10) 'posted successfully' INTO ls_msg-msg SEPARATED BY space.
APPEND ls_msg TO lit_msg.
CLEAR ls_msg..
""""""" Update Custom Tables """"""""""""""""""""""""""""""""""""""""""""
ls_prov_post-bukrs = gfs_record-bukrs. "'1000'.
ls_prov_post-pabrp = pn-pabrp.
ls_prov_post-pabrj = pn-pabrj.
ls_prov_post-blart = gfs_record-blart. "'BO'.
ls_prov_post-zbelnr = lv_obj_key+0(10).
ls_prov_post-gjahr = pn-pabrj.
MODIFY zhr_fi_prov_post FROM ls_prov_post.
"""""" Update IT tables
lt_emp_post = gt_emp_prov.
DELETE lt_emp_post WHERE blart NE gfs_record-blart. "'BO'.
LOOP AT lt_emp_post ASSIGNING <lfs_emp_post>.
<lfs_emp_post>-gjahr = pn-pabrj.
<lfs_emp_post>-zbelnr = lv_obj_key+0(10).
ENDLOOP.
MODIFY zhr_emp_prov_pst FROM TABLE lt_emp_post.
ELSE.
ls_msg-doc_type = gfs_record-blart. "'BO'.
ls_msg-type = 'E'.
ls_msg-msg = 'Unable create posting document' && ls_prov_post-zbelnr.
APPEND ls_msg TO lit_msg.
CLEAR ls_msg.
ENDIF.
ENDIF.
‎2021 Oct 18 5:39 AM
Hi Nivetha,
Yes, this is very much possible.
Please refer to the below code snippets:
Header structure:
ls_header-bus_act = 'RFBU'.
ls_header-username = sy-uname.
ls_header-comp_code = gfs_record-bukrs.
ls_header-doc_date = pn-endda.
ls_header-pstng_date = pn-endda.
ls_header-doc_type = gfs_record-blart.
ls_header-fis_period = pn-pabrp.
ls_header-fisc_year = pn-pabrj.
ls_header-header_txt = 'Bonus Entries'.
ls_header-ref_doc_no = gfs_record-xblnr.
Item Tables to be filled, you can loop the internal table and append all the entries in BAPI Account GL & currency amount Table, here item will be incremented like counter starting from 1,2,3....and so on.
LOOP AT git_record INTO gfs_record WHERE blart = 'BO'.
CLEAR: ls_accountgl, ls_currencyamount.
SHIFT gfs_record-newko LEFT DELETING LEADING '0'.
lv_itemno = lv_itemno + 1.
ls_accountgl-itemno_acc = lv_itemno.
ls_accountgl-gl_account = gfs_record-newko.
ls_accountgl-item_text = gfs_record-sgtxt.
ls_accountgl-comp_code = gfs_record-bukrs.
ls_accountgl-doc_type = gfs_record-blart.
ls_accountgl-pstng_date = pn-endda.
ls_accountgl-value_date = pn-endda.
ls_accountgl-fis_period = pn-pabrp.
ls_accountgl-fisc_year = pn-pabrj.
IF gfs_record-newbs EQ '40'.
ls_accountgl-de_cre_ind = 'S'.
ls_accountgl-costcenter = gfs_record-kostl.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_accountgl-costcenter
IMPORTING
output = ls_accountgl-costcenter.
ELSEIF gfs_record-newbs EQ '50'.
ls_accountgl-de_cre_ind = 'H'.
ENDIF.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = ls_accountgl-gl_account
IMPORTING
output = ls_accountgl-gl_account.
APPEND ls_accountgl TO lt_accountgl.
ls_currencyamount-itemno_acc = lv_itemno.
ls_currencyamount-curr_type = '00'.
IF gfs_record-newbs EQ '40'.
ls_currencyamount-amt_doccur = gfs_record-wrbtr / 10.
ELSEIF gfs_record-newbs EQ '50'.
ls_currencyamount-amt_doccur = ( gfs_record-wrbtr * -1 ) / 10.
ENDIF.
ls_currencyamount-currency = gfs_record-waers.
APPEND ls_currencyamount TO lt_currencyamount.
ENDLOOP.
"""" Post Bonus
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = ls_header
IMPORTING
obj_type = lv_obj_type
obj_key = lv_obj_key
obj_sys = lv_obj_sys
TABLES
accountgl = lt_accountgl
currencyamount = lt_currencyamount
return = lt_return.
READ TABLE lt_return INTO ls_return WITH KEY type = 'E'.
IF sy-subrc NE 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT' .
ls_msg-doc_type = gfs_record-blart. "'BO'.
ls_msg-type = 'S'.
CONCATENATE 'Document No.' lv_obj_key+0(10) 'posted successfully' INTO ls_msg-msg SEPARATED BY space.
APPEND ls_msg TO lit_msg.
CLEAR ls_msg..
""""""" Update Custom Tables """"""""""""""""""""""""""""""""""""""""""""
ls_prov_post-bukrs = gfs_record-bukrs. "'1000'.
ls_prov_post-pabrp = pn-pabrp.
ls_prov_post-pabrj = pn-pabrj.
ls_prov_post-blart = gfs_record-blart. "'BO'.
ls_prov_post-zbelnr = lv_obj_key+0(10).
ls_prov_post-gjahr = pn-pabrj.
MODIFY zhr_fi_prov_post FROM ls_prov_post.
"""""" Update IT tables
lt_emp_post = gt_emp_prov.
DELETE lt_emp_post WHERE blart NE gfs_record-blart. "'BO'.
LOOP AT lt_emp_post ASSIGNING <lfs_emp_post>.
<lfs_emp_post>-gjahr = pn-pabrj.
<lfs_emp_post>-zbelnr = lv_obj_key+0(10).
ENDLOOP.
MODIFY zhr_emp_prov_pst FROM TABLE lt_emp_post.
ELSE.
ls_msg-doc_type = gfs_record-blart. "'BO'.
ls_msg-type = 'E'.
ls_msg-msg = 'Unable create posting document' && ls_prov_post-zbelnr.
APPEND ls_msg TO lit_msg.
CLEAR ls_msg.
ENDIF.
ENDIF.
‎2021 Oct 18 5:57 AM
Hello Vipin,
Thank you for the answer
for single document number , my inputs are
1 record in ACCOUNTGL with item number 1
1 record in ACCOUNTPAYABLE with item number 2
2 records in CURRENCYAMOUNT with item number 1 and 2
If this is the case , then how should I provide item number for the next document ?
And , will the object key be same for all the posted records ?
‎2021 Oct 18 6:38 AM
Hi Nivetha,
Every time you call BAPI_ACC_DOUCMENT_POST a document will be posted, in your case the item number for the next docuemnt should be again 1,2,... and so on. Whwneveer you have posted one document you need to clear the item counter back to 0.
‎2021 Oct 18 8:22 AM