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

ME_PROCESS_PO_CUST - how to force PROCESS_ITEM method?

Former Member
0 Likes
10,847

Hello,

The PROCESS_ITEM method availabe in BADI ME_PROCESS_PO_CUST is only processed when a user makes a change to a field in the item overview. We want PROCESS_ITEM to run any time the user chooses to save a PO.

For example, we need to read text the user may have entered and capture it in EKPO.

Just changing item text does NOT get PROCESS_ITEM called.

Any ideas on how to force it to be called?

?

1 ACCEPTED SOLUTION
Read only

mvoros
Active Contributor
0 Likes
7,451

Hi

you can't force call of this method. But it looks like your are using a wrong BADI method. If you want to implement some logic which should be called whenever user want to save a PO then why don't use method CHECK?

Cheers

13 REPLIES 13
Read only

mvoros
Active Contributor
0 Likes
7,452

Hi

you can't force call of this method. But it looks like your are using a wrong BADI method. If you want to implement some logic which should be called whenever user want to save a PO then why don't use method CHECK?

Cheers

Read only

Former Member
0 Likes
7,451

Indeed, the method CHECK does get called. However, this method only gives the programmer access to change ONLY "header" level information. I need to update line-level information.

Read only

mvoros
Active Contributor
0 Likes
7,451

Hi,

that's not true. You get a reference to PO header but this object has method GET_ITEMS which returns a table with reference to all items.

Cheers

Read only

Former Member
0 Likes
7,451

Martin,

Would you mind typing the five or six lines of code needed in the CHECK method to _____SET_____ the line item data?

I know you can _____GET_____ the lines. I need to actually update one of the EKPO fields. I do not believe such fields can be changed in the CHECK method. Please prove me wrong.

-Ken

Read only

mvoros
Active Contributor
0 Likes
7,451

Hi,

take this more as pseudo code cause I am writing it directly to this forum.



items = im_header->get_items( ).

loop at items into item.
  data = item->get_data( ).
  "change required field of data
  item->set_data( importing IM_DATA = data ).
endloop.

Read only

Former Member
0 Likes
7,451

Okay. Thank you and here is my code in the CHECK method. The bolded line of code gives the following compilation error:

"_Item is not a reference variable_" If you could please let me know what I'm missing, I would appreciate it. Thank you very much for being so engaged here!

Before that line of code, I know the "Loop at...." statement is working.

DATA lo_item TYPE REF TO if_purchase_order_item_mm.

DATA dref TYPE REF TO data.

DATA items TYPE purchase_order_items.

DATA item TYPE LINE OF purchase_order_items.

DATA re_data TYPE mepoitem.

items = im_header->get_items( ).

LOOP AT items INTO item.

*FOLLOWING LINE OF CODE GIVES ERROR

re_data = item->get_data( ).

re_data-ZZZFIELDOFMYCHOICE = 'something'.

*What would follow to set the data too................

ENDLOOP.

Read only

mvoros
Active Contributor
0 Likes
7,451

The type purchase_order_item is a structure with one component item. So you have to write


re_data = item-item->get_data( ).

Cheers

Read only

Former Member
0 Likes
7,451

Okay. That compiles no problem

After I make my change to a field and then call the SET_DATA method as follows, the SET_DATA kicks it out because it fails a CHECK statement (bolded below).

MY CODE TO SET DATA

call method item-item->set_data

exporting

im_data = re_data.

THE STATEMENT IN SETDATA_:

mmpur_dynamic_cast l_parent my_parent.

check not l_parent is initial.

check l_parent->my_ibs_firewall_on eq mmpur_yes or

l_parent->my_cust_firewall_on eq mmpur_yes.

THE VALUES IN THE DEBUGGER

l_parent

l_parent->my_ibs_firewall_on

mmpur_yes X

l_parent->my_cust_firewall_on

Read only

mvoros
Active Contributor
0 Likes
7,451

Hi,

sorry, but it looks bad. It looks like PO is not changeable at this point. You can call method IS_CHANGEABLE to check if it is or not. But it looks like you can't use this method. If you don't want to display error messages then you can try method POST. But I guess that PO will be non-changeable there as well. Definitely, you can use method PROCESS_ITEM to manipulate fields. If you really can't use this method then you can't use this BADI. You can try to find suitable enhancement point in program for ME2xN. Another possible solution could be to force the change of that field. Item object has a hash table with all fields. But I am not sure if this is safe even for custom Z fields.

Good luck

Read only

Former Member
0 Likes
7,451

Martin,

Thank you for everything here. Would you agree that one should just just look at the interfaces available in the method for assessing what can and cannot be done? I mean PROCESS_ITEMS clearly has the IM_ITEM interface for updating items and CHECK does not.

Thanks again.

Read only

0 Likes
7,451

I replay this post although it is quite old. I hope I save time for someone else who will serach for the solution I have found.

To force process_item method or process_header or any other you should use fm from group MEPOBADI, for example MEPOBADI_PROCESS_ITEM. It triggers process_item of the BADI. This is also solution if you want to trigger BADI after change of customer fields in ME21n. You react on ENTER in PAI and you call for example MEPOBADI_PROCESS_HEADER.

