Module Pool Programming: by - Sudhir Kumar
Module Pool Programming: by - Sudhir Kumar
By SUDHIR KUMAR
Introduction
Syntax Description
Demonstration
Exercises
HelpMe
2
Purpose
For performing any kind of task in SAP R/3 system, a transaction is used.
SAP provides a standard set of transactions to manipulate data in the
system. But sometimes, the need to create a customer specific transaction
arise due to following reasons :
Use
user-friendly user interface.
format and consistency checks for the data entered by the user.
an easy way of correcting wrong entries.
access to data by storing it in the database.
PrepareMe
Syntax description
Demonstration
Exercises
HelpMe
5
Creating a Program
Create a program using transaction SE38. Program name as
Z_MODULE_TRAINING.
Program type should be Module Pool. Save and activate the program.
Program Structure
Module pool program when viewed from SE80 transaction will have
structure as below,
Use of Screen
Screen is a interface between user and SAP.
Using screen user can provide input to program and in turn program will
display result on screen.
Screen is made up of screen elements such as text box, input/output field,
check box, radio button etc.
One of the strength is that screen elements are combined with the ABAP
dictionary to allow check the consistency of the data that user has
entered.
10
Screen Painter
11
Developing Screen
12
Developing Screen
13
Developing Screen
14
Screen Attributes
Short description Describes screen purpose
Original language Default logon language
Package Identifies the package with which screen is saved
Last changed on/by Date & time screen is last changed
Last generation Date & time screen is last generated.
15
Screen Attributes
Screen Type
Normal Default setting
Subscreen To indicate the screen as a subscreen
Modal dialog box used to display details in a dialog box. Used for data
input, confirmation/error/help messages.
Selection screen Identifies selection screen. The system sets this
attribute automatically.
Settings
Hold data On checking this, system can hold entries made on the screen
at runtime. System automatically displays this data if the user calls the
particular screen again.
16
Screen Attributes
Settings
Switch off runtime compress On setting this option, the screen is not
compressed at runtime. If you hide fields dynamically at runtime, empty
lines may appear on the screen and the processing may take longer time.
Template non executable If this attribute is set:
The screen cannot be generated or activated and therefore cannot be
executed.
The screen is not included in the screen consistency checks during the
extended program check.
This attribute is primarily for internal use by SAP.
Hold scroll position On setting the attribute, the scroll position is
retained when the user returns to the screen after processing another
screen.
Without application tool bar To suppress the display of the application
toolbar belonging to the current program status.
Other Attributes
Next Screen Next screen number to be displayed.
17
Screen Attributes
Other Attributes
Cursor position Identifies the screen element that contains the cursor when a
screen is first displayed. If you leave this field blank, the system uses the first
screen field that can accept input.
Screen group Specifies a four-character identifier of a group of associated
screens.
Line/Columns
Occupied Specifies the size of the screen area currently occupied with
screen elements
Maintained
Context menu It will hold a routine name required to set up the context menu
in the program. This routine connects the screen (elements) from the Screen
Painter to the context menu of the program.
Input/output fields , Text fields, Table controls, Subscreens
Global Class CL_CTMENU , methods- LOAD_GUI_STATUS, ADD_FUNCTION,
ADD_MENU etc..
18
The Screen Painter has a layout editor that you use to design your screen
layout.
It works in two modes:
Graphical mode Drag and drop interface is used, similar to a drawing
tool.
Alphanumeric mode Keyboard and menus are used for designing.
Both modes offer the same functions but use different interfaces.
Graphical mode of screen designing is commonly used.
19
Screen Designing
We have learnt about creating a screen.
To start screen design, click on layout button on
screen.
20
Element bar screen element attributes appear in this line. You can also
change these attributes in the corresponding field.
21
Screen Components
Screen element properties can be seen
in detail by double clicking on the
element.
Properties of an element can be set
here, such as variable length, F4 help,
input/output, mode of display etc.
Best practice is to define screen
elements by adopting the corresponding
field from the ABAP Dictionary. However,
you can also use field descriptions that
you defined in your program. To do this
you must generate the program first.
22
Screen Elements
Radio button
Push button
Tab strip
Box
Sub screen area
Table control
Custom control
Status Icon
23
Screen Elements
Push Button
Can be placed on screen by drag
& drop from Element palette.
To set the properties, double
click on it.
Each screen element should
have unique name.
In addition to that push button
will have text and function code
assigned to it.
24
Screen Elements
Once screen is designed, it should be saved and checked for errors and activated. Screen looks as below,
25
Testing Screen
Screen can tested by executing F8 or click on button
26
Testing Screen
27
Flow Logic
28
Menu Painter
29
Menu Painter
Now double click on STATUS_0400. A pop up window will appear. Click on Yes.
*&---------------------------------------------------------------------*
module STATUS_0400 output.
* SET PF-STATUS 'xxxxxxxx'.
* SET TITLEBAR 'xxx'.
endmodule.
30
Menu Painter
Uncomment the line SET PF-STATUS 'xxxxxxxx'. and replace 'xxxxxxxx with
name STATUS_400.
Click on STATUS_400. Click Yes on the pop-up.
31
Menu Painter
Enter description and choose the status type as Normal screen which is
default.
32
Menu Painter
Click on
to expand the menu bar, application toolbar and function
keys.
System and Help are default in menu bar
33
To create a user defined menu enter the name of the menu and double
click on it. We can define options for the menu here as below,
34
Application tool bar can also be created in same way as menu bar.
35
36
Execution
We can test the menu painter by clicking on F8 key or execute button
Enter a screen number and title if you want to simulate a whole screen. If
you do not enter a screen number, the system simulates the status using
an empty test screen.
37
Execution
Output as below, New Menu is added, Find Item in Application tool bar,
Save, Back & Print button on standard tool bar enabled.
38
Flow logic refers to code behind the screens. It is the code that
processes a screen.
Flow Logic commands are different than ABAP commands
(e.g., IF ENDIF is not valid in Flow Logic).
Dynamic Processor (DYNPRO) controls the flow logic and prepares data
to be displayed on the screen.
39
is displayed.
PROCESS AFTER INPUT (PAI) - event processed after the user has
40
Keywords supported
Keywords supported by flow logic events are as below,
Keyword
Function
MODULE
FIELD
ON
VALUES
CHAIN
ENDCHAIN
CALL
LOOP
ENDLOOP
41
PBO Event
By default the module created in PBO event will be like
MODULE STATUS_<screen number>
Ex:-MODULE STATUS_0100.
This module will be processed before the screen is displayed.
By default this module will be commented. To use this uncomment and
double click on it to get the module created.
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
module STATUS_0100 output.
*
42
PBO Event
Menu bar and title bar can be set in this module.
Menu BarTo set menu bar uncomment the SET PF_STATUS and give a name to status
as ,
SET PF-STATUS 'STATUS100'.
Double click on STATUS100 and click yes to create GUI status.
43
PBO Event
Title Bar
To assign a title uncomment SET TITLEBAR and give a name as,
SET TITLEBAR 'TITLE100'.
Double click on TITLE100 and click yes to create GUI title. Enter title as
below and click on
, save and activate.
Once all the modules in the PBO block are processed, the system copies
the content of the fields in the ABAP work area to their corresponding
fields in the screen work area.
44
PAI Event
Default module in PAI event will be
MODULE USER_COMMAND_<screen number>.
Ex:- MODULE USER_COMMAND_0100.
This event is triggered once the user invokes function code or presses
Enter key on the screen.
System variable SY-UCOMM will hold the function code assigned to the
screen elements (push button, radio button, check box etc).
Within the above module code has to written to branch to group of code
based on the function code from SY-UCOMM.
The system copies the contents of the fields in the screen work area to
their corresponding fields in the ABAP work area once user clicks Enter
key on screen or any function code is invoked.
45
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'ENT'.
SELECT ebeln ebelp bukrs
INTO CORRESPONDING FIELDS OF TABLE it_po
FROM ekpo
WHERE ebeln = po_no.
WHEN 'BCK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE.
46
Includes
47
Includes
To create include right click on object name, select Include from the
Create menu.
48
Includes
We can gave the include names as Z<Program>_TOP, Z<Program>_PBO,
Z<Program>_PAI. This will help to understand which modules are
covered in each include.
Each include program will insert a include statement in the main
program.
49
Message Statement
50
Message Types
S:success
I: information
A: abend
X: exit
W: warning
E: error
51
Messages
52
Messages
Abend message is displayed on the current screen in a dialog box.
The user cannot make any changes to the values on the current screen.
After pressing the Enter key on the dialog box, transaction will be
terminated.
Exit message is identical to the ABEND message except that the transaction
is terminated with a short dump instead of the message in a dialog box.
WARNING message is displayed at the bottom of the current screen.
On pressing the Enter key on the current screen, the user will be taken to
the next screen even if no changes were made on the current screen . Thus
user is not restricted from going on to the next screen.
53
Messages
54
55
56
57
The Flow Logic VALUES statement defines a set of valid values for the
screen field specified in the FIELD statement.
If the value entered in this field is not in the valid set, an error message
will be issued by the system.
PROCESS AFTER INPUT.
field PO_NO values ('1', '100').
This indicates PO_NO can take input as either 1 or 100. For any other
value system will through error and the field will be open for input.
With VALUES parameter for field, we can get a list of possible values by
clicking on the drop-down arrow of the screen fields or pressing the F4
key. It will list the values mentioned.
58
Values option
PO_NO with values 1 and 100.
59
CHAIN Statement
To keep multiple screen fields open for input after an error or warning
message is displayed, you need to use the CHAIN and ENDCHAIN
Flow Logic commands.
These statements group the FIELD statements and the MODULE
statements together.
The basic syntax of these statements is:
CHAIN.
FIELD: <f1>, <f 2>,...
MODULE <mod1>.
MODULE <mod2>.
...
ENDCHAIN.
If an error or warning message is issued in <module name>, all the
screen fields listed in the FIELD statements will be open for input.
60
Cursor Position
By default, the cursor will be positioned in the first field open for input
on a screen.
Cursor position can be changed in two ways
1. By setting the cursor position in PBO eventSyntax - SET CURSOR FIELD <field name>
Cursor will be placed on the screen field mentioned.
2. Cursor position in screen attributesMention the field name where cursor to be placed on screen
cursor position attribute .
in
61
Screen commands
The LEAVE SCREEN statement ends the current screen and calls the
subsequent screen.
When the system encounters the SET SCREEN <screen #> ABAP
statement, it temporarily overrides the Next Screen attribute with this
<screen #> and the PAI processing continues. After all PAI modules are
executed, the system goes to the PBO event of
<screen #>.
62
Screen commands
63
All modules listed in the PAI event get executed from top to bottom.
We can control the execution of the modules using additions to MODULE.
Additions are,
ON INPUT
ON REQUEST
AT EXIT-COMMAND
AT CURSOR-SELECTION
64
ON INPUT
With the ON INPUT addition to the MODULE statement, a module will be
executed only if the specified fields value is not equal to the initial value
appropriate to its data type
Ex- blanks for character fields and zeroes for numeric fields.
The basic syntax for this conditional execution Flow Logic command is:
65
ON REQUEST
With the ON REQUEST, a module will be executed only if a value has been
entered in the specified field since the screen was displayed.
The basic syntax for this conditional execution Flow Logic command is:
66
AT EXIT-COMMAND
67
AT EXIT-COMMAND
used with a
FIELD statement.
If the user invokes a type E function code, a module with the AT EXITCOMMAND addition will be executed immediately.
It will be executed even before the automatic field checks.
68
69
AT CURSOR-SELECTION
You can specify that a module should only be called if the cursor is
positioned on a particular screen element.
Syntax - MODULE <mod> AT CURSOR-SELECTION.
The module <mod> is called whenever the function code of the user
action is CS with function type S.
The module is called in the sequence in which it occurs in the flow logic.
It does not bypass the automatic input checks.
70
AT CURSOR-SELECTION
You can also combine this MODULE statement with the FIELD statement:
FIELD <f> MODULE <mod> AT CURSOR-SELECTION.
For more than one field:
CHAIN.
FIELD: <f1>, <f 2>,...
MODULE <mod> AT CURSOR-SELECTION.
ENDCHAIN.
71
All fields of the current screen are stored in the system table SCREEN
with their attributes.
The LOOP AT SCREEN statement places this information in the header line
of the system table.
We can modify the attributes of the fields and update the screen table
using MODIFY SCREEN.
Sample code:
loop at screen.
if screen-name = 'GV_MATNR'.
screen-input = 1.
modify screen.
endif.
endloop.
72
ACTIVE
REQUIRED
INPUT
OUTPUT
INTENSIFIED
INVISIBLE
LENGTH
DISPLAY 3D
VALUE HELP
A field attribute is turned on with a value of 1. It is turned off with a
value of 0.
The statements LOOP AT SCREEN ... ENDLOOP define a loop around a
statement block.
73
Screen
1
Screen
2
Screen
3
SELECT A
SELECT B
UPDATE A
DELETE B
Database
Transaction
Database
Transaction
Database
Transaction
74
LUW
75
LUW
76
SAP Locks
R/3 system contain lock mechanism for SAP LUWs called SAP Locks.
Lock object is created in ABAP Dictionary.
A lock object definition contains the database tables and their key fields
on the basis of which you want to set a lock.
System automatically generates two function modules with the names
ENQUEUE_<lock object name> and DEQUEUE_<lock object name> when a
lock is generated.
Locks can be set and released on corresponding database table by calling
these function modules in program.
77
SAP Locks
Consider below example,
When user clicks on change, the program locks the relevant database
object by calling the corresponding ENQUEUE function.
You can release the lock by calling DEQUEUE function when user clicks on
SAVE or when user clicks on BACK button.
78
Table Control
A table control is an area on the screen where the system displays data in
a tabular form. It is processed using a loop.
To create a table control, drag & drop table control from screen elements
on screen painter. Give a name to table control.
Select the table definition and fields clicking on Dictionary/Program fields
object button.
Each table control need to be declared in declaration part of the program
as,
CONTROLS <ctrl> TYPE TABLEVIEW USING SCREEN <scr>.
where <ctrl> is the name of the table control on a screen.
79
Table Control
You must code a LOOP statement in both the PBO and PAI events for each
table in your screen.
This is because the LOOP statement causes the screen fields to be copied
back and forth between the ABAP program and the screen field.
80
Table Control
81
82
Tab Title Title of the component to which user can navigate. They are
push buttons.
83
84
Step loops
85
86
Step loops
To use a Step-Loop block in an online program, you must create one work
area for the Step-Loop block. To hold all the lines of a Step-Loop block in
the programs memory area, use an internal table.
Ex:-TYPES: BEGIN OF TY_REC,
MATNR TTPE MARA-MATNR,
MATKL TYPE MARA-MATKL,
END OF TY_REC.
DATA: GT_MARA TYPE TABLE OF TY_REC WITH
HEADER LINE.
For Step loop the flow logic statement loop must be coded in both PBO and
PAI event. One form of the Flow Logic LOOP statement is;
LOOP.
. . . <flow logic statements> . . .
ENDLOOP.
87
Subscreen
A subscreen is a screen that is displayed in a specified area of the main
screen.
A subscreen cannot be displayed by itself.
The subscreen displayed in the predefined area will depend on the users
request on the main screen.
Subscreen is used to vary the fields displayed on a screen. As an example:
information.
Another subscreen contains customer bank
information.
88
Creating Subscreen
In main screen,
subscreen on layout.
You can set the length and width of the subscreen
by double clicking on subscreen.
Provide unique name to subscreen, save and
activate it.
Subscreen
89
Creating Subscreen
Create a subscreen
screen.
90
Creating Subscreen
User can design in the subscreen area as below,
91
92
93
The CALL SUBSCREEN statement must be used to invoke the PAI event
of the subscreen.
94
If the subscreen does not contain any PAI code, this CALL SUBSCREEN
statement is not needed in the PAI event of the main screen.
In both the PBO and PAI of the main screen, the CALL SUBSCREEN
statement cannot be used inside a LOOP or a CHAIN.
95
96
Subscreen Restrictions
SET PF-STATUS
SET TITLEBAR
SET SCREEN
LEAVE TO SCREEN
CALL SCREEN
Note: These ABAP/4 statements in a subscreen
97
98
Process on Help
99
Process on Value
This event is a user-programmed help that occurs when the user presses
F4 with the cursor positioned on a screen field.
The modules specified in the subsequent FIELD statement is called instead
of the SAP help.
Syntax is:
FIELD <screen field> MODULE <module>.
100
PrepareMe
Syntax Description
Demonstration
Exercises
HelpMe
101
Demonstration
Please refer the attached document for demo example.
102
Introduction
Syntax Description
Demonstration
Exercises
HelpMe
103
Exercises
Exercise 2 This covers tab strip, subscreen, table control, 4 flow logic
events, screen navigation, menu painter.
104
Introduction
Syntax Description
Demonstration
Exercises
HelpMe
105
HelpMe
Refer help.sap.com
Refer Transaction code ABAPDOCU (check in drop down ABAP User Dialogs)
for documentation and examples
For screen elements and controls (table control, tabstrip) refer transaction
BIBS.
Refer package SLIS for examples of ALV grids, ALV Tree.
106