Professional Documents
Culture Documents
SAP AG
Chapter 12 Objectives
SAP AG
The Main Components of a Dialog Program
Development environm ent
SAP AG
You use the Screen Painter and the Menu Painter to create and design screen templates and screen
programs.
You define the processing logic in an ABAP/4 program (module pool).
Data structures are defined in the ABAP/4 Dictionary. You can access these structures from the
ABAP/4 program and when defining screen fields.
The dialog processor controls the flow of your dialog program.
Screen Painter ABAP/4
Screen
Painter
Screen Screen Field
attributes layout attributes Flow logic
Screen no. 100 PROCESS BEFORE OUTPUT.
NUM BER
Short text Test Num ber: MODULE INIT.
CHA R
Screen type Normal
10 characters
Next screen 200
Input x PROCESS AFTER INPUT.
...
... MODULE READ.
ABAP/4
SAP AG
II D
DEEN
N TT II C
CAA LL N
NAAM
MEES
S
SAP AG
The screen flow logic is divided into two events for each screen:
The PROCESS BEFORE OUTPUT event (PBO) is executed before the screen is displayed.
The PROCESS AFTER INPUT event (PAI) is executed after the user has pressed ENTER.
The system processes the modules in an event sequentially.
In each module, control passes from the dialog processor to the ABAP/4 processor. After processing,
control is returned to the dialog processor.
When all the PBO modules have been processed, the contents of fields in the ABAP/4 work area are
copied to the identically named fields in the screen work area.
Before the PAI module is processed, the contents of fields in the screen work area are copied to the
identically named fields in the ABAP/4 work area.
Overview: Creating a Dialog Program
Airline carrier LH
...
Planned flight
From FRANKFURT
To NEW YORK
Tim e 08:24:00
...
SAP AG
In the following, we are going to create a dialog program which displays a planned flight connection.
On the first screen, the user can enter the key of the planned flight connection. On the second screen,
the system displays the contents of the corresponding entry in table SPFLI.
Creating Programs
Development class Edit
Program
Functional area
Local private objects
Create
Programs
..
.
Choose
Program SAPMTALA
with TOP Include
SAP AG
Create your program (ABAP/4 module pool) in the ABAP/4 Development Workbench.
The TOP include program initially includes just the PROGRAM statement. To this, you add all the
data declarations (global data).
If you are using includes, the system proposes names formulated according to a particular rule. The
first three bytes of the ABAP/4 module pool name are removed and the string starting from the fourth
byte is moved three bytes to the left. In the three free bytes at the end, the system then adds characters
which are appropriate for the include.
Example: The name of the TOP include for the ABAP/4 module pool SAPMTALA is MTALATOP.
Note:
In this chapter, create all of your objects as local private objects
Program Attributes
Title
Test
Type M
Application S
Save
SAP AG
In the program attributes, you maintain the title, the program type and the application. For program
type, enter the value M (module pool). Select S (Basis Component) as the application.
Defining Screens
programs
SAPMTALA
Create ..
.
screens
..
.
Create the relevant screens for your module pool from the object list.
After you have entered the screen number, the system branches to the screen attribute maintenance.
Enter a short description, select the screen type Normal and specify the number of the follow-up
screen
Using ABAP/4 Dictionary Fields
Fullscreen Dict/ProgFields
Dict/ProgFields
Key word
- short
- m edium
- long
- header
Copy
SAP AG
Generally, you define screen fields by using existing ABAP/4 Dictionary field attributes.
You can also use field attributes already stored in the module pool. To do this, a generated version of
the module pool must exist.
You can copy the field texts and the output templates individually or together.
Screen Layout (Graphical Screen Painter)
Field
Field attr.
attr. Dict./prog.fields
Dict./prog.fields Field
Field list
list
Text
Text
Entry
Entry
Check
Check
Airline carrier
Radio
Radio
Connection number
Box
Box
SAP AG
SAP AG
The alphanumeric Screen Painter provides the same functionality as the graphical Screen Painter to
design the layout of your screens.
In the alphanumeric fullscreen editor, you enter underscores for input/output fields.
For radio buttons and checkboxes, you first define an one-byte long input/output field and then enter
a field text.
After maintaining the field list, you define both fields as a graphical element.
To create a group box, enter a title and then choose a graphical element and a group box.
Field List Views
Matchcode/reference
Modification groups
Display attributes
General attributes
Texts/templates
Field types
SPFLI-CARRID
SPFLI-CARRID
.
.
.
SAP AG
There are six field list views available for maintaining the screen field attributes. Alternatively, you
can define them from one of the lists. Attribute maintenance for one field is also possible in the
fullscreen editor.
In the Screen Painter, you use external data types. The external data types of fields that you select
from the ABAP/4 Dictionary are displayed in the Format column. In the case of fields (templates)
that do not have any ABAP/4 Dictionary reference, you define an external data type yourself.
You can find out the correspondence of external data types to internal data types (i.e. ABAP/4 data
types) by referring to the documentation on the ABAP/4 key word TABLES. Examples are as follows:
CHAR C
NUMC N
Field Attributes
Field attributes
Graph. type
Field name
.
.
.
Dict. attributes
Program attributes
Display attributes
SAP AG
You can also maintain the attributes of your screen fields from the Screen Painter by selecting a field
and then choosing the Attributes function.
Defining the Flow Control
Screen
Painter
PROCESS BEFORE OUTPUT.
MODULE INITIALIZE.
SAP AG
Screen 200
SAP AG
For screens with a similar structure, you can copy an existing screen and, if necessary, modify it (e.g.
layout, flow logic).
To do this, you work in the ABAP/4 Development Workbench by positioning the cursor on the screen
you want to copy (usually the object) and choose the Copy function.
When you have successfully copied the screen, the system displays the screen as a new sub-object of
the module pool and you can edit it.
Defining Fields in the Module Pool
Top include
ABAP/4
MTALATOP
PROGRAM SAPMTALA.
TABLES: SPFLI.
DATA: ... .
OR
Global data
ABAP/4
DATA: ... .
SAP AG
In dialog processing, data is passed between the screens and the ABAP/4 program at runtime. The
system performs this communication automatically, but you must use identical names in the screens
and the module pool.
Define the relevant fields as global data in the TOP include program. To do this, you process either
the TOP include program as a whole or the sections concerning global data or Dictionary structures.
Even then, the TOP include program is still implicitly in control.
Creating ABAP/4 Modules
Create Create
.. ..
. .
PBO modules PAI modules
.. ..
. .
Choose Choose
SAP AG
When creating PBO and/or PAI modules, you can assign them to an include or the main program via
a dialog box. Normally, the system automatically assigns your PBO modules to the include program
xxxxxI01.
Processing in the Module Pool
ABAP/4
MODULE INITIALIZE OUTPUT.
CLEAR SPFLI.
ENDMODULE.
ABAP/4
MODULE READ_SPFLI INPUT.
SELECT SINGLE * FROM SPFLI
WHERE CARRID = SPFLI-CARRID
AND CONNID = SPFLI-CONNID.
.
.
.
ENDMODULE.
SAP AG
The ABAP/4 MODULE statements for PBO modules contain the addition OUTPUT, while the
MODULE statements for PAI modules contain the addition INPUT.
Defining Calls (Transaction Codes)
Programs
SAPMTALA
Create ..
.
Transactions
..
.
SAP AG
You can start an ABAP/4 dialog program ("transaction") by specifying a transaction code.
Customer transactions must begin with Z or Y.
The system stores your specifications in the table TSTC. (Instead of creating a transaction from the
object list, you can maintain the table itself.)
Action Sequence
Screen Action sequence
PROCESS BEFORE OUTPUT. Pain ter
MODULE A. Execute module A
Send screen
ENTER
Execute module B
SAP AG
When all the PBO modules have been processed, the data of identically named fields is transported
from the module pool work area to the screeen work area.-
Before the PAI modules are executed, the data of identically named fields is usually transported from
the screen work area to the module pool work area.
Field Format Checking
Screen
Pain ter
Field list
DATE DATS
.
.
.
Amount DEC
SAP AG
The dialog processor checks the input against the format attributes of the relevant field.
If the system detects an incorrect input value, it displays an error message and makes the field ready
for input again.
Obligatory Field
Screen
Pain ter
Field list
PLANETYPE X
SAP AG
Screen
Painter
Field list Check table P1
Field Foreign key PFELD
FELD1 X A
B
C
.
.
.
Feld1 C
SAP AG
Foreign key checking involves the system comparing the value entered in a screen field against a set
of values. If the entered value is not found in the set of values, the system displays an error message
and makes the corresponding field ready for input again.
Here the following requirements apply:
- The screen field is a field in an ABAP/4 Dictionary table (foreign key table).
- The table against which the value is checked (known as the check table) is also defined in the
ABAP/4
Dictionary.
- The foreign key table and the check table are assigned to the same domain.
- The check table is assigned to this domain as a value table.
- The value table becomes the check table by through the definition of a foreign key between the
foreign
key field and the check table field in the ABAP/4 Dictionary.
- The check table field must be the key field of the check table.
You can also perform foreign key checking against check tables with several key fields.
You can display the contents of the check table by placing the cursor on the screen field and pressing
F4.
By pressing F1, you can display the documentation defined at data element level.
Input Checking in the Module Pool
Screen
PROCESS AFTER INPUT. Painter MODULE <module> INPUT. ABAP/4
FIELD <screen field> .
.
MODULE <module>. .
MESSAGE E ... .
ENDMODULE.
1 1
E... m essage
SAP AG
If you want to check input values in the module pool and include an error dialog following a negative
check result, use the MODULE parameter with the FIELD statement. You also have to define an error
or warning message in the module pool.
Please note that only the FIELD statement is responsible for modifying the status of a field to make it
ready for input again:
If you define a message in the module pool, but do not call the module within a FIELD statement, the
system sends the message, but the fields are not ready for input.
FIELD Statement and Data Transport
A ENTER
Screen
PROCESS AFTER INPUT. Painter c
Data transport for all
MODULE A. t fields other than X, Y
FIELD X MODULE B.
FIELD Y MODULE C. i from the screen to the
ABAP/4 work area
MODULE D. o
n
Execute module A
u
Data transport for Y
e
n Execute module C
c
e Execute module D
SAP AG
In the PAI module, screen fields are transported to identically named ABAP/4 fields. Fields not
defined in FIELD statements are transported first. All the other fields are copied only when the
relevant FIELD statements have been processed.
Setting the Next Screen Dynamically
Screen Screen
Painter Painter
Screen attributes Screen attributes
Screen Screen
Painter Painter
PROCESS
PROCESS AFTER
AFTER INPUT.
INPUT. PROCESS
PROCESS BEFORE
BEFORE OUTPUT
OUTPUT
MODULE ..
MODULE OK_CODE.
OK_CODE. ..
..
ABAP/4
MODULE OK_CODE INPUT.
.
. PROCESS
PROCESS AFTER
AFTER INPUT.
INPUT.
. ..
SET SCREEN 200. ..
..
LEAVE SCREEN.
SAP AG
If the functions in your dialog program require a different control process, you can control the screen
sequence dynamically using the SET SCREEN statement.
The statement SET SCREEN nnnn temporarily overwrites the follow-up screen.
Screen nnnn must be a screen from the same module pool.
When the current screen has been processed, the system processes the follow-up screen unless you
cancel the current screen process with LEAVE SCREEN.
You can also use the CALL SCREEN statement for dynamic screen sequence control. Here, you can
insert a screen sequence and then either return to the original call location after this has been
executed or call a screen defined as a modal dialog box. The CALL SCREEN statement is not
covered in this course.
Reading Function Codes in Programs
Screen
Pain ter
PROCESS AFTER INPUT.
.
.
.
Screen MODULE USER_COMMAND.
Pain ter
Display
ABAP/4
DATA: OKCODE(4),
SAVE_OKCODE(4).
SAP AG
You define pushbuttons to enable the user to choose specific functions. When the user presses a
pushbutton, the PAI event is triggered.
You also assign a function code to each pushbutton.
When the user chooses a function, the function code is in the field you have defined in the field list
with the attributes length 5 and format OK.
To be able to react to a function code in the ABAP/4 module pool, you define an identically named
OKCODE field. This contains the current function code after the field has been transported.
You are recommended to use a backup version of the OKCODE field to avoid sending a screen that
already has a function code.
Menu Painter: Overview
Title bar
M enu bar
Standard toolbar
Application toolbar
SAP AG
You use the Menu Painter to define functions on a screen in a particular status and assign them to the
appropriate menu bar, standard toolbar and application toolbar.
You also define the title.
In general, you define a menu bar for each dialog program and assign it to a status. For each status,
you define which menu functions are to be active/inactive.
All the statuses of a dialog program make up the user interface. If you add a new status, you have to
regenerate the interface.
You assign a status and a title to a screen in the appropriate PBO module using the SET PF-STATUS
and SET TITLEBAR statements respectively. The status can be up to 8 characters long, while the
title code should consist of no more than 3 characters.
GUI Title
SAPMTALA
Create
..
.
GUI title
..
.
Choose
Create title
Title code 001
Continue
Program SAPMTALA
Maint. language ENGLISH
Title code 001
Title
Test dialog program
SAP AG
You can create and/or maintain a title either from the object list or from a GUI status.
To set a title in a PBO module, you use the statement SET TITLEBAR <code> WITH <value1>
<value2> ... <valuen>. The contents of <code> can be up to three characters long. The system
replaces & placeholders in the title with the contents of <value1>....<valuen>.
Once a title is set, it remains valid until you set a new title.
The system field SY-TITLE contains the current screen title.
GUI Status
SAPMTALA
Create
..
.
GUI status
..
.
Choose
Create status
Program SAPMTALA
Status STAT1
Continue
..
.
Short desc. Test status
Status type
- screen
- dialog box
- list
- list in dialog box
SAP AG
You can define one or more statuses for a screen. A status defines which functions the user can
choose and whether they can be selected via the menu bar or standard toolbar, or by pressing function
keys or pushbuttons.
To set a status in a PBO module, you use the statement SET PF-STATUS <status>. The contents of
<status> can have up to eight characters.
By using the EXCLUDING parameter with the SET PF-STATUS statement, you can deactivate the
functions of the current status which were defined as active in the Menu Painter.
Once a status is set, it remains valid until you set a new status.
The system field SY-PFKEY contains the current status.
By choosing a status type, you determine whether the status is to refer to a normal screen or a list.
The system offers different functions for each status type.
Defining the Interface I
Menu bar
- Hide standards
F key assignment
SAP AG
On request, the system proposes default values for the menu bar and the function key setting, but you
can modify these.
Menu bars can contain up to eight menus. You can define up to six of these yourself, but the System
and Help menus are added automatically by the system.
A single menu can contain up to 15 entries, including the functions and their descriptions, sub-menu
names and separator lines.
You should also specify all the functions that are active in a status as active in the menu bar (SAP
ergonomic standard).
Defining the Interface II
Standard toolbar
...
Application toolbar
...
SAP AG
You assign the active functions that a user is most likely to need in the current status to the
application toolbar. Before you can do this, the function code must be assigned to a function key.
You assign function codes to function keys by entering them in the Recommended function key
settings or the Freely assigned function keys sections.
The system automatically assigns the functions in the standard toolbar to special function keys (see
next page).
Chapter 12 Summ ary
SAP AG BC400 / 12 - 1
Exercises Chapter 12: Introduction to Dialog Programming
Schluessel Flugdaten
Fluggesellschaft
Airline carrier ___
Verbindungs-Nummer
Connection number____
Datum des date
Flight Fluges __________
b) Screen 200
Airline carrier
Connection number
Flight date
Flight information
FlgtPrice
Local currency
Plane type
Maximum capacity
Occupied seats
2. Program name: SAPMZ##2
Transaction code: Z##2
Development class: $TMP
Screens 100 Follow-up screen 100
200 Follow-up screen 200
## Group number
Copy your program SAPMZ##1 or the example solution
SAPMTAL1 and add the following functionality:
- The key fields of table SFLIGHT should be defined as
required fields. In addition, they should be used to transfer
data to the SPA/GPA Memory and/or provided with data
from the SPA/GPA Memory.
- If invalid values are entered in the key fields, you should
display an error dialog message on the first screen and make
the field Date of flight ready for input again. Use message
class.
- Changing screens should only be possible by pressing the
appropriate pushbutton (see example).
a) Screen 100
Schluessel Flugdaten
Display
Fluggesellschaft
Airline ___
Verbindungs-Nummer
Connection number____
Datum desofFluges
Date flight __________
b) Screen 200
Back
Airline
Connection number
Date of flight
Flight information
FlgtPrice
Local currency
Plane type
Maximum capacity
Occupied seats
3. Program name: SAPMZ##3
Transaction code: Z##3
Development class: $TMP
Screens 100 Follow-up screen 100
200 Follow-up screen 200
## Group number
Copy your program SAPMZ##2 or the example solution
SAPMTAL2 and modify the copy as follows:
- The dialog program should have a GUI title.
- Define one GUI status. When the transaction is executed,
only the relevant function is to be active (see example).
- On the first screen, implement the Display function as an
icon in the standard toolbar (cf. example).
Note:
When defining the status, use the system standards.
Examples
a) Screen 100
b) Screen 200
1. Exercise 1
*&---------------------------------------------------------------*
*&---------------------------------------------------------------*
* Screen 100
MODULE INITIALIZE.
MODULE READ_SFLIGHT.
*&---------------------------------------------------------------*
*&---------------------------------------------------------------*
PROGRAM SAPMTAL1.
TABLES SFLIGHT.
*&---------------------------------------------------------------*
*&---------------------------------------------------------------*
CLEAR SFLIGHT.
*&---------------------------------------------------------------*
*&------------------------------------------------------------*
* Screen 100
MODULE INITIALIZE.
MODULE USER_COMMAND_0100.
* Screen 200
MODULE USER_COMMAND_0100.
*&------------------------------------------------------*
*&------------------------------------------------------*
TABLES SFLIGHT.
DATA: OKCODE(4).
*&------------------------------------------------------*
*&------------------------------------------------------*
*&------------------------------------------------------*
IF SY-SUBRC NE 0.
CLEAR OKCODE.
MESSAGE E007.
ENDIF.
*&---------------------------------------------------------------*
*&---------------------------------------------------------------*
CASE SY-DYNNR.
WHEN 100.
IF OKCODE = 'MORE'.
ENDIF.
WHEN 200.
IF OKCODE = 'BACK'.
ENDIF.
ENDCASE.
*&--------------------------------------------------------
* Screen 100
MODULE STATUS_100.
MODULE INITIALIZE.
MODULE USER_COMMAND_0100.
* Screen 200
MODULE STATUS_100.
MODULE USER_COMMAND_0100.
*&---------------------------------------------------------------*
*&---------------------------------------------------------------*
CASE SY-DYNNR.
WHEN 100.
WHEN 200.
ENDCASE.