Module Pool Programming
Module Pool Programming
Module Pool Programming
BY ----Arjun
Objective
Introduction:
It is a special type of programming which is used to create custom SAP Screen as per business requirement. SE80 is the TCODE for creating MPP programs. Every MPP program must be executed with a transaction.
Events in MPP
Events in MPP
Events in Module Pool Programming
There are four events available. PBO (Process Before Output):Triggered before MPP screen is
displayed
screen is displayed whenever user raises an action. Also,Now PBO is also triggered.
POV (Process On Value Request): Triggered when User Clicks on search help or F4 Button
POH (Process On Help Request): Triggered when User Clicks on search help or F4 Button
Screen is displayed
PAI triggered
Include prgs: Basically there are four include programs which are created automatically for an MPP program <MPP name>_TOP top include program All data declarations. <MPP name>_o01PBO include program All logic related to PBO event <MPP name>_I01PAI include program All logic related to PAI event <MPP name>_F01Forms include program All logic related to subroutines
Screen
Screen
SCREEN:
It is a visible layout which is displayed in the output. The components of the Screen are
Components of Screen:
Attributes : Properties of screen Element List : List of UI/Library elements Flow-Logic : Abap logic related to MPP Layout : Screen Designing Area
FLOW-LOGIC
FLOW-LOGIC
It will contain the logic related to screen in the form of modules By default, 2 events will be available with their corresponding modules as below:
Just uncomment the modules and create them and write the abap logic.
PROCESS BEFORE OUTPUT. *MODULE STATUS_0100. PROCESS AFTER INPUT. *MODULE USER_COMMAND_0100.
MODULE
MODULE
MODULE:
It is an sub-program which contains the ABAP code for a screen . Flow-Logic cannot understand ABAP statements. So the entire ABAP code is written in the form of modules Since the entire abap logic is divided in the form of modules, that is why it is called MODULE POOL PROGRAMMING
STEPS: Go to SE80 Select program from dropdown list Give a name & press enter Click on YES Click on Continue
Give a name for TOP include program Press ENTER The program will be created Uncomment each include program and create them Right click on the program nameACTIVATE
Creating a Screen:
Right click on program nameCreateScreen
Give the screen number as 0100 and Press ENTER Give the description Click on Flow-Logic Uncomment the modules and create them as below
Click on Layout Button Drag and drop text UI element onto the screen
Double click on it Provide the name and texts Name T1. Text This is a sample Program. Check the below screen shot
Save and activate. Right click on Program name create. Transaction. Give the text, program name, screen number. Select all the checkboxes at the bottom. Save it. Execute the transaction and test the program.
Business Req: Create a MPP which displays material details for a given material no
Create a MPP prg in SE80 and create all include programs Create a Screen and create PBO and PAI Modules Goto TOP Include prg and declare the following .
Save & Activate TOP Include prg immediately Now goto Screen 0100 layout. Click on Dictionary/Program fields ICON
and click on
Now Drag and drop text fields from library and place them before each input field . Now Drag and drop a button also and provide the details as below:
which is clicked
Now go to PAI module and write the below code. Save,Activate,Test it.
The output is :
Enter the Material no Click on GET button The details should be displayed
Syntax :Field <Field-name> Module <Module-Name>. Example :Field V_matnr Module Validate_matnr.
Ex Prg:
Create a prg as below:
Double click and create the module . Write the below code in the module
<Field-Namen> .
Module <Module name>. ENDCHAIN.
Ex Prg:
Create same prg as above:
Here I want to validate both MATNR and MTART fields. Write the below code under PAI event.
Save, activate and test it . The difference b/w single field and multiple field validation is : Single field validation: It is used to validate a single field. Only that particular field which is validated is input enabled when there is an error. The remaining fields will be input disabled. With Multiple field validation: It is used to validate multiple fields. All the fields which are in between CHAIN..ENDCHAIN are input enabled when there is an error. The remaining fields will be input disabled.
Creating a Screen: Create Screen 0100. Create a PBO module and PAI module. PROCESS BEFORE OUTPUT. MODULE STATUS_0100. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100.
SCREEN LAYOUT
Click on layout button. Click on dictionary/program fields icon. Give the field name as V_CH1. Select radionutton as below
Place it on the screen. Click on dictionary/program fields icon again . Give the field name V_TEXT Place it on the layout
Dobule click on the check and set the below properties : NAME,TEXT,FCTCODE
Now go to PAI module and write the below code. Save,Activate,Test it.
RADIOBUTTON IN MPP
Steps:Create a program in se80.
Define the below data declarations in the Top include file.
DATA : v_RB1(1) TYPE C VALUE 'X'. DATA : V_RB2(1) TYPE C. DATA : V_TEXT1(25) TYPE C.
Creating a Screen:
Create Screen 0100. Create a PBO module and PAI module. PROCESS BEFORE OUTPUT. MODULE STATUS_0100. PROCESS AFTER INPUT. MODULE USER_COMMAND_0100.
SCREEN LAYOUT
Click on layout button. Click on dictionary/program fields icon. Give the field name as *. Select the following as below:
Write the below code in PAI Module. Save activate and test
TABSTRIP
Tab strips are used to divide the main screen into sub screens to display mass amount of data. Each sub screen is called as a TAB. Each sub screen Should be designed separately with a no. Each sub screen must have an area to display the sub screen called as Sub screen area When you drag and drop the TABSTRIP from the library, two tabs will be displayed by default For each tab create the sub screens and sub screen areas CONTROLS is the keyword used to declare a tab strip. Ex: CONTROLS : TABSTR TYPE TABSTRIP.
Finally use the below syntax under the PBO event to assign each sub screen no to its corresponding sub screen area
Syntax :Call subscreen <subscreen area >including <program name> <sub screen>.
Ex:Call subscreen SUBAREA1 including sy-repid 0200. Call subscreen SUBAREA2 including sy-repid 0300.
Syntax:<tabstrip name >-active tab=TABNAME. Ex :- TBSTR-active tab =tab1. TBSTR-active tab =tab2.
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 50
Real Time Ex on TABSTRIP BR: Develop a MPP prg which display material details and description details in 2 separate tabs.
STEPS:
Create an MPP Prog Create a MAIN screen by no 1000
Goto top include prg and declare a TBASTRIP and other data declarations as below
Save activate immediately
Give the fieldname as V_MATNR and click on GET FROM PROGRAM button
Place the field on layout Provide the text lable for the field. The screen should look as below.
Drag and Drop tabstrip onto layout. Double click on tabstrip (exactly at center) and set the name as TBSTR(name given in top include prog)
Double click on TAB1, give the text as GEN.DATA,give the FCT code as TAB1.
Similarly, Double click on TAB2, give the text as DESC.DATA, give the FCT code as TAB2.
Click on TAB1,Drag and drop a subscreen under TAB1 This is because each TAB should have a subscreen area to display subscreen give the name as SUB1.
Similarly click on TAB2,Drag and drop a subscreen under TAB2 , give the name as SUB2. Click on FLOW-LOGIC Write the below code under PBO event. This is because we need to assign each sub screen no to its corresponding sub screen area
CREATING sub screens Now create 2 sub screens by the numbers 0100 and 0200
Goto subscreen 0100 Click on layout button Click on Dictionary/program fields icon
Give the fieldname as WA_MARA and click on GET FROM PROGRAM button
Select and Place all the fields on layout Provide the text lable for all fields. The screen should look as below.
Now Goto subscreen 0200 Click on layout button Click on Dictionary/program fields icon
Give the fieldname as WA_MAKT and click on GET FROM PROGRAM button
Select and Place all the fields on layout Provide the text lable for all fields. The screen should look as below.
Finally write the below code to activate the tabs in PAI module.
SaveactivateTest it
Steps for tabstrip:STEPS: Create an mpp program. Declare TABSTRIP in top include program. Drag and drop tab strip on to the screen. By default, 2 tabs will be available Create subscreen areas for each TAB. Cerate subscreen for each TAB. Assign each subscreen to subscreen area under PBO event.
TABLE CONTROL
o TABLE CONTROL : It is an element which is used to display the data in the form of a table format is called TABLE CONTROL. There are 3 important points to be followed, when working with table control. 1. Table control declaration. 2.
1.
Loop at ITAB into WA with control <table control name>(IN PBO). Endloop
Endloop.
TABLE CONTROL
Controls : <table control> name type table view using screen <screen no>.
Loop at PBO
The loop at ITAB into WAend loop must be used in PBO event to read each record from ITAB internal table into work area and then work area to table control columns
TABLE CONTROL
Loop at PAI
The loop at ITAB into WAend loop must be used in PAI event to read each record from table control columns into internal table
PBO event
ITAB --------------WA----------------Table control. Loop at ITAB into WA with control <table control name> Endloop
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 67
TABLE CONTROL
PBO EVENT
PAI EVENT
TABLE CONTROL
PAI Event
Table Control ---------Internal Table ------------- Work area. Loop at ITAB . Endloop. Vertical scrollbar : In Table control by default, we dont get vertical scroll bar. To display it, use the below syntax <TABLECONTROLNAME>-LINES = <NO> Horizontal & Vertical Lines : In Table control by default, we dont get vertical and Horizontal lines. To display them, Set the below property.
Ex on Table control
Busniess Req : Develop a MPP program which displays list of the material for a material type. Steps:Create a program in se80.
Define the below data declarations in the Top include file.
SCREEN
Create Screen 0100. Write the below statement under the PBO event.
SCREEN LAYOUT
Click on layout button. Click on dictionary/program fields icon. Give the field name as v_mtart. Place it on the screen. Provide a text(MATERIAL TYPE ) for the input field.
Drag and drop a button & define the properties. Name: GET Text : GET DATA Fctcode: GET The screen should look as above Drag and drop table control UI element on the screen. Double click on it, set the properties as below. Name = TBCL (same as top include file name) Separators: Vertical Horizontal Click on the dictionary / program fields icon. Give the field name as wa_mara. Click on continue. Place them on the table control UI element. Each field will be displayed as column.
Provide the column headings by drag & drop using text label.
Click on text field, place it on the first column. Give the name as T1, text as matnr. Repeat for all fields Textfield1 Textfield2 Textfield3 Textfield4
Name :T1
TEXT: Matnr Click on the flow logic.
Name :T2
Name :T3
Name :T4
TESTING
Execute the TCODE. The output is as below:
Go to the screen layout, add a button by name = save, text = save data, Fct code = save.
Double click on the PAI module & write the below code. IF SY-UCOMM = 'SAVE'. MODIFY MARA FROM TABLE I_MARA2. "UPDATE DATABASE IF SY-SUBRC = 0. MESSAGE : 'THE DATA IS SUCCESSFULLY MODIFIED' TYPE 'I'. ENDIF. *********Move THE MODIFIED DATA BACK TO ORIGINAL ITAB(I_MARA)********* REFRESH I_MARA. LOOP AT I_MARA2 INTO WA_MARA2. MOVE-CORRESPONDING WA_MARA2 TO WA_MARA. APPEND WA_MARA TO I_MARA. ENDLOOP. ENDIF.
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 77
o Whenever we want to move from one screen to another screen we use below two statements.
CALL SCREEN
CALL SCREEN
This statement is used to call the new screen by suspending the current screen Once the new screen processing is finished it will come back or resume back to the old screen and continuous its processing.
SET SCREEN
SET SCREEN
This statement will not call any new screen, but it will set a new screen as a next screen Once the current screen is finished totally, then it will call new screen Once the new screen is processed it will not come back automatically to the previous screen If we want to came back, use the statement LEAVE TO SCREEN <SCREEN NO>.
PROCESS ON VALUE REQUEST : This event is triggered whenever the user clicks on search help button for an input field. Syntax :PROCESS ON VALUE REQUEST.
PROCESS ON HELP REQUEST : This event is triggered whenever the user clicks on F1(Help Button). Syntax : PROCESS ON HELP REQUEST.
Ex on POV Event: create a MPP programe create a screen 0100. Declare a below STMT in top include file. Data : v_file type RLGRAP-filename. save , active. Go to screen 0100 layout. Place an input field & text field on screen as below.
click on flow logic. Write the below code. PROCESS ON VALUE-REQUEST . FIELD V_FILE MODULE GET_F4 . Create the module and write the below code:
MODULE GET_F4 INPUT. CALL FUNCTION 'KD_GET_FILENAME_ON_F4' EXPORTING PROGRAM_NAME = SYST-REPID DYNPRO_NUMBER = SYST-DYNNR FIELD_NAME = 'V_FILE' CHANGING FILE_NAME = V_FILE . ENDMODULE. " GET_F4 INPUT
The output is :
Ex on POV Event: Same prg as abovebut just write the below event in screen 100 Flowlogic Process on Help-Request Field V_File module GET_F1. create the module and write the below code in the module. Module GET_F1 INPUT. Message please select file name type I.
Endmodule.
Mandatory fields steps: Double click on the field where you want to set mandatory parameter. Go to the program tab, set as Input = Required.
Ignoring the Mandatory fields:o If we want to ignore or exit an MPP screen without entering the mandatory fields, then please follow
Syntax:-
Click on the flow logic & write the below code. PROCESS AFTER INPUT. Module module_EXIT AT EXIT-Command. Create the module and write the below code. Module module_EXIT Input. Case sy-ucomm. When EXIT. Leave program. Endcase
Endmodule.
Save, Active & Text it.
TYPES OF SCREENS
TYPES OF SCREENS
There are basically Three types of screens NORMAL SCREEN : A main screen with minimize, maximize and close buttons is called a NORMAL SCREEN SUBSCREEN : A part of screen with in a main screen is called a SUBSCREEN. Generally subscreens are used in TABSTRIPS.
MODEL DIALOG BOX : A screen with only close button is called MODEL DIALOG BOX.
INTERVIEW QUESTIONS
What are the various events available in MPP, explain with example? What are the various include programs in MPP?
What do you write in the Flow-Logic ? What is a MODULE? How do you create a transaction? What is the system variable where FCT code is stored? How do you disable an input field? How do you validate a single field? How do you validate a multiple fields? What is the exact diff b/w single field& multiple fields validation?
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 97
INTERVIEW QUESTIONS
What is the use of sub-screen area? What is a table control? What is the use of loop at itab into PBO and PAI? Tell me about table control with modifications? How do you vertical scroll bar in table control? What is the difference between call screen and set screen? How do you create mandatory fields? How do you exit an MPP screen without entering the mandatory fields? How do you assign a search help? What are the various types of screens and explain each?
SAP AG 2001, Smart Forms - the Form Printing Solution,
Claudia Binder / Jens Stumpe 98
.THANK YOU