Module Pool Programming
Module Pool Programming
INITIALIZATION
AT SELECTION-SCREEN
START-OF-SELECTION
TOP-OF-PAGE
END-OF-PAGE
END-OF-SELECTION.
1. PROCESS BEFORE OUTPUT (PBO) - Used to specify initial attributes for the screen.
1. NORMAL SCREEN - A screen which has maximizing, minimizing and closing options
is referred to as normal screen.
2. SUBSCREEN - A screen within a normal screen with either of above three options
is referred to as subscreen.
3. MODAL DIALOG BOX - A screen with only closing option which is used to provide
information to the end user is referred to as modal dialog box.
NAVIGATIONS TO CREATE A SIMPLE MPP PROGRAM:
SE80 -> Select Program from the dropdown list -> SPecify program name starting with SAPMZ
or SAPMY (eg. SAPMYFIRSTMPP) -> Press Enter -> Click on Yes to Create object -> Opens
another dialog box -> Click on Continue to create Top Include File for the program -> Opens
another dialog box specifying TOP INCLUDE FILE name (MYFIRSTMPPTOP) -> Click on
Continue -> Opens Program Attributes screen -> Enter short description -> The default program
type is M -> Save under a package -> Assign Request number -> A folder with specified program
name(SAPMYFIRSTMPP) is created with Top Include File.
To create a screen, right click on program name -> Create -> SCreen -> Opens dialog box
-> Specify Screen number (100) -> Continue -> Opens an interface -> Enter short description
-> Select Screen type as Normal -> Click on LAYOUT pushbutton from appn. toolbar
-> Opens Graphical Screen painter -> Drag and drop two input fields, two pushbuttons and
two text fields -> Double click on each component to specify attributes as follows:
-> Save -> Click on Flowlogic Pushbutton from appn. toolbar -> Opens Flow Logic editor
with two events (PA1 and PBO).
CASE SY-UCOMM.
WHEN 'PRINT'.
LEAVE TO LIST-PROCESSING.
WRITE :/ IO1, IO2.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
Save -> Activate -> Right click on Program name -> Activate (to activate all inactive objects).
To execute MPP program, right click on program name -> Create -> Transaction
-> Opens an interface -> Specify Tcode starting with Z or Y (zfirstmpp) -> Enter short
description -> Continue -> Specify Main program name (SAPMYFIRSTMPP) and initial Screen
number (100) -> Save under a package -> Assign a request number -> Execute.
TOP INCLUDE FILE is an area to declare variables for the program, and the variables declared
here becomes globally accessed.
SCREEN is a predefined structure used to make MPP screen validations dynamically. SCREEN
has following components:
GROUP1
INVISIBLE
REQUIRED
INPUT
OUTPUT
INTENSIFIED
IF SCREEN-INVISIBLE = 0 - Sets the input field values as visible.
SCREEN-INVISIBLE = 1 - Sets the input field as password field.
SCREEN-REQUIRED = 0 - Not a mandatory field.
SCREEN-REQUIRED = 1 - Sets input field as mandatory one.
Eg. code to perform validation dynamically for a login screen:
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'GR1'.
SCREEN-REQUIRED = '1'.
ENDIF.
IF SCREEN-GROUP1 = 'GR2'.
SCREEN-INVISIBLE = '1'.
ENDIF.
CASE SY-UCOMM.
WHEN 'LOGIN'.
CALL TRANSACTION 'SE38'.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
CASE SY-UCOMM.
WHEN 'INSERT'.
INSERT INTO KNA1 VALUES IT_KNA1.
IF SY-SUBRC = 0.
MESSAGE S000(ZMSG).
ELSE.
MESSAGE W001(ZMSG).
ENDIF.
WHEN 'EXIT'.
*LEAVE PROGRAM.
SET SCREEN 0.
ENDCASE.
LIST OF VALUES:
VRM is a predefined type group which has the following structure and internal table:
VRM_VALUE is a structure with the components KEY and TEXT.
VRM_VALUES is an internal table declared for the above structure without header line.
The above type group is used to fetch values from the internal table declared with user-defined
records and insert into the input field in the screen.
'VRM_SET_VALUES' is a function module used to carry the records from the internal table and
populate in the input field.
TYPE-POOLS VRM.
DATA IO1(20).
DATA A TYPE I.
DATA ITAB TYPE VRM_VALUES. * To create an internal table of an existing type
DATA WA LIKE LINE OF ITAB. * To create a temporary structure of same line type of internal
table.
IF A = 0.
WA-KEY = 'ABAP'.
WA-TEXT = 'ADVANCED PROGRAMMING'.
APPEND WA TO ITAB.
WA-KEY = 'BW'.
WA-TEXT = 'BUSINESS WAREHOUSING'.
APPEND WA TO ITAB.
WA-KEY = 'EP'.
WA-TEXT = 'ENTERPRISE PORTAL'.
APPEND WA TO ITAB.
A = 1.
ENDIF.
CASE SY-UCOMM.
WHEN 'PRINT'.
LEAVE TO LIST-PROCESSING.
WRITE :/ IO1.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
'CONTROLS' statement is used to allocate a memory area for the tabstrip created in the normal
screen. 'TABSTRIP' itself is a data type for the tabstrip control. Whenever a tabstrip is created,
SAP creates an object called 'ACTIVETAB' which is used to call the corresponding subscreens
for each tab button in PAI.
5. In Flowlogic editor, write following code to initiate the subscreens to the corresponding
subscreen areas of each tab button when the main screen is called:
6. In PAI, specify following code for click events on each tab button:
CASE SY-UCOMM.
WHEN 'TAB1'.
A = '10'. * calls specified subscreen during PAI
TBSTR-ACTIVETAB = 'TAB1'. * makes entire tab button in active status
WHEN 'TAB2'.
A = '20'.
TBSTR-ACTIVETAB = 'TAB2'.
WHEN 'DISPLAY'.
LEAVE TO LIST-PROCESSING.
WRITE :/ IO1, IO2, IO3, IO4.
WHEN 'EXIT'.
LEAVE PROGRAM.
ENDCASE.
TABLE CONTROLS:
Table Control component is used to view the internal table contents in the screen.
3. Create a Screen (100) -> Select Table control component from toolbar -> Double Click and
specify name (TBCL) -> Press F6 and specify internal table name (ITAB) -> Select required
fields -> Paste on the Table control -> To separate the fields, use Separators option in Table
control Attributes -> Specify labels if necessary -> Create pushbuttons (FETCH, MODIFY,
PRINT, EXIT) -> Save -> Flowlogic.
CASE SY-UCOMM.
WHEN 'FETCH'.
SELECT * FROM KNA1 INTO TABLE ITAB.
TBCL-LINES = SY-DBCNT. * To create Vertical Scrollbar
WHEN 'EXIT'.
LEAVE PROGRAM.
WHEN 'PRINT'.
GET CURSOR LINE CUR.
READ TABLE ITAB INDEX CUR.
LEAVE TO LIST-PROCESSING.
WRITE :/ ITAB-KUNNR, ITAB-NAME1, ITAB-ORT01, ITAB-LAND1.
WHEN 'MODIFY'.
LOOP AT ITAB1.
MODIFY KNA1 FROM ITAB1.
IF SY-SUBRC = 0.
MESSAGE S002(ZMSG).
ELSE.
MESSAGE E003(ZMSG).
ENDIF.
ENDLOOP.
ENDCASE.
1. Create an executable program (Z_TABLEWIZARD) in SE38 editor. Write the following code:
2. Goto SE51 -> Specify program name created earlier (Z_TABLEWIZARD) -> Specify Screen
number (200) -> Layout -> Select Table Control (Wizard) component from toolbar -> Opens
Table control Wizard -> Follow the navigations -> Save and Activate the table control.