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: 

Accessing all the line items of Purchase requisition(ME51N)

Former Member
0 Kudos

Hi All,

Is there any way to access all the line items of a purchase requisition(ME51N) at a time?  I Implemented a BADI ‘ME_PROCESS_REQ_CUST’ and check all the interfaces like PROCESS_ITEM, CHECK, POST etc and found these interfaces only triggers for one line item which is currently being processed. Can anyone suggest.

Regards,

Jitendra

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Thank you all for your help. Finally I solved the user requirement with the below code, which I have written in CHECK method.

DATA : ls_item     TYPE mmpur_requisition_items,"mereq_item,

          lv_lifnr    TYPE wlief,

          l_item_list TYPE mmpur_requisition_items,

          l_item      TYPE mmpur_requisition_item,

          l_item_akt  TYPE mereq_item,

          l_item_ref  TYPE REF TO if_purchase_requisition_item,

          ld_attr     TYPE string,

          lo_obj      TYPE REF TO object,

          lv_procss   TYPE char1.

   FIELD-SYMBOLS:

     <lo_lcl>        TYPE any,

     <ls_item>       TYPE mereq_item,

     <ls_itemx>      TYPE mereq_itemx.

   IMPORT lv_procss TO lv_procss FROM MEMORY ID 'ZPROCSSED'.

* TO execute update process for all line item only once

   IF lv_procss NE 'X'.

* Get all the line item into internal tbale

     CALL METHOD im_header->get_items

       EXPORTING

         im_auth_check = mmpur_no

         im_release_op = mmpur_no

       RECEIVING

         re_items      = ls_item.

     l_item_list = im_header->get_items( ).

     LOOP AT l_item_list INTO l_item.

* Decode the line item from reference to Data.

       l_item_akt = l_item-item->get_data( ).

       l_item_ref = l_item-item.

       lo_obj     ?= l_item-item.

       ld_attr = 'MY_STATE'.

       ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.

       ld_attr = 'MY_STATE->ITEM'.

       ASSIGN lo_obj->(ld_attr) TO <ls_item>.

* Check Vendor is not initial

       IF <ls_item>-lifnr IS NOT INITIAL .

         lv_lifnr = <ls_item>-lifnr.

       ELSE.

         <ls_item>-lifnr = lv_lifnr  .

       ENDIF.

* Update line item with Vendor

       ld_attr = 'MY_STATE->ITEMX'.

       ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.

     ENDLOOP.

     lv_procss = 'X'.

     EXPORT lv_procss FROM lv_procss TO MEMORY ID 'ZPROCSSED'.

   ENDIF.


Regards,

Jitendra Nayak

11 REPLIES 11

rajkumarnarasimman
Active Contributor
0 Kudos

Hi Jitendra,

I found that you are not able to find the item internal table name inside Exit. Get the Internal table and Program name for Item. Using Field symbol concept, access the value inside Exit as shown below.


"Data Declarations
   
FIELD-SYMBOLS: <tblgart>        TYPE ANY TABLE,
                   <wa_tblgart>    
TYPE ANY,
                   <fs_value_lgart>
TYPE ANY,
                   <fs_value_betrg>
TYPE ANY.

   
DATA: obj_tblTYPE REF TO data.

"Assign Program and Internal Table as shown below

   
ASSIGN ('(MP000800)TBLGART[]') TO <tblgart>.
   
CREATE DATA obj_tbl LIKE LINE OF <tblgart>.
   
ASSIGN obj_tbl->* TO <wa_tblgart>.

   
"Check Table have initialized
   
IF <tblgart> IS ASSIGNED.
     
LOOP AT <tblgart> ASSIGNING <wa_tblgart>.
       
ASSIGN COMPONENT 'LGART' OF STRUCTURE <wa_tblgart> TO <fs_value_lgart>.

       
"Check Wage type is initialized
       
IF <fs_value_lgart> IS ASSIGNED.

         
"Check Transport/Conveyance Allowance
         
IF <fs_value_lgart> = '1002'.

          "Write the Logic Here    

          ENDIF.
         
ENDIF.
       
ENDIF.
     
ENDLOOP.

   
ENDIF.

Regards

Rajkumar Narasimman

0 Kudos

Hi Rajkumar,


Thank you for your quick reply. Please let me know in which EXIT I should write the above code.


Regards,

Jitendra

0 Kudos

Hi Jitendra,

The above code is common one, find internal table name and variable and change for your program. Place the breakpoint in the following Exit, hope it will trigger.

  • EXIT_SAPLMEREQ_001
  • EXIT_SAPLMEREQ_002
  • EXIT_SAPLMEREQ_003

Regards

Rajkumar Narasimman

qingda_niu
Explorer
0 Kudos

Hi  Jitendra

    

You can use the CHECK Method , use the parameter 'IM_HEADER' whose Type is IF_PURCHASE_REQUISITION.

The interface IF_PURCHASE_REQUISITION has a method called 'GET_ITEMS', Method get_items will return all the items of PR. ( IF_PURCHASE_REQUISITION_ITEM->get_item will return every single item)


Regards.

Qingda Niu

0 Kudos

Hi Qingda Niu,

Thank you for the information. I know that using the above given method I can get all the line items of purchase req. at a time, but those items are in reference format like '->{O:1265*\FUNCTION-POOL=MEREQ\CLASS=LCL_REQ_ITEM}'. Could you please help me how to decode it into original format and update some field value, which will be updated in database.

Regards,

Jitendra

0 Kudos

Hi Jitendra.

  I think you are not familiar with the 'OO Programming', just like this:


