Code examples · Modern ABAP · Beginner
Dialog program (module pool): a screen with an input field, a Show button and a transaction code
The problem
Support staff want a tiny transaction ZCUST where they type a customer number, press Show and see the customer name.
How we solve it
- 1Datascreen fields
- 2PBOstatus and title
- 3PAIread the button
The result
The name appears for a known customer.
SAP objects in play
1. The requirement
Support staff want a tiny transaction ZCUST where they type a customer number, press Show and see the customer name. Back, Exit and Cancel must leave the program. An unknown customer shows a message at the bottom.
2. How we design it
A dialog program is a module pool: ABAP code that is not run by itself but by screens. Each screen has a layout, flow logic with the two events PBO (process before output) and PAI (process after input), and the program holds the modules that the flow logic calls. The function code of the pressed button arrives in the OK_CODE field. A transaction code starts the first screen.
Why we decided it this way
- 1Copy OK_CODE into SAVE_OK and clear itThe field is shared with the screen. Working on a copy avoids that an old code is processed again on the next round trip.
- 2The screen fields have the same names as the program variablesThe dynpro and the program exchange data by field name. GV_KUNNR and GV_NAME in the program are the fields of the same name on the screen.
- 3Information message shown as an errorA status message keeps the user on the screen with all input kept, while DISPLAY LIKE 'E' paints it red.
Before you start
- SE80 with a new program ZCUST_DIALOG (type: module pool).
- A GUI status ZSTATUS_0100 with the function codes SHOW, BACK, EXIT and CANC, created in the Menu Painter from the program.
3. The code, step by step
Step 1 of 3: Declare the screen fields and start the screen
Global fields that match the screen fields.
Part by part (plain text)
- Fields, OK code and the first call. GV_KUNNR is the input field and GV_NAME the output field of screen 0100. In the screen painter the same names are used, and in the Element list the OK_CODE field is named OK_CODE. CALL SCREEN 100 in the transaction's start step shows the screen. The transaction ZCUST is created with SE93 as a program-and-screen transaction pointing to the program and screen 0100.
Open in the portal
The SAP objects named in this code are linked in the code above and listed here. Each opens its page in the SAP Library.
SAP tables
Transaction codes
If it does not work
4. The final outcome
The name appears for a known customer. For an unknown one the status bar shows a red message.
What you should see
Customer 1000 -> Name: Example Customer Inc. Customer 99999999 -> status bar: Customer not found
Try it and check the result
- Activate everything (program, screen 0100, GUI status), create transaction ZCUST in SE93 and run it.
- Enter 1000 and press Show: the name appears. Enter a wrong number: a red message appears and the field keeps its value.
- Press Back: the transaction ends. Set a breakpoint in user_command_0100 to watch save_ok change.
Common mistakes
- If the OK_CODE field is not named in the element list of the screen, save_ok stays empty and no button works.
- A screen field and its program variable must have the same name and compatible type, or the data does not arrive.
- An error message (type E) in PAI blocks the whole screen. A status message with DISPLAY LIKE 'E' is friendlier, or use the FIELD statement in the flow logic to open only the wrong field for input.
- New developments in S/4HANA are usually built with Fiori or RAP, not with dialog screens. Dialog programming is still common in older code you will have to maintain.