PO Save BADI

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Post Reply
new2sapfans
Posts: 71
Joined: Thu Jan 01, 2009 11:01 am

PO Save BADI

Post by new2sapfans » Mon Aug 24, 2009 2:47 pm

Hi,

I have a requirement that for a particalar document type, (say ZSTO), one field at the item level needs to be set.
The field is REPOS, and is a checkbox at the Invoice tab on the PO Item.

So, I instantiated BADI ME_PROCESS_PO_CUST.
In its method PROCESS_ITEM, I wrote the following code.

Code: Select all

  data: lv_po_head_ref  type ref to IF_PURCHASE_ORDER_MM,
        lv_MEPOHEADER   type MEPOHEADER,
        lv_MEPOITEM     type MEPOITEM.

  lv_po_head_ref = im_item->GET_HEADER( ).
  lv_mepoheader  = lv_po_head_ref->get_data( ).
  if lv_mepoheader-bsart eq 'ZSTO'.
    lv_mepoitem-repos = 'X'.
    im_item->set_data( EXPORTING im_data = lv_mepoitem ).
  endif.
After activating the badi, ME21N gives me the following.
Is it that the field REPOS is not supposed to be changed? Is there any other work around or user exit where this can be done?

Code: Select all

Data from Business Add-In ME_PROCESS_PO_CUST not adopted                  
                                                                          
    Message no. MEPO151                                                   
                                                                          
Diagnosis                                                                 
                                                                          
    An endless loop occurred during the processing of the Business Add-In 
    ME_PROCESS_PO_CUST. The system terminated the processing.             
                                                                          
                                                                          
                                                                          
Procedure                                                                 
                                                                          
    Contact your system administrator.                                    
                                                                          
Procedure for System Administration                                       
                                                                          
    Check whether standard fields are changed in the implementation of the
    Business Add-In ME_PROCESS_PO_CUST.                                   
    Changes to standard fields that are part of the Include structure      
    MEPOITEM_TECH and/or MEPOSCHEDULE_TECH are generally not allowed. In   
    addition, no field values that are not changeable through the field    
    settings in the Enjoy transactions can be changed in the BAdI. Correct 
    the implementation accordingly.                                        


Alexius
Posts: 66
Joined: Wed Dec 10, 2008 9:30 pm

Re: PO Save BADI

Post by Alexius » Thu Aug 27, 2009 7:40 pm

new2sapfans wrote:Hi,

I have a requirement that for a particalar document type, (say ZSTO), one field at the item level needs to be set.
The field is REPOS, and is a checkbox at the Invoice tab on the PO Item.

So, I instantiated BADI ME_PROCESS_PO_CUST.
In its method PROCESS_ITEM, I wrote the following code.

Code: Select all

  data: lv_po_head_ref  type ref to IF_PURCHASE_ORDER_MM,
        lv_MEPOHEADER   type MEPOHEADER,
        lv_MEPOITEM     type MEPOITEM.

  lv_po_head_ref = im_item->GET_HEADER( ).
  lv_mepoheader  = lv_po_head_ref->get_data( ).
  if lv_mepoheader-bsart eq 'ZSTO'.
    lv_mepoitem-repos = 'X'.
    im_item->set_data( EXPORTING im_data = lv_mepoitem ).
  endif.
After activating the badi, ME21N gives me the following.
Is it that the field REPOS is not supposed to be changed? Is there any other work around or user exit where this can be done?

Hi,

I think from the code you you need to change the set_data method part because lv_mepoitem is basically empty except for REPOS field.
I guess (haven't tried it) this what caused the error because after you set the REPOS field value, you tried to set the PO item data with lv_mepoitem structure, which is empty except for REPOS field.

Try to change the code to this (fill in the lv_mepoitem structure first, then change its value when the validation is met):

Code: Select all

" get the PO item data first.
  lv_mepoitem = im_item->get_data( ).

" Validate based on PO doc type
  if lv_mepoheader-bsart eq 'ZSTO'.

 " Change the field value 
    lv_mepoitem-repos = 'X'.
    im_item->set_data( EXPORTING im_data = lv_mepoitem ).
  endif.
Regards,

Alexius

Post Reply