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
CALL FUNCTION ‘MATNR_GET_OUTLEN’
ev_outlen = l_outlen
no_customizing = 1
OTHERS = 2.
IF l_outlen > 18.
LOOP AT s_matnr TRANSPORTING NO FIELDS
WHERE sign EQ ‘I’ AND option NE ‘EQ’.
*- Edit Ranges from external to internal representation
IF l_ieq IS INITIAL.
CALL FUNCTION ‘MATNR_CONV_RANGES’
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.
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.