FM MEPOBADI* usually get parameters like IM_HEADER or IM_ITEM which are objects related to current purchase order. So at the beginning we have to remember the reference to current PO. For example: in ME_PROCESS_PO_CUST->OPEN() store the reference in your Z class in static attribute. Later in USER_COMMAND_101 you can retrive the reference and pass it to MEPOBADI* function module.

Best regards

Read only

former_member156446
Active Contributor
0 Likes
7,451

From the documentation:

FIELDSELECTION_ITEM_REFKEYS

This method enables you to change the display properties of fields at item level by supplementing or swapping the field selection reference key. You can thus restrict the processing options for certain groups of users, for example.

Parameters

The following parameters are available:

IM_ITEM

This import parameter contains the item data of the outline agreement.

The interface reference is of the category IF_PURCHASE_OUT_ITEM.

CH_KEY0 to CH_KEY6

These change parameters contain the field selection reference keys.

Notes

Because this method is frequently invoked, it is essential that you take performance into account during implementation.

Under no circumstances make any changes to the database within this method. On no account use Commits.

2. Opening of a purchase order (OPEN method)

The system opens a new document to create, change or display a purchase order.

With the OPEN method, you can import your own data and prepare it for further

processing. Documentation for BAdI method OPEN

Read only

Former Member
0 Likes
7,451

This Code is use full to update manafacuter and External number ..Using Classes

Srinivas Patchipulusu.

DATA: go_po_header   TYPE REF TO cl_po_header_handle_mm,

       go_po_order    TYPE REF TO if_purchase_order_mm,

       gc_items       TYPE i.

DATA: gt_items       TYPE purchase_order_items,

       gs_item        TYPE purchase_order_item,

       gs_item_data   TYPE mepoitem,

       gt_item_data   TYPE STANDARD TABLE OF mepoitem.

DATA : go_po_item    TYPE REF TO cl_po_item_handle_mm.

DATA : lt_models    TYPE mmpur_models,

        ls_model     LIKE LINE OF lt_models.

DATA: go_table       TYPE REF TO cl_salv_table.

DATA : ls_document TYPE mepo_document,

        lv_result   TYPE mmpur_bool.

PARAMETERS:

   p_ebeln   TYPE ebeln  DEFAULT '8500000293'.

START-OF-SELECTION.

   CREATE OBJECT go_po_header

     EXPORTING

       im_po_number = p_ebeln

     EXCEPTIONS

       failure      = 1

       OTHERS       = 2.

   IF sy-subrc <> 0.

*   MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

*              WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

   ENDIF.

   MOVE mmpur_po_process TO ls_document-process.

   MOVE 'V' TO ls_document-trtyp. " edit mode of Po

   MOVE p_ebeln TO ls_document-doc_key(10).

   MOVE mmpur_initiator_call TO ls_document-initiator-initiator.

* Set the state to existing Purchase Order *

   go_po_header->set_state( im_state = cl_po_header_handle_mm=>c_available ).

   MOVE mmpur_yes TO go_po_header->for_bapi.

* Initialize the environment *

   go_po_header->po_initialize( im_document = ls_document ).

   " initialization

*  CALL METHOD go_po_header->po_initialize

*    EXPORTING

*      im_document =

   .

*  " Read purchase order

*  CALL METHOD go_po_header->po_read

*    EXPORTING

*      im_tcode     = 'ME23N'

*      im_trtyp     = 'A'

*      im_aktyp     = 'A'

*      im_po_number = p_ebeln

**      im_document  =

**    IMPORTING

**      ex_result    =

*      .

* Read PO document *

   go_po_header->po_read(

     EXPORTING

       im_tcode     = 'ME22N'

       im_trtyp     = ls_document-trtyp

       im_aktyp     = ls_document-trtyp

       im_po_number = p_ebeln

       im_document  = ls_document

     IMPORTING

       ex_result    = lv_result ).

   " Casting to purchase order

   go_po_order ?= go_po_header.

   gt_items = go_po_order->get_items( ).

   LOOP AT gt_items INTO gs_item.

     gs_item_data = gs_item-item->get_data( ).

     gs_item_data-mfrpn = '654321'.

     gs_item_data-emnfr = '654321'.

     go_po_item ?= gs_item-item.

     CALL METHOD go_po_item->set_data

       EXPORTING

         im_data = gs_item_data.

     ls_model-model ?= go_po_item.

     APPEND ls_model TO lt_models.

*    APPEND gs_item_data TO gt_item_data.

   ENDLOOP.

   IF lt_models[] IS NOT INITIAL.

     CALL METHOD go_po_header->if_flush_transport_mm~start

       EXPORTING

         im_models    = lt_models[]

       EXCEPTIONS

         illegal_call = 1

         error        = 2

         OTHERS       = 3.

     CALL METHOD go_po_header->po_post

       EXPORTING

         im_uncomplete  = mmpur_no

         im_no_commit   = mmpur_no

         im_commit_wait = mmpur_yes

       EXCEPTIONS

         failure        = 1

         OTHERS         = 2.

     CALL METHOD go_po_header->po_close.

   ENDIF.