Professional Documents
Culture Documents
Module Pool Programming: by - Sudhir Kumar
Module Pool Programming: by - Sudhir Kumar
By – SUDHIR KUMAR
Module pool programming
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 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 :
3
Use
format and consistency checks for the data entered by the user.
4
Module pool programming
1 PrepareMe
2 Syntax description
3 Demonstration
4 Exercises
5 HelpMe
5
Developing Module pool Program
Tools used:
ABAP Editor(SE38) – To maintain main ABAP program. Program contains data declarations
and modules.
Object Navigator (Repository Browser)(SE80) - You should always use the object navigator for
online programs because you will be able to see the hierarchy. From this hierarchy list, you will
be able to branch to the Screen Painter, ABAP Editor, Menu Painter, and ABAP Dictionary.
6
Creating a Program
7
Program Structure
Module pool program when viewed from SE80 transaction will have structure
as below,
8
Assigning transaction code
Dialog program is executed using transaction code. We can not execute this
like normal report using execute or pressing F8 button.
Transaction is created using SE93 transaction or from object browser by right
clicking on transaction, click on create. Give name and description and select
the radio button Program and screen (dialog transaction)
9
Use of Screen
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
To start the Screen Painter, choose the corresponding pushbutton on the initial
screen of the ABAP Workbench or enter Transaction SE51.
Best practice is to go to transaction SE80, enter program name and you can
perform one of the below,
11
Developing Screen
12
Developing Screen
13
Developing Screen
14
Screen Attributes
15
Screen Attributes
Screen Type –
Normal – Default setting
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.
Line/Columns –
Occupied – Specifies the size of the screen area currently occupied with
screen elements
Maintained – Size of the screen in rows/columns.
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
Screen Layout Mode
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.
Both modes offer the same functions but use different interfaces. Graphical
mode of screen designing is commonly used.
19
Screen Designing
20
Components of Layout Editor
Element palette – Used for creating screen elements. These can be drag &
dropped on screen.
Element bar – screen element attributes appear in this line. You can also
change these attributes in the corresponding field.
21
Screen Components
22
Screen Elements
Check box Each element will have its position on screen, visible/definite length, mode
of display etc.
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
In all programs GUI consists of a menu bar, a standard toolbar, an application
toolbar and title bar.
A program’s GUI is created in Menu Painter.
To Create a Menu for a screen, in flow logic uncomment MODULE
STATUS_0400. in PBO event
29
Menu Painter
Now double click on STATUS_0400. A pop up window will appear. Click on Yes.
30
Menu Painter
Uncomment the line SET PF-STATUS 'xxxxxxxx'. a nd replace 'xxxxxxxx‘ with name
‘STATUS_400’.
31
Menu Painter
Enter description and choose the status type as Normal screen which is
default.
32
Menu Painter
33
Creating Menu bar
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
Creating Application Tool bar
Application tool bar can also be created in same way as menu bar.
35
Assigning function keys
We can assign code to existing function keys. Only keys for which code is
assigned will be active. We can see this when the menu painter is executed.
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
More on Flow Logic
Flow logic refers to code behind the screens. It is the code that processes a
screen.
Dynamic Processor (DYNPRO) controls the flow logic and prepares data to be
displayed on the screen.
39
More on Flow Logic
Each screen has its own Flow Logic which is divided into four main events:
• PROCESS BEFORE OUTPUT (PBO) - event processed before the screen
is displayed.
• PROCESS AFTER INPUT (PAI) - event processed after the user has
invoked a function code (e.g., clicked on a pushbutton) or pressed the
‘Enter’ key.
• Process on Value Request (POV) - Triggered when the user requests field
help (F1)
Each screen must be generated. If you make a change to any component of a
screen, the screen must be re-generated before execution.
40
Keywords supported
Keyword Function
41
PBO Event
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
*&---------------------------------------------------------------------*
module STATUS_0100 output.
* SET PF-STATUS ‘XXX'.
* SET TITLEBAR 'xxx'.
endmodule. " STATUS_0100 OUTPUT
42
PBO Event
Menu Bar-
To set menu bar uncomment the SET PF_STATUS and give a name to status as ,
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
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
PAI Event- Sample Code
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
CASE sy-ucomm.
WHEN 'ENT'.
WHEN 'BCK'.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
46
Includes
There should be a TOP include which will have the data declarations.
47
Includes
To create include right click on object name, select Include from the Create
menu.
48
Includes
Each include program will insert a include statement in the main program.
49
Message Statement
t – Message type
nnn –Message Number
WITH – This is optional. It is needed if variables are used in a message.
A message can contain up to four variables, indicated with an ampersand (&)
in the message text.
50
Message Types
S:success
I
I: information
A: abend
X: exit
W: warning
E: error X
The message type determines where the message is displayed and what
action the user can or must take on the current screen.
51
Messages
If you have next screen then the message will be displayed at the bottom of
the next screen.
After pressing Enter key on dialog box user will be taken to next screen. The
user is not restricted from going on to the next screen.
52
Messages
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.
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
The user must make changes to the values on the current screen.
On pressing the ‘Enter’ key on the current screen, the user will be taken to the
next screen only if the appropriate corrections were made on the current
screen.
If no corrections were made, the error message would be redisplayed at the
bottom of the current screen.
When a warning or error message is triggered the system will stop at current
screen, prompting the user to make corrections. However the input fields on
the screen will be disabled for input.
54
Handling Error messages
The purpose of the “FIELD” statement is to keep a single screen field open for
input after an error or warning message is issued.
55
FIELD with select statement
56
Error for invalid input
57
FIELD with Values Check
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
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>.
FIELD: <g1>, <g 2>,...
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 event-
Syntax - SET CURSOR FIELD <field name>
Cursor will be placed on the screen field mentioned.
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
More on PAI modules
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 field’s 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:
− FIELD <screen field> MODULE <module> ON INPUT.
− The PAI <module> will be executed only if the value in
<screen field> is not equal to its initial value.
− The “ON INPUT” addition must be used with a “FIELD”
statement because this condition depends on the value of
a particular field.
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
The basic syntax for this conditional execution Flow Logic command is:
67
AT EXIT-COMMAND
If the user invokes a type ‘E’ function code, a module with the “AT EXIT-
COMMAND” addition will be executed immediately.
68
Assigning Function type
69
AT CURSOR-SELECTION
You can specify that a module should only be called if the cursor is positioned
on a particular screen element.
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.
71
Modifying Screen Fields
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
Modifying Screen Fields
73
Logical Unit of Work (LUW)
Database Database
Database
Transaction Transaction
Transaction
LUW refers to a collection of actions performed at the database level as a complete
unit.
In this ex: LUW is selecting A and B from the database, updating A, and deleting B.
This would be the desired LUW because we would want to rollback all changes if any
of these actions failed.
74
LUW
Changes will be saved (commit work) in database at the end of third screen.
An SAP LUW will end with either the COMMIT WORK or ROLLBACK WORK
statement.
A logical unit consisting of dialog steps, whose changes are written to the
database in a single database LUW is called an SAP LUW.
If an SAP LUW contains database changes, you should either write all of them
or none at all to the database.
Include a database commit when the transaction has ended successfully, and
a database rollback in case the program detects an error.
75
LUW
In our example, we need to perform UPDATE A and DELETE B at the end of
third screen.
76
SAP Locks
R/3 system contain lock mechanism for SAP LUWs called SAP Locks.
A lock object definition contains the database tables and their key fields on the
basis of which you want to set a lock.
77
SAP Locks
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.
For this reason, at least an empty LOOP...ENDLOOP must be there.
80
Table Control
Sample code -
81
Tab Strip Controls
Use –
− To give complex applications a uniform structure and
make it easier for users to navigate between their
components.
82
Tab Strip Control components
Tab Title – Title of the component to which user can navigate. They are push
buttons.
83
Tab Strip Control components
Tab Page - A tab page contains a collection of fields that logically belong
together. Tab pages are implemented using subscreens.
Tab Environment - The screen environment around the tabstrip must remain
constant. When you change between tab pages, the menus, application
toolbar, and other fields outside the tabstrip control must not change.
For designing and using tab strip controls, see Transaction BIBS .
84
Step loops
85
Creating a Step loop
In one or more lines, create the elements you want to repeat.
Your element lines now make up a single step loop block. The block includes the
original elements with their attributes and a predefined number of repetition
blocks.
The repetition blocks are consecutively numbered, so that you can establish a
reference to a particular line.
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 program’s
memory area, use an internal table.
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
The subscreen displayed in the predefined area will depend on the user’s
request on the main screen.
88
Creating Subscreen
Subscreen
89
Creating Subscreen
Create a subscreen
− Create a screen as given in earlier slides.
− Screen type should be subscreen.
90
Creating Subscreen
91
Call subscreen in PBO
To include a subscreen in a predefined area on the “main” screen, use the “CALL
SUBSCREEN” statement in the “main” screen’s PBO event.
92
Call subscreen in PBO
93
Call subscreen in PAI
If the subscreen contains any PAI code, use the “CALL SUBSCREEN”
statement in the PAI event of the “main” screen.
The “CALL SUBSCREEN” statement must be used to invoke the PAI event of
the subscreen.
- When the “CALL SUBSCREEN” statement is
encountered in the “main” screen’s PAI event, the system
executes the PAI event of the subscreen.
94
Call subscreen in PAI
In both the PBO and PAI of the “main” screen, the “CALL SUBSCREEN”
statement cannot be used inside a “LOOP” or a “CHAIN”.
95
Main screen Flow logic
96
Subscreen Restrictions
− SET PF-STATUS
− SET TITLEBAR
− SET SCREEN
− LEAVE TO SCREEN
− CALL SCREEN
97
Additions with ABAP OOPS
Enjoy SAP controls (ALV Grid , ALV Tree, HTML controls etc) can be displayed
in screen.
To place these grids we need to have screen element Custom Control placed on
the screen.
Also we need to have ABAP OOPS knowledge. ( Refer package SLIS for
examples)
98
Process on Help
If the user presses the ‘F1’ key with the cursor is positioned in <screen field>,
the <supplemental documentation> will be displayed along with the data
element’s short text and documentation.
The only other Flow Logic statement that can be used in the POH event is:
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.
Syntax is:
FIELD <screen field> MODULE <module>.
100
Module pool programming
1 PrepareMe
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
101
Demonstration
Microsoft Word
Document
102
Module pool programming
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 HelpMe
103
Exercises
Microsoft Word
Exercise 2 – This covers tab Document
strip, subscreen, table control, 4 flow logic
events, screen navigation, menu painter.
Microsoft Word
Document
104
Module pool programming
1 Introduction
2 Syntax Description
3 Demonstration
4 Exercises
5 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.
106