2023 Mar 17 5:24 AM
Hi All,
I am using 2 BAPIs one is 'BAPI_ACC_DOCUMENT_POST' and other is ‘FI_DOCUMENT_CHANGE’ .I am calling one after the other immediately in the Loop .For each BAPI , am using ‘BAPI_TRANSACTION_COMMIT’ . 'BAPI_ACC_DOCUMENT_POST' is working fine and ‘FI_DOCUMENT_CHANGE’ is not working fine as its not updating XREF3 in the FB03 T-Code level and Table(BSEG) level as well . For each BAPI, I am using separate BAPI_TRANSACTION_COMMIT
Please find the attached code and let me know if any issue in code please. Kindly help me with your suggestions as soon as possible as it needed on priority. Thanks in advance .
This program run as background job .
Best Regards,
Likhitha D
2023 Mar 17 7:52 AM
You should first analyze at your side and tell us more, because you didn't even say if you observed by debug that FI_DOCUMENT_CHANGE was actually called, if there was an exception or not after calling FI_DOCUMENT_CHANGE, etc.
Concerning BSEG-XREF3, there are existing answers in the forum, so please tell us what you tried.
PS: first of all, fix your code to log the errors. Also rollback if there's an error.
2023 Mar 17 6:10 AM
Hi Team,
Please suggest as this need to be fixed in Priority .Thanks in advance .
2023 Mar 17 6:12 AM
LOOP AT lt_data ASSIGNING FIELD-SYMBOL(<lfs_data>).
* Header Data for the Document
le_doc_header-bus_act = 'RFBU'.
le_doc_header-username = sy-uname.
le_doc_header-header_txt = <lfs_data>-rxblnr.
le_doc_header-comp_code = <lfs_data>-bukrs.
le_doc_header-doc_date = <lfs_data>-laufd."bldat.
le_doc_header-pstng_date = sy-datum + 1.
le_doc_header-doc_type = lv_doctype.
le_doc_header-ref_doc_no = <lfs_data>-belnr.
*--------------------------------------------------------------------------------------------------------notepad
* Fill Line 1 of Document Item
le_doc_item-itemno_acc = '1'.
le_doc_item-gl_account = lv_gl_1.
le_doc_item-pstng_date = sy-datum + 1 .
le_doc_item-item_text = <lfs_data>-rxblnr.
le_doc_item-comp_code = <lfs_data>-bukrs.
le_doc_item-alloc_nmbr = <lfs_data>-zuonr.
le_doc_item-ref_key_1 = <lfs_data>-vblnr.
le_doc_item-ref_key_2 = <lfs_data>-belnr.
le_doc_item-value_date = sy-datum + 1.
IF le_doc_item-gl_account EQ lv_gl_1.
le_doc_item-trade_id = lv_cc.
ENDIF.
APPEND le_doc_item TO lt_doc_item.
CLEAR le_doc_item.
* Fill Line 2 of Document Item
le_doc_item-itemno_acc = '2'.
le_doc_item-gl_account = lv_gl_2.
le_doc_item-pstng_date = sy-datum + 1.
le_doc_item-item_text = <lfs_data>-rxblnr.
le_doc_item-comp_code = <lfs_data>-bukrs.
le_doc_item-alloc_nmbr = <lfs_data>-zuonr.
le_doc_item-ref_key_1 = <lfs_data>-vblnr.
le_doc_item-ref_key_2 = <lfs_data>-belnr.
le_doc_item-profit_ctr = <lfs_data>-prctr.
le_doc_item-value_date = sy-datum + 1.
IF le_doc_item-gl_account EQ lv_gl_1.
le_doc_item-trade_id = lv_cc.
ENDIF.
APPEND le_doc_item TO lt_doc_item.
CLEAR le_doc_item.
** Fill Line 3 of Document Item
le_doc_item-itemno_acc = '3'.
le_doc_item-gl_account = lv_gl_3.
le_doc_item-pstng_date = sy-datum + 1.
le_doc_item-item_text = <lfs_data>-rxblnr.
le_doc_item-comp_code = lv_cc.
le_doc_item-alloc_nmbr = <lfs_data>-zuonr.
le_doc_item-ref_key_1 = <lfs_data>-vblnr.
le_doc_item-ref_key_2 = <lfs_data>-belnr.
le_doc_item-value_date = sy-datum + 1.
IF le_doc_item-gl_account EQ lv_gl_1.
le_doc_item-trade_id = <lfs_data>-zbukr.
ENDIF.
APPEND le_doc_item TO lt_doc_item.
CLEAR le_doc_item.
** Fill Line 4 of Document Item
le_doc_item-itemno_acc = '4'.
le_doc_item-gl_account = lv_gl_4.
le_doc_item-pstng_date = sy-datum + 1.
le_doc_item-item_text = <lfs_data>-rxblnr.
le_doc_item-comp_code = lv_cc.
le_doc_item-alloc_nmbr = <lfs_data>-zuonr.
le_doc_item-ref_key_1 = <lfs_data>-vblnr.
le_doc_item-ref_key_2 = <lfs_data>-belnr.
le_doc_item-value_date = sy-datum + 1.
IF le_doc_item-gl_account EQ lv_gl_1.
le_doc_item-trade_id = <lfs_data>-zbukr.
ENDIF.
APPEND le_doc_item TO lt_doc_item.
CLEAR le_doc_item.
*--------------------------------------------------------------------------------------------------------
* Fill Line 1 of Document Value.
le_doc_values-itemno_acc = '1'.
IF <lfs_data>-shkzg = 'S'.
le_doc_values-amt_doccur = <lfs_data>-dmbtr.
ELSE.
le_doc_values-amt_doccur = <lfs_data>-dmbtr * -1.
ENDIF.
le_doc_values-currency = <lfs_data>-waers.
APPEND le_doc_values TO lt_doc_values.
CLEAR le_doc_values.
* Fill Line 2 of Document Value
le_doc_values-itemno_acc = '2'.
IF <lfs_data>-shkzg = 'S'.
le_doc_values-amt_doccur = <lfs_data>-dmbtr * -1.
ELSE.
le_doc_values-amt_doccur = <lfs_data>-dmbtr.
ENDIF.
le_doc_values-currency = <lfs_data>-waers.
APPEND le_doc_values TO lt_doc_values.
CLEAR le_doc_values.
* Fill Line 3 of Document Value.
le_doc_values-itemno_acc = '3'.
IF <lfs_data>-shkzg = 'S'.
le_doc_values-amt_doccur = <lfs_data>-dmbtr.
ELSE.
le_doc_values-amt_doccur = <lfs_data>-dmbtr * -1.
ENDIF.
le_doc_values-currency = <lfs_data>-waers.
APPEND le_doc_values TO lt_doc_values.
CLEAR le_doc_values.
* Fill Line 4 of Document Value
le_doc_values-itemno_acc = '4'.
IF <lfs_data>-shkzg = 'S'.
le_doc_values-amt_doccur = <lfs_data>-dmbtr * -1.
ELSE.
le_doc_values-amt_doccur = <lfs_data>-dmbtr.
ENDIF.
le_doc_values-currency = <lfs_data>-waers.
APPEND le_doc_values TO lt_doc_values.
CLEAR le_doc_values.
*--------------------------------------------------------------------------------------------------------
*BAPI Call BAPI Name 'BAPI_ACC_DOCUMENT_POST' to post the GL Account Postings automatically.
*This call will post the gl accounts via Transaction FB01.
CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
EXPORTING
documentheader = le_doc_header
IMPORTING
obj_type = le_doc_header-obj_type
obj_key = le_doc_header-obj_key
obj_sys = le_doc_header-obj_sys
TABLES
accountgl = lt_doc_item[]
currencyamount = lt_doc_values[]
return = lt_return[] "#EC CI_USAGE_OK[2628704]
"#EC CI_USAGE_OK[2438131] "#EC CI_USAGE_OK[2628704]
"#EC CI_SEL_NESTED or "#EC CI_SROFC_NESTED
"#EC CI_USAGE_OK[2438131]
.
READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = 'E' .
IF sy-subrc NE 0.
* CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = abap_true
* IMPORTING
* RETURN =
.
le_logs-status = TEXT-001.
*Selecting PYORD from PYORDH Table to fill the ref in customer document.
ASSIGN lt_pyord[ laufd = <lfs_data>-laufd laufi = <lfs_data>-laufi ] TO FIELD-SYMBOL(<lfs_pyord>).
IF sy-subrc = 0 AND <lfs_pyord> IS ASSIGNED.
*If BAPI succesfully completes GL Posting then Customer XREF3 field will be updated with Payment Order Payment Run Date and Payment Run ID from PYORDH Table.
lv_date = |{ <lfs_data>-laufd+6(2) }{ <lfs_data>-laufd+4(2) }{ <lfs_data>-laufd+2(2) }|.
lv_pmt_ord = condense( |{ <lfs_pyord>-pyord ALPHA = OUT }| ).
lv_concat = condense( |{ lv_pmt_ord }-{ lv_date }-{ <lfs_data>-laufi }| ).
*Modifying the BSEG Table to fill the XREF3 Field.
* Updating SOR reference value to Reference 3 filed for matching documents.
ASSIGN lt_bseg_data[ belnr = <lfs_data>-belnr bukrs = <lfs_data>-bukrs gjahr = <lfs_data>-gjahr ] TO FIELD-SYMBOL(<lfs_bseg_data>).
IF <lfs_bseg_data> IS ASSIGNED.
lv_buzei1 = <lfs_bseg_data>-buzei.
ENDIF.
lv_bukrs1 = <lfs_data>-bukrs .
lv_belnr1 = <lfs_data>-belnr .
lv_gjahr1 = <lfs_data>-gjahr.
IF lv_concat IS NOT INITIAL .
lt_accchg1 = VALUE #( ( fdname = lc_xref3 oldval = lc_oldval1 newval = lv_concat ) ).
ENDIF .
IF lt_accchg1 IS NOT INITIAL .
* Check if there is lock on document before proceeding
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
gclient = sy-mandt
gname = lc_gname1 " BKPF
garg = lv_garg1
TABLES
enq = lt_enq1
EXCEPTIONS
communication_failure = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc EQ 0 AND lt_enq1 IS INITIAL.
CALL FUNCTION 'FI_DOCUMENT_CHANGE' ##COMPATIBLE
EXPORTING
i_buzei = lv_buzei1
i_bukrs = lv_bukrs1
i_belnr = lv_belnr1
i_gjahr = lv_gjahr1
TABLES
t_accchg = lt_accchg1
EXCEPTIONS
no_reference = 1
no_document = 2
many_documents = 3
wrong_input = 4
overwrite_creditcard = 5
OTHERS = 6.
IF sy-subrc = 0.
* Commit the changes
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
ENDIF.
ENDIF.
ENDIF.
CLEAR: <lfs_bseg_data>, lv_date, lv_concat, lv_pmt_ord,lt_bseg.
ENDIF.
ELSE.
le_logs-status = TEXT-002.
ENDIF.
le_logs-belnr = <lfs_data>-belnr.
le_logs-obj_type = le_doc_header-obj_key.
APPEND le_logs TO lt_logs.
CLEAR : lt_doc_item,lt_doc_values,lt_return,le_doc_header, le_logs. "Clearing internal tables and structure variables for next loop.
ENDLOOP.
2023 Mar 17 7:52 AM
You should first analyze at your side and tell us more, because you didn't even say if you observed by debug that FI_DOCUMENT_CHANGE was actually called, if there was an exception or not after calling FI_DOCUMENT_CHANGE, etc.
Concerning BSEG-XREF3, there are existing answers in the forum, so please tell us what you tried.
PS: first of all, fix your code to log the errors. Also rollback if there's an error.
2023 Mar 17 10:08 AM
2023 Mar 17 10:20 AM
Perhaps more details could help.
- does the FM for 'FI_DOCUMENT_CHANGE' not returning any sy-subrc?
- what about other fields, have you try updating other field and check if it succeeded?
- try adding extra 1 or 2 second waiting time after 1st BAPI finished with the commit work, sometimes the document is still being processed.
2023 Mar 17 1:24 PM