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

MIRO Posting Issue

former_member223133
Active Participant
0 Likes
2,415

Hi,

We have one requirement, where we have to post 2 more entries for MIRO as soon as the invoice document created successfully.

We searched many threads in SCN to find the user exit or BADI after COMMIT (invoice being created successfully), but couldn't able to find.

Later we found one include LMR1MF2Y after the commit work and we implemented an implicit enhancement to post the 2 new entries w.r.t Invoice created. Here we are facing an issue while posting the entries and below is the code and error.

LOOP AT LT_BSEG INTO LS_BSEG.

     IF LS_BSEG-shkzg = 'H'.
        CONCATENATE LS_BSEG-BELNR LS_BSEG-gjahr INTO documentheader-header_txt.
        documentheader-username = sy-uname.
        documentheader-obj_type = LS_BKPF-TCODE.
        documentheader-comp_code = LS_BSEG-bukrs.
        documentheader-doc_date = ls_bkpf-bldat.
        documentheader-pstng_date = ls_bkpf-budat.
        documentheader-doc_type = 'SA'.
        documentheader-fisc_year = LS_BSEG-gjahr.
*       documentheader-ref_doc_no = LS_BSEG-xblnr.
****line item 1
       accountgl-itemno_acc = '1'.
       accountgl-gl_account = LS_BSEG-HKONT.
       accountgl-comp_code = LS_BSEG-bukrs.
       accountgl-pstng_date = ls_bkpf-budat.
       accountgl-doc_type = 'SA'.
       accountgl-stat_con = 'H'.
       accountgl-profit_ctr = LS_BSEG-prctr.
       accountgl-alloc_nmbr = LS_BSEG-zuonr.
       accountgl-VENDOR_NO  = LS_BSEG-lifnr.
       accountgl-TAX_CODE   = LS_BSEG-MWSKZ.
       APPEND accountgl.

       currencyamount-itemno_acc = '1'.
       currencyamount-currency = LS_BSEG-PSWSL.
       currencyamount-amt_doccur = LS_BSEG-WRBTR.
       APPEND currencyamount.


      ELSE.
****line item 2
       accountgl-itemno_acc = '2'.
       accountgl-gl_account = LS_BSEG-HKONT.
       accountgl-comp_code = LS_BSEG-bukrs.
       accountgl-pstng_date = ls_bkpf-budat.
       accountgl-doc_type = 'SA'.
       accountgl-stat_con = 'S'.
       accountgl-profit_ctr = LS_BSEG-prctr.
       accountgl-costcenter = LS_BSEG-kostl.
       accountgl-alloc_nmbr = LS_BSEG-zuonr.
       accountgl-VENDOR_NO  = LS_BSEG-lifnr.
       accountgl-TAX_CODE   = LS_BSEG-MWSKZ.
       APPEND accountgl.

       currencyamount-itemno_acc = '2'.
       currencyamount-currency = LS_BSEG-PSWSL.
       currencyamount-amt_doccur = LS_BSEG-WRBTR.
       APPEND currencyamount.
     ENDIF.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
       EXPORTING
         documentheader = documentheader
       TABLES
         accountgl      = accountgl
         currencyamount = currencyamount
         return         = return
         extension1     = extension1
       EXCEPTIONS
         OTHERS         = 1.
     IF sy-subrc <> 0.
       MESSAGE e999(re) WITH 'Problem occured'.
     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 'Problem occured'.
         ROLLBACK WORK.
       ELSE.
         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
             wait   = gs_wait
           IMPORTING
             return = wa_comm_return.
         WRITE 😕 return-message+0(30),return-message+36(10).
       ENDIF.

     ENDIF.
     REFRESH: currencyamount,accountgl,return,extension1.
     CLEAR: currencyamount,accountgl,documentheader,return,extension1.

ENDLOOP.


  • Please let us know if we have any user exits or BADIs after commit for MIRO.
  • Please let us know if we missed any other parameters for above BAPI.

Please help us to resolve this issue.

Thanks

Gangadhar

9 REPLIES 9
Read only

nabheetscn
SAP Champion
SAP Champion
0 Likes
2,167

Hi Gangadhar

You can use TRFC call for such cases. In badi search on SCN (many are their). The TRFC calls will be called fater the document gets posted and all locks released. Simply use call function in background task

Nabheet

Read only

0 Likes
2,167

Sorry for typo using mobile. Call function in background task will make sure all locks are released

Nabheet

Read only

0 Likes
2,167

Hi Nabheet,

Thanks for your quick response. Could you please elaborate and share the sample code.

Thanks

Gangadhar

Read only

0 Likes
2,167

What I mean to say is create an RFC enabled function module and inside it call the BAPI to post and commit. In order to amke sure it is called after document has been posted call this Z FM with addition of background task in any BADI method where document number gets generated. Search on SCN for call function in background task. This FM will get trigger when standard processing will do commit work

