Application Development 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: 

BADI for MIRO

themax
Explorer
0 Kudos


Hello everybody!

I  apologize for my English in advance, but I will try what I want. I need that the invoce will be done (Mir7 or miro) in the order would be put tiked final invoice like on a picture, but I need that it would be tiked automatically.

It is necessary for  commercial closing PM Orders, so a have tried use BADI  INVOICE_UPDATE. I have created implementation.  There are an interface IF_EX_INVOICE_UPDATE and method CHANGE_AT_SAVE. In this method  I was trying all time write this kod 


method if_ex_invoice_update~change_at_save.

data: wa_reseg_new like line of ti_rseg_new.

field-symbols: <fs_ydrseg> type MRM_TAB_MRMRSEG  .

  ASSIGN ti_rseg_new TO <fs_ydrseg>.

*

  loop at <fs_ydrseg> into wa_reseg_new.

    BREAK-POINT.

*  "  ASSIGN wa_reseg_new TO <fs_ydrseg>.

    wa_reseg_new-erekz = 'X'.

    MODIFY <fs_ydrseg> FROM wa_reseg_new .

  endloop.

Then I have activated, but during creating invoice the programm is falls down in dump and there written that all parameters are defended and I can not change any. Did somebody meet this problem? May be somebody did this?

4 REPLIES 4

raymond_giuseppi
Active Contributor
0 Kudos

Always check type of parameter, you can  only change changing/exporting/returning parameters not importing, also read the documentation of the method in the interface.

This method seems executed too late (so with protected parameters, so supposed to trigger other tasks and not to change current data) so look for an earlier method during transaction.

Hint: there is a reference note for BAdI in MM invoicing 1156325 - BAdIs in the Logistics Invoice Verification environment, you get a list of available BAdi and what they do and do not.

Regards,

Raymond

0 Kudos

You are absolutely right and I should not to try use importing parameters, but I could do something.


data: begin of wa_tab,
          ebelp type
ekpo-ebelp,
          netpr type ekpo-netpr,
          MENGE type
ekpo-MENGE,
          DMBTR type ekbe-DMBTR,
        end of wa_tab,
   
    begin of wa_tab1,
          ebelp type ekbe-ebelp,
          DMBTR
type ekbe-DMBTR,
          SHKZG type ekbe-SHKZG,
        end of
wa_tab1,
        begin of wa_tab3,
          ebelp type ekbe-ebelp,
   
      DMBTR type ekbe-DMBTR,
        end of wa_tab3,
        begin of
wa_tab2,
          belnr type rseg-belnr,
          ebeln type
rseg-ebeln,
          ebelp type rseg-ebelp,
          wrbtr type
rseg-wrbtr,
          summa type rseg-wrbtr,
        end of wa_tab2.
  data: tab LIKE TABLE OF wa_tab,
        tab1 LIKE TABLE OF wa_tab1,
        tab2 LIKE TABLE OF wa_tab2,
        tab3 LIKE TABLE OF wa_tab3.
 
type-pools mmcr.
  data: ydrseg type table of mmcr_drseg.
  field-symbols:
<fs> like ydrseg.
  field-symbols: <s> type mmcr_drseg.
 
field-symbols: <s1> type mmcr_drseg.
  data: sss(40).

  sss =
'(SAPLMR1M)YDRSEG[]'.
  assign (sss) to <fs>.
  read table
<fs> index 1 assigning <s1>.
  BREAK-POINT.
  if sy-tcode
<> 'MR8M'.
    select ebelp netpr menge into CORRESPONDING FIELDS OF
TABLE tab from ekpo where ebeln = <s1>-ebeln.
    select * from ekbe  into CORRESPONDING FIELDS OF TABLE tab1 where ebeln = <s1>-ebeln and VGABE = 2.

    loop at <fs> assigning <s>.
      wa_tab3-ebelp =
<s>-ebelp.
      if <s>-SHKZG = 'H'.
        wa_tab3-dmbtr =
-1 * <s>-NETWR.
      else.
        wa_tab3-dmbtr =
<s>-NETWR.
      endif.
      COLLECT wa_tab3 into tab3 .
   
endloop.
    loop at <fs> assigning <s>.
      READ TABLE tab
into wa_tab WITH KEY ebelp = <s>-ebelp.
      wa_tab-DMBTR =
wa_tab-netpr * wa_tab-menge.
      if sy-subrc = 0.
        loop at tab1
into wa_tab1 where ebelp = <s>-ebelp.
          if wa_tab1-SHKZG =
'H'.
            wa_tab1-dmbtr = -1 * wa_tab1-dmbtr.
          endif.
 
        wa_tab-DMBTR = wa_tab-DMBTR - wa_tab1-dmbtr.
        endloop.
   
    READ TABLE tab3 into wa_tab3 WITH KEY ebelp = <s>-ebelp.
       
wa_tab-DMBTR = wa_tab-DMBTR - wa_tab3-dmbtr.
        if wa_tab-DMBTR <=
0.
          <s>-erekz = 'X'.
        endif.
      endif.
   
endloop.
  else.
    loop at <fs> assigning <s>.
     
<s>-erekz = ''.
    endloop.
  endif.8M

I have written a few kod and it working, but I  was not able to do with transaction MR8M. I wanted when the document would be reversed the tik would be put away. If somebody has thoughts about this I will be happy.

0 Kudos

When using such assign to protected data, you have to be very careful and test assiduously.


Case: you update the data but SAP has already prepared/called some update FM then execute the "post" BAdI where you change protected data and SAP continue with other update FM messing up the database.


Regards,

Raymond

0 Kudos

Ok Raymond! Thanks a lot for your advice. I will be carefully test this small implementation.