Introduction: This article will discuss in detail how to create a Range in Module Pool Program.
Requirement and scenario: Before breaking the ice, I would like to describe kernel of the topic.
When we create a range, at the same time create an internal table then it have four components …
Sign
Option
Low
High
These all four component have the corresponding value.
Steps to be followed:
Step 1 : Create a program in SE38 and program type should be Module pool (M type) after that save
& activate the program .
Step2: Go to transaction SE51 and write the same program name which you have created in SE38
and then create screen for program.
Step3: Select Screen type as Normal Screen, after that click Layout button
Step4: Choose one text field, two input/output field and box for background.
And give the input field name similar to MLOW and MHIGH.
Step 5: Now go to SE11 and create search help for input/output field .
Step 6 : Create search help .
Step7: Now go to SE51->Layout-> and fill this search help name on both input/output attribute windows.
Step8: Now go Flow Logic and double click on module User_command_9000.
Step 9 : Define user_command_9000 in main program .
Step10 : Write the following code…………..
*&---------------------------------------------------------------------*
*& Module Pool ZSAPMZ_RANGE_IN_MPP
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM ZSAPMZ_RANGE_IN_MPP.
TYPE-POOLS:SLIS.
TABLES : MARA .
DATA :MLOW(18),MHIGH(18).
DATA :MLOW1(18),MHIGH1(18).
DATA: BEGIN OF T_MARA OCCURS 1,
MATNR TYPE MARA-MATNR,
ERSDA TYPE MARA-ERSDA,
ERNAM TYPE MARA-ERNAM,
PSTAT TYPE MARA-PSTAT,
MBRSH TYPE MARA-MBRSH,
END OF T_MARA.
DATA : BEGIN OF RANGE OCCURS 0 ,
SIGN(1),
OPTION(2),
LOW(18),
HIGH(18),
END OF RANGE .
DATA : T_FCAT TYPE TABLE OF SLIS_FIELDCAT_ALV ,
W_FCAT TYPE SLIS_FIELDCAT_ALV ,
W_LAYO TYPE SLIS_LAYOUT_ALV .
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9000 INPUT.
CASE SY-UCOMM.
WHEN ''."FC-CODE OF ENTER BUTTON
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT' "CONVERSION ROUTINE FOR
MLOW
EXPORTING
INPUT = MLOW
IMPORTING
OUTPUT = MLOW1
EXCEPTIONS
LENGTH_ERROR = 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.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'"CONVERSION ROUTINE FOR
MHIGH
EXPORTING
INPUT = MHIGH
IMPORTING
OUTPUT = MHIGH1
EXCEPTIONS
LENGTH_ERROR = 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.
******************************************************************
* LOGICALLY BUILD A INTERNAL TABLE (RANGE)
******************************************************************
RANGE-SIGN = 'I'. " I OR E
RANGE-OPTION = 'BT'.
RANGE-LOW = MLOW1 .
RANGE-HIGH = MHIGH1 .
APPEND RANGE ."APPEND DATA IN INTERNAL TABLE
******************************************************************
PERFORM FETCH_DATA .
PERFORM DISPLAY_DATA .
ENDCASE.
ENDMODULE. " USER_COMMAND_9000 INPUT
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM FETCH_DATA .
SELECT MATNR
ERNAM
ERSDA
PSTAT
MBRSH
FROM MARA
INTO CORRESPONDING FIELDS OF TABLE T_MARA
WHERE MATNR IN RANGE .
ENDFORM. " FETCH_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM DISPLAY_DATA .
LEAVE TO LIST-PROCESSING .
W_FCAT-TABNAME = 'MARA'.
W_FCAT-FIELDNAME = 'MATNR'.
W_FCAT-SELTEXT_M = 'Material No'.
APPEND w_fcat to t_Fcat .
W_FCAT-TABNAME = 'MARA'.
W_FCAT-FIELDNAME = 'ERSDA'.
W_FCAT-SELTEXT_M = 'Created On'.
APPEND w_fcat to t_Fcat .
W_FCAT-TABNAME = 'MARA'.
W_FCAT-FIELDNAME = 'ERNAM'.
W_FCAT-SELTEXT_M = 'Name of Person'.
APPEND w_fcat to t_Fcat .
W_FCAT-TABNAME = 'MARA'.
W_FCAT-FIELDNAME = 'PSTAT'.
W_FCAT-SELTEXT_M = 'Maintenance status'.
APPEND w_fcat to t_Fcat .
W_FCAT-TABNAME = 'MARA'.
W_FCAT-FIELDNAME = 'MBRSH'.
W_FCAT-SELTEXT_M = 'Industry sector'.
APPEND w_fcat to T_FCAT.
W_LAYO-ZEBRA = 'X'.
W_LAYO-COLWIDTH_OPTIMIZE = 'X'.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER = ' '
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME = 'MARA'
* I_BACKGROUND_ID = ' '
I_GRID_TITLE ='MATERIAL REPORT'
* I_GRID_SETTINGS =
IS_LAYOUT = W_LAYO
IT_FIELDCAT = T_FCAT
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* I_HTML_HEIGHT_TOP = 0
* I_HTML_HEIGHT_END = 0
* IT_ALV_GRAPHICS =
* IT_HYPERLINK =
* IT_ADD_FIELDCAT =
* IT_EXCEPT_QINFO =
* IR_SALV_FULLSCREEN_ADAPTER =
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = T_MARA[]
* EXCEPTIONS
* PROGRAM_ERROR = 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.
ENDFORM. " DISPLAY_DATA
Step11: After coding save & activate the program.
Step12: go to T-code SE93 and create T-code for program ZSAPMZ_RANGE_IN_MPP
And fill required information
Step13: Write program name and screen no of program and save it .
Step14 : Execute the
t-code ZMPP_RANGE.
Step15: After filling Material No range, Press Enter Button.
Result: