Skip to Content
Author's profile photo anju e v

Material Range Conversion

In all custom reports developed for MM (Material Management) and SCM (Supply Chain Management) modules encompassing material range as a selection criteria we face problem with converting the range. The external material range entered by user is converted into internal material number and this is taken as range. This results in incorrect data selection.

As a solution to this problem we will have to fetch all the material numbers in case of a range and then convert them to internal number and continue, then it will work.

Clarifying the issue with below example:

Let the material range entered on selection screen be as given below
Material Number from 332A31-3061-01 to 332A31-3061-04

It shows the output for materials different than the range entered (332A31-3061-01 to 332A31-3061-04), this is because it is taking the range as 000000010000124767 (internal number for 332A31-3061-01) to
000000010000124781 (internal number for 332A31-3061-04).


The report should have fetched data only for the below 4 materials.


In order to overcome this we will fetch all the material numbers in case of a range and then convert them to internal number. Will be including the below logic AT SELECTION-SCREEN event of the report.

TYPES: BEGIN OF ty_matnr_linetype,
               matnr TYPE mara-matnr,
           END OF ty_matnr_linetype.
TYPES: lt_imatnr_tab TYPE STANDARD TABLE OF ty_matnr_linetype WITH NON-UNIQUE KEY matnr.

*- Declare a range for selection screen material
RANGES: lt_range FOR s_matnr.
DATA: l_ieq             TYPE c VALUE ‘X’,
          l_plines         TYPE i,                               “Count of original entries
          l_outlen        TYPE i,                               “Output length of material
          l_slines         TYPE i,                               “Count of selected entries
          lwa_range     LIKE LINE OF lt_range,        “Range work area
          lwa_imatnr    TYPE ty_matnr_linetype, 
          lt_matnr_int  TYPE lt_imatnr_tab,
          lt_imatnr       TYPE lt_imatnr_tab WITH HEADER LINE.

*- Converting the material entered by the user into internal material number and taking the internal material number as range

*- Count the number of entries in selection screen
  DESCRIBE TABLE s_matnr LINES l_plines.
  IF NOT l_plines IS INITIAL.
*- Calculate Output length of material number fields
        ev_outlen      = l_outlen
        no_customizing = 1
        OTHERS         = 2.

    IF l_outlen > 18.

           WHERE sign EQ ‘I’ AND option NE ‘EQ’.
        CLEAR l_ieq.
*- Edit Ranges from external to internal representation
      IF l_ieq IS INITIAL.
            selopt_name = ‘S_MATNR[]’
            range       = s_matnr[].
*- Populate the range
        LOOP AT s_matnr INTO lwa_range.
          lwa_imatnr-matnr = lwa_range-low.
          APPEND lwa_imatnr TO lt_imatnr.
*- Fetch the internal number
        SELECT matnr_int FROM materialid  INTO TABLE lt_matnr_int
        FOR ALL ENTRIES IN lt_imatnr
        WHERE matnr_int EQ lt_imatnr-matnr.
*- Get the count of original and selected material
        DESCRIBE TABLE lt_imatnr LINES l_plines.         “original matnr
        DESCRIBE TABLE lt_matnr_int LINES l_slines.      “selected matnr
*- Populate the select option with internal numbers
        IF l_slines > 0 AND l_plines <> l_slines.
          REFRESH lt_range.
          CLEAR lwa_range.
          REFRESH s_matnr.
          CLEAR s_matnr.
          lwa_range-sign    = ‘I’.
          lwa_range-option  = ‘EQ’.
          LOOP AT lt_matnr_int INTO lwa_imatnr.
            lwa_range-low = lwa_imatnr-matnr.
            APPEND lwa_range TO s_matnr.



After implementing the changes please find below the report output.We are fetching all the material numbers in case of a range and then convert them to internal number.


Thus the report only return output for these materials.


Hope this helps.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Sandra Rossi
      Sandra Rossi

      Thanks for this article. Maybe, could you add a screen capture of what we get (an incorrect list of materials) when this special code is not implemented, to illustrate "This results in incorrect data selection.".

      I'm not sure whether it would work for your particular case, but some conversion routines implement a built-in feature to do the same thing, if they implement CONVERSION_EXIT_xxxxx_RANGE_I. This is not called for dynpro fields, but from the search help selection criteria screen. We may call it explicitly. In your case, maybe it's CONVERSION_EXIT_MATN1_RANGE_I. For Material Number from 332A31-3061-01 to 332A31-3061-04, that should return the explicit list of Material Number 000000010000124767, 000000010000124714, 000000010000124717, 000000010000124781.

      More info here and here.