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: 

Issue with badi ME_PROCESS_REQ_CUST for transaction ME51N

Former Member
0 Kudos

Hi Techies,

Requirement: In t-code me51n, when user selects material and presses enter, the long text(basic text) present in mm03 for that material needs to be fetched and displayed in me51n item text.

My Piece of code:


data: lt_line type table of tline,
        ls_line type tline,
         gs_item     type mereq_item,
         g_matnr     type thead-tdname,
         g_fname     type thead-tdname,
         gt_line     type table of mmpur_textlines,
         gs_line     type mmpur_textlines,
         g_longtext  type ref to if_longtexts_mm.

  call method im_item->get_data
  receiving
    re_data = gs_item.

  g_matnr = gs_item-matnr.


  call function 'READ_TEXT'
    exporting
     client                        = sy-mandt
      id                            = 'GRUN'
      language                      = sy-langu
      name                          = g_matnr
      object                        = 'MATERIAL'
    tables
      lines                         = lt_line
   exceptions
     id                            = 1
     language                      = 2
     name                          = 3
     not_found                     = 4
     object                        = 5
     reference_check               = 6
     wrong_access_to_archive       = 7
     others                        = 8
            .
  if sy-subrc <> 0.
 message id sy-msgid type sy-msgty number sy-msgno
         with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  endif.

loop at lt_line into ls_line.
move-corresponding ls_line to gs_line.
append gs_line to gt_line.
*gt_line[] = lt_line[].
endloop.

call method im_item->if_longtexts_mm~set_text
  exporting
    im_tdid      = 'B01'
    im_textlines = gt_line
    .

I am using Badi ME_PROCESS_REQ_CUST , method PROCESS_ITEM.

The issue I am facing is when I enter material and press enter, it is going to endless loop(i.e. not able to see the output).

Can anybody suggest where I am going wrong or if I need to write the logic in some other method.

Any suggestions will be appreciated.

T&R,

Vinit

9 REPLIES 9

Former Member
0 Kudos

Execute your code only when the value of importing parameter IM_COUNT (iteration counter) is 1. This will avoid infinate loop while processing.

Wiki post [Purchase Req. Line item Data manipulation using BADI - ME_PROCESS_REQ_CUST |http://wiki.sdn.sap.com/wiki/display/ABAP/PurchaseReq.LineitemDatamanipulationusingBADI-+ME_PROCESS_REQ_CUST] will be helpful.

Regards, Vinod

0 Kudos

Thanks Vinod!!!

The link you provided was very helpful. I resolved my issue by just checking IM_COUNT = 1 along with the code which I posted earlier.

Once again thanks a lot.

T&R,

Vinit

0 Kudos

Hi vinod,

I gave im_count =1 but I am getting infinite loop please guide me to solve

Regards,

JP

0 Kudos

Hi vinoth.

Please guide me to stop that infinite loop.Already i gave IM_count = 1 but am getting the loop again.

Regards,

JP

0 Kudos

Hi vinoth,

This is the code in the method

method IF_EX_ME_PROCESS_REQ_CUST~PROCESS_ITEM.

IF im_count = 1." to avoid infinate Loop"

DATA : ls_item_data TYPE mereq_item,

lc_source TYPE REF TO cl_source_of_supply_mm,

lt_source TYPE mereq_t_source_of_supply,

ls_source TYPE REF TO cl_source_of_supply_mm,

ls_source_data TYPE mereq_source,

lv_obj TYPE REF TO object,

lv_attr TYPE string,

lv_aktyp TYPE aktyp,

lv_source_n TYPE sy-tabix.

DATA : lv_tdobject TYPE tdobject,

lv_metafield TYPE mmpur_metafield,

lt_texttypes TYPE mmpur_t_texttypes,

ls_texttypes TYPE mmpur_texttypes,

lt_textlines TYPE mmpur_t_textlines,

ls_textlines TYPE mmpur_textlines.

FIELD-SYMBOLS : <fs_lcl> TYPE ANY,

<fs_source> TYPE ANY.

*************************************************

    • Access Attributes value of Local Class

    • for getting the transaction mode of Line item

    • H-> Create

*************************************************

lv_obj ?= im_ref_item.

MOVE 'MY_STATE->AKTYP' TO lv_attr.

ASSIGN lv_obj->(lv_attr) TO <fs_lcl>.

lv_aktyp = <fs_lcl>.

IF lv_aktyp EQ 'H'. "While creating line item"

*************************************************

    • Extracting existing Item Data and Modify the fields.** Requestor Name (AFNAM) & Source of supply details

*************************************************

CLEAR : ls_item_data.

ls_item_data = im_ref_item->get_data( ).

MOVE ls_item_data-ernam TO ls_item_data-afnam.

    • Get source of supply details

CLEAR : ls_source.lc_source = im_item->get_source_of_supply( ).

lt_source = lc_source->update( im_nomei = 'X' ).

DESCRIBE TABLE lt_source LINES lv_source_n.

IF lv_source_n EQ 1. "Assign the default data otherwise populate the list"

READ TABLE lt_source ASSIGNING <fs_source> INDEX 1.

IF sy-subrc EQ 0.

ls_source ?= <fs_source>.

ls_source_data = ls_source->get_data( ).

MOVE-CORRESPONDING ls_source_data TO ls_item_data.

ENDIF.

ENDIF.

im_ref_item->set_data(

EXPORTING

im_data = ls_item_data ).

*************************************************

    • Populating item text while creating Line item

*************************************************

    • Get Text Object **

CLEAR : lv_metafield, lv_tdobject.

im_ref_item->if_longtexts_mm~get_textobject(

IMPORTING

ex_tdobject = lv_tdobject

ex_metafield = lv_metafield ).

    • Get Text IDs **

REFRESH : lt_texttypes.

CLEAR : ls_texttypes.

im_ref_item->if_longtexts_mm~get_types(

IMPORTING

ex_texttypes = lt_texttypes ).

    • Updating Item Text

LOOP AT lt_texttypes INTO ls_texttypes.

CLEAR : ls_textlines.

REFRESH : lt_textlines.

MOVE lv_tdobject TO ls_textlines-tdobject.

MOVE ls_texttypes-tdid TO ls_textlines-tdid.

MOVE '*' TO ls_textlines-tdformat.

CONCATENATE 'Test : ' ls_texttypes-tdtext INTO ls_textlines-tdline.

APPEND ls_textlines TO lt_textlines.

im_ref_item->if_longtexts_mm~set_text(

EXPORTING

im_tdid = ls_texttypes-tdid

im_textlines = lt_textlines ).

ENDLOOP.

ENDIF.

ENDIF.

endmethod.

But still am getting infinite loop .please guide me

Regards,

JP

0 Kudos

Hi Vinod, Does this need to be a attribute created locally? i did the same and set the value of im_count =1 in header method as well. But still this does not seem to be working for me. Can you please help

Former Member
0 Kudos

Resolved

0 Kudos

HI VINEET,

i gave im-count = 1 in my case but i am getting infinite loop and please guide me

Regards,

JP

0 Kudos

Hi Vinod, How can set the value of Attribute, im_count? . In which method do i need to populate.