Nabheet

Read only

0 Likes
2,167

Hi Nabheet,

I tried to post the document using FM "BAPI_ACC_DOCUMENT_POST". But still I'm getting the following error.

Please find the below code.

LOOP AT LT_BSEG INTO LS_BSEG.

     IF LS_BSEG-shkzg = 'H'.
        CONCATENATE LS_BSEG-BELNR LS_BSEG-gjahr INTO documentheader-header_txt.
        documentheader-username = sy-uname.
        documentheader-obj_type = LS_BKPF-TCODE.
        documentheader-comp_code = LS_BSEG-bukrs.
        documentheader-doc_date = ls_bkpf-bldat.
        documentheader-pstng_date = ls_bkpf-budat.
        documentheader-doc_type = 'SA'.
        documentheader-fisc_year = LS_BSEG-gjahr.
*       documentheader-ref_doc_no = LS_BSEG-xblnr.
****line item 1
       accountgl-itemno_acc = '1'.
       accountgl-gl_account = LS_BSEG-HKONT.
       accountgl-comp_code = LS_BSEG-bukrs.
       accountgl-pstng_date = ls_bkpf-budat.
       accountgl-doc_type = 'SA'.
       accountgl-stat_con = 'H'.
       accountgl-profit_ctr = LS_BSEG-prctr.
       accountgl-alloc_nmbr = LS_BSEG-zuonr.
       accountgl-VENDOR_NO  = LS_BSEG-lifnr.
       accountgl-TAX_CODE   = LS_BSEG-MWSKZ.
       APPEND accountgl.

       currencyamount-itemno_acc = '1'.
       currencyamount-currency = LS_BSEG-PSWSL.
       currencyamount-amt_doccur = LS_BSEG-WRBTR.
       APPEND currencyamount.


      ELSE.
****line item 2
       accountgl-itemno_acc = '2'.
       accountgl-gl_account = LS_BSEG-HKONT.
       accountgl-comp_code = LS_BSEG-bukrs.
       accountgl-pstng_date = ls_bkpf-budat.
       accountgl-doc_type = 'SA'.
       accountgl-stat_con = 'S'.
       accountgl-profit_ctr = LS_BSEG-prctr.
       accountgl-costcenter = LS_BSEG-kostl.
       accountgl-alloc_nmbr = LS_BSEG-zuonr.
       accountgl-VENDOR_NO  = LS_BSEG-lifnr.
       accountgl-TAX_CODE   = LS_BSEG-MWSKZ.
       APPEND accountgl.

       currencyamount-itemno_acc = '2'.
       currencyamount-currency = LS_BSEG-PSWSL.
       currencyamount-amt_doccur = LS_BSEG-WRBTR.
       APPEND currencyamount.
     ENDIF.

    CALL FUNCTION 'BAPI_ACC_DOCUMENT_POST'
       EXPORTING
         documentheader = documentheader
       TABLES
         accountgl      = accountgl
         currencyamount = currencyamount
         return         = return
         extension1     = extension1
       EXCEPTIONS
         OTHERS         = 1.
     IF sy-subrc <> 0.
       MESSAGE e999(re) WITH 'Problem occured'.
     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 'Problem occured'.
         ROLLBACK WORK.
       ELSE.
         CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
           EXPORTING
             wait   = gs_wait
           IMPORTING
             return = wa_comm_return.
         WRITE 😕 return-message+0(30),return-message+36(10).
       ENDIF.

     ENDIF.
     REFRESH: currencyamount,accountgl,return,extension1.
     CLEAR: currencyamount,accountgl,documentheader,return,extension1.

ENDLOOP.

Read only

0 Likes
2,167

Hi Gangadhar

If you look at your code you are calling BAPI in a loop. Only thing to be take care in calling this BAPI is DEBIT/CREDIT entry should sum up to zero or should be equal. In your case during first loop iteration one entry will get appended and BAPI will be called which is wrong as balance is not zero. You should call the BAPI when credit/debit are equal. Either bring your endloop of LOOP AT LT_BSEG INTO LS_BSEG. before BAPI call or make sure  you have credit+debit equal

Nabheet


Read only

0 Likes
2,167

Hi Nabheet,

Thanks for reply. Though I'm directly executing the BAPI through SE37 with the same data, we are getting the same error "FI/CO interface: Inconsistent FI/CO document header data for updating"

It seems an issue with the header data. Could you pls help us.

Thanks

Gangadhar

Read only

0 Likes
2,167

In return table what values are present in MESSAGE_V1/V2/V3/V4 fields.. It will contain the fieldname

Nabheet

Read only

0 Likes
2,167

Hi Nabheet,

Below are the return table entries.

E RW               609 Error in document: BKPFF $ ESNCLNT150
E RW               015 FI/CO interface: Inconsistent FI/CO document header data for updating

Thanks

Gangadhar