Professional Documents
Culture Documents
Module-Pool Programming - Complete Guide
Module-Pool Programming - Complete Guide
Syntax Description
5
India SAP CoE, Slide 2
Demonstration
Exercises
HelpMe
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 :
Standard SAP may not support that task.
A particular transaction needs to be customized to suit the customer
requirements .
A transaction (also called module pool programs, dialog programs) is
defined as a collection of screens (the actual, physical image that the users
sees), their Flow Logic (code behind the screens ), and the code within the
main ABAP program.
Program Attributes
With TOP INCL.
should be checked.
Title
Type M
Go back to Repository
Browser, not source
code.
Application
ABAP
PBO Modules
PAI Modules
Subroutines
India SAP CoE, Slide 6
An online program consists not only of the screens and their Flow Logic,
but also ABAP program components: Global data, PBO modules, PAI
modules, and subroutines.
PBO and PAI modules: It contain the main processing logic of online
program and are called from within the Flow Logic of the screens.
F8
Transaction Code
Transaction
Text
Program Name
Initial Screen
required
required
required
Syntax description
5
India SAP CoE, Slide 9
Demonstration
Exercises
HelpMe
Tools used:
When creating an module pool program, you will use many tools within
the ABAP Development Workbench: Screen Painter, ABAP Editor,
Menu Painter, ABAP Dictionary, and Repository Browser.
ABAP Editor (SE38) To maintain main ABAP program. Program
contains data declarations and modules.
IBM Global Services
Screen Painter
Repository Browser
Menu Painter
ABAP Dictionary
Slide 2
| August -2003
Tools used:
Screen Painter(SE51) used to maintain components of screen.
Menu Painter(SE41) Used to design GUI.
Maintain Transaction(SE93) To create transaction code for program.
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.
You should always use the Repository Browser to create online programs
because the system will automatically maintain an online programs subobjects and you will be able to see the hierarchy list of these sub-objects.
From this hierarchy list, you will be able to branch to the Screen Painter,
ABAP Editor, Menu Painter, and ABAP Dictionary.
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
Using screen user can provide input to program and in turn program will
display result on screen.
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.
Screen Painter
Screen Painter
Screen
Layout
Flow Logic
Field
Attributes
Developing Screen
Developing Screen
Screen numbers can be up to 4 characters long, all of which must be
digits.
The number 1000 is reserved for table screens and report selection
screen.
Screen numbers from 9000 are reserved for customer-specific screens.
The use of screen numbers is namespace-dependent.
For screens in programs in the SAP namespace, numbers less than 9000
are reserved for SAP screens, numbers between 9000 and 9500 are
reserved for SAP partners, and numbers greater than 9500 are for
customers.
Developing Screen
Developing Screen
Enter description and save.
Check the screen and activate it.
Screen Attributes
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.
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.
Screen Attributes
Settings
Switch off runtime compress On setting this option, the screen is not
compressed at runtime.
Other Attributes
Next Screen Next screen number to be displayed.
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.
Both modes offer the same functions but use different interfaces. Graphical
mode of screen designing is commonly used.
Screen Designing
screen.
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.
Radio Button
Check Box
Creating Check Box
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.
Screen Elements
Screen elements are,
Text field
Input/Output field
Check box
Radio button
Push button
Tab strip
Box
Sub screen area
Table control
Custom control
Status Icon
Screen Elements
Push Button
Can be placed on screen by drag
& drop from Element palette.
Screen Elements
Program Tab is Selected
Choose if want to Make the Field Mandatory
Tick If Input or Output Box
Entries in (*********)
Function Code for Push Buttons, check box, Radio Button
Dict. Tab is Selected
Screen Elements
Once screen is designed, it should be saved and checked for errors and activated.
Screen looks as below,
Input Box
Testing Screen
Testing Screen
Flow Logic
Menu Painter
Menu Painter
Menu Painter
Menu Painter
Enter description and choose the status type as Normal screen which is
default.
Menu Painter
Click on
to expand the menu bar, application toolbar and function
keys.
System and Help are default in 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,
Application tool bar can also be created in same way as menu bar.
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.
Execution
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.
Execution
Output as below, New Menu is added, Find Item in Application tool bar,
Save, Back & Print button on standard tool bar enabled.
Flow logic refers to code behind the screens. It is the code that processes
a screen.
Keywords supported
Function
MODULE
FIELD
ON
VALUES
CHAIN
ENDCHAIN
CALL
LOOP
ENDLOOP
PBO Event
By default the module created in PBO event will be like
MODULE STATUS_<screen number>
Ex:-MODULE STATUS_0100.
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
PBO Event
Menu Bar To set menu bar uncomment the SET PF_STATUS and give a name to
status as ,
SET PF-STATUS 'STATUS100'.
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.
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.
Includes
There should be a TOP include which will have the data declarations.
Includes
To create include right click on object name, select Include from the
Create menu.
Includes
Each include program will insert a include statement in the main program.
Message Statement
Message Types
S: success
I: information
A: abend
X: exit
W: warning
E: error
The message type determines where the message is displayed and what
action the user can or must take on the current screen.
India SAP CoE, Slide 62
Messages
Success message is displayed at the bottom of the screen.
If you have next screen then the message will be displayed at the bottom
of the next screen.
Information message is displayed in a dialog box in same 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.
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.
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.
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.
Values option
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.
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
in cursor position attribute .
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 #>.
Screen commands
LEAVE TO SCREEN <screen #> ABAP statement,
terminates the screens PAI event and immediately goes to the
PBO of <screen #>.
The LEAVE TO SCREEN <screen #> statement performs the
functionality of two statements: SET SCREEN <screen #>
and LEAVE SCREEN.
CALL SCREEN <screen #> ABAP statement, temporarily
suspends the current screens PAI processing and immediately
goes to the PBO event of <screen #>. When control returns back
to the calling screen, its PAI processing will resume.
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:
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.
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:
FIELD <screen field> MODULE <module> ON REQUEST.
The PAI <module> will be executed only if a value was entered in <screen field>
since the screen was displayed.
The ON REQUEST addition must be used with a FIELD statement because this
condition depends on the value of a particular field.
AT EXIT-COMMAND
With the AT EXIT-COMMAND addition to the MODULE
statement, a module will be executed only if the user invokes a
function code with the E function type.
AT EXIT-COMMAND
The PAI <module> will be executed only if the user invokes a
FUNCTION type E.
The AT EXIT-COMMAND addition cannot be used with a
FIELD statement.
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.
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.
Screen
2
Screen
3
SELECT A
SELECT B
UPDATE A
DELETE B
Database
Transaction
Database
Transaction
Database
Transaction
LUW
If an SAP LUW contains database changes, you should either write all
of them or none at all to the database.
LUW
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.
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.
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.
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.
Screen
Database
le
Tab
l
a
rn
Inte
er
ead
h
h
wit
Table Control
Sample code PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
LOOP AT it_po INTO wa_ekpo WITH CONTROL tab2 CURSOR
tab2-current_line.
ENDLOOP.
PROCESS AFTER INPUT.
field po_no module po_check.
module exit_mod at exit-command.
MODULE USER_COMMAND_0100.
loop at it_po.
endloop.
Subscreen
A subscreen is a screen that is displayed in a specified area of the main screen.
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:
The main screen contains the customer number, name, and a predefined
area for a subscreen.
One subscreen contains customer address information.
Another subscreen contains customer bank information.
Creating Subscreen
In main screen,
In the screen layout, place the screen element 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
Creating Subscreen
Create a subscreen
Save the subscreen and go to screen layout. Here subscreen are will
be displayed.
Creating Subscreen
If the subscreen contains any PAI code, use the CALL SUBSCREEN
statement in the PAI event of the main screen.
Subscreen Restrictions
SET PF-STATUS
SET TITLEBAR
SET SCREEN
LEAVE TO SCREEN
CALL SCREEN
Tab Page
Scrolling
For designing and using tab strip controls, see Transaction BIBS .
...
PROCESS AFTER INPUT.
...
CALL SUBSCREEN: area1,
area2,
area3,
...
PROCESS AFTER INPUT.
...
CALL SUBSCREEN area.
Activetab contains the function code of the last active tab title on the
screen.
India SAP CoE, Slide 108
Step loops
Step loops are considerable less flexible than table controls.
Used to group screen elements together. A step loop is a repeated series of
loop blocks. A loop block consists of one or more loop lines of graphical
screen elements.
Loop blocs can be defined as fixed or variable.
In a fixed loop, the lower limit of the loop area always remains as
originally defined.
For a variable loop, the number of repetitions is adjusted dynamically in
the screen program to suit the size of the current window.
The repetition blocks are consecutively numbered, so that you can establish a reference to a
particular line.
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.
Enjoy SAP controls (ALV Grid , ALV Tree, HTML controls etc) can be
displayed in screen.
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 elements short text and documentation.
The only other Flow Logic statement that can be used in the POH event
is:
FIELD <screen field> MODULE <module>.
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>.
Syntax Description
2
3
Demonstration
Exercises
5
India SAP CoE, Slide 118
HelpMe
Demonstration
Please refer the attached document for demo example.
Microsoft Word
Document
Syntax Description
2
3
Demonstration
Exercises
5
India SAP CoE, Slide 120
HelpMe
Exercises
Please refer the attached documents for hands-on.
Exercise 1 This covers input/output, radio button, table control, screen
navigation, flow logic events, Menu painter.
Microsoft Word
Document
Exercise 2 This covers tab strip, subscreen, table control, 4 flow logic
events, screen navigation, menu painter.
Microsoft Word
Document
Syntax Description
2
3
Demonstration
Exercises
5
India SAP CoE, Slide 122
HelpMe
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.