DATA: lr_t_pr_item  TYPE mmpur_requisition_items," Refer to INTERFACE -> IF_PURCHASE_REQUISITION_ITEM

         lr_s_pr_item  TYPE mmpur_requisition_item.

   DATA: lr_pr_item    TYPE REF TO if_purchase_requisition_item.

   DATA: ls_mmreq_item TYPE mereq_item.

   CALL METHOD im_header->get_items

*    EXPORTING

*      im_auth_check = MMPUR_NO

*      im_release_op = MMPUR_NO

     RECEIVING

       re_items      = lr_t_pr_item.

   LOOP AT lr_t_pr_item INTO lr_s_pr_item.

     lr_pr_item = lr_s_pr_item-item.

*" Here, we will get the PR Item, then you can use it do anything, e.g. check the item

     CALL METHOD lr_pr_item->get_data

       RECEIVING

         re_data = ls_mmreq_item.

*" Check The Item data, if an error occured, set the 'ch_failed' as 'X'

*    ch_failed = 'X'.

   ENDLOOP.

You can try it.

Regards.

Qingda Niu

0 Kudos

Hi Qingda Niu,

Thank you for the information. My requirement is while creating PR the user will enter the field 'Desired Vendor' in first line item only. When save it the same vendor number will be copied to the rest line item. I have written the below code, in debugger mode I checked the structure is updating and set_data is calling successfully. But the database table 'EBAN' is not being updated.

Here is the code.

DATA : ls_item  TYPE  mmpur_requisition_items,"mereq_item,

lw_item  TYPE mmpur_requisition_item,

pr_item  TYPE  REF TO if_purchase_requisition_item,

lv_lifnr    TYPE wlief,

ls_req_item TYPE mereq_item,

ls_datax      TYPE mereq_itemx.

     CALL METHOD im_header->get_items

*  EXPORTING

*    im_auth_check = MMPUR_NO

*    im_release_op = MMPUR_NO

     RECEIVING

       re_items      = ls_item

       .

   LOOP AT ls_item INTO lw_item.

     pr_item = lw_item-item.

     CALL METHOD pr_item->get_data

       RECEIVING

         re_data = ls_req_item.

     IF ls_req_item-lifnr IS NOT INITIAL.

       lv_lifnr = ls_req_item-lifnr.

     ELSE.

       ls_req_item-lifnr lv_lifnr.

       CALL METHOD pr_item->set_data

         EXPORTING

           im_data = ls_req_item.

       MOVE: 'X' TO ls_datax-lifnr,

             'X' TO ls_datax-lifnr.

       pr_item->set_datax( ls_datax ) .

       pr_item->set_datax( im_datax = ls_datax ).

     ENDIF.

   ENDLOOP.

Could you please tell me what I missed?

Regards,

Jitendra

0 Kudos

Hi Jitendra -

Try to create a local variable in the implementing class for vendor. Use the Method PROCESS_ITEM to set the vendor by populating the local variable for the 1st item  and then populate vendor for other lines with this local variable.


Hope it helps

0 Kudos

Just like what Atul Mohanty said,

use method process_item, and create a global variable of the implementing class, and use methodss: set_data and set_datax.

P.S. you should use the parameter IM_TRTYP of method 'OPEN' also, if you want to achieve your requirement only when creatint a PR. The value doiman of im_trtyp, you will find it in the relevant domain.

Regards.

Former Member
0 Kudos

This message was moderated.

Former Member
0 Kudos

Thank you all for your help. Finally I solved the user requirement with the below code, which I have written in CHECK method.

DATA : ls_item     TYPE mmpur_requisition_items,"mereq_item,

          lv_lifnr    TYPE wlief,

          l_item_list TYPE mmpur_requisition_items,

          l_item      TYPE mmpur_requisition_item,

          l_item_akt  TYPE mereq_item,

          l_item_ref  TYPE REF TO if_purchase_requisition_item,

          ld_attr     TYPE string,

          lo_obj      TYPE REF TO object,

          lv_procss   TYPE char1.

   FIELD-SYMBOLS:

     <lo_lcl>        TYPE any,

     <ls_item>       TYPE mereq_item,

     <ls_itemx>      TYPE mereq_itemx.

   IMPORT lv_procss TO lv_procss FROM MEMORY ID 'ZPROCSSED'.

* TO execute update process for all line item only once

   IF lv_procss NE 'X'.

* Get all the line item into internal tbale

     CALL METHOD im_header->get_items

       EXPORTING

         im_auth_check = mmpur_no

         im_release_op = mmpur_no

       RECEIVING

         re_items      = ls_item.

     l_item_list = im_header->get_items( ).

     LOOP AT l_item_list INTO l_item.

* Decode the line item from reference to Data.

       l_item_akt = l_item-item->get_data( ).

       l_item_ref = l_item-item.

       lo_obj     ?= l_item-item.

       ld_attr = 'MY_STATE'.

       ASSIGN lo_obj->(ld_attr) TO <lo_lcl>.

       ld_attr = 'MY_STATE->ITEM'.

       ASSIGN lo_obj->(ld_attr) TO <ls_item>.

* Check Vendor is not initial

       IF <ls_item>-lifnr IS NOT INITIAL .

         lv_lifnr = <ls_item>-lifnr.

       ELSE.

         <ls_item>-lifnr = lv_lifnr  .

       ENDIF.

* Update line item with Vendor

       ld_attr = 'MY_STATE->ITEMX'.

       ASSIGN lo_obj->(ld_attr) TO <ls_itemx>.

     ENDLOOP.

     lv_procss = 'X'.

     EXPORT lv_procss FROM lv_procss TO MEMORY ID 'ZPROCSSED'.

   ENDIF.


Regards,

Jitendra Nayak