SAP Dialog Programming
SAP Dialog Programming
SAP Dialog Programming
Dialog Programming
ABAP Training
Dialog Programming
Overview of Components
Unlike report, interface, and conversion development which generally entails the creation of one autonomous program which can be executed independently of other objects, dialog program development entails development of multiple objects, none of which can be executed on its own. Instead, all objects are linked hierarchically to the main program and are executed in a sequence dictated by the program. Dialog programs are composed of the following main components: Screens Module pool Subroutines Menus/GUI statuses Transaction codes
ABAP Training
Dialog Programming
Screen Overview
Screens are made up of the following components: Screen attributes Screen layout/screen elements Fields Flow logic Flow logic is comprised of two events: The process before output (PBO) event invokes any processing which is to occur before the screen is displayed to the user. The process after input (PAI) event invokes any processing which is to occur after the user has completed interaction with the screen by invoking any one of the possible functions (I.E. Save, back, enter, etc.).
ABAP Training
Dialog Programming
The module pool consists of modularized ABAP/4 syntax which is placed inside include programs belonging to the dialog program. These modules are invoked when called upon by flow logic. Processing of flow logic and ABAP/4 modules is handled by different processors in the SAP system. Flow logic is processed by the dialog processor while all ABAP/4 is processed by the ABAP/4 processor.
ABAP Training
Dialog Programming
ABAP Training
Dialog Programming
ABAP Training
Dialog Programming
When processing is transferred from the dialog processor (screen) to the ABAP/4 processor (module pool), the values of all screen fields must be passed to their respective ABAP/4 fields. This data transfer process must also occur when processing returns to the dialog processor form the ABAP/4 processor. In order for values to pass successfully between the dialog processor and the ABAP/4 processor, screen fields must be named identically to their respective ABAP/4 fields. In the most basic case, data transfer between the dialog processor and the ABAP/4 processor occurs at the beginning of the PBO event and immediately after the function code is invoked for the PAI event. Exceptions to this include the existence of the field statement in the flow logic or the use of a control table.
ABAP Training
Dialog Programming
ABAP Training
Dialog Programming
Dialog programs are composed of the following components: Module pool Screens Subroutines Menus/GUI statuses Transaction codes The individual components of a dialog program interact to form an executable transaction. Screens are processed by the dialog processor. Process before output (PBO) and process after input (PAI) flow logic instructions are read by the dialog processor which in turn invokes the ABAP/4 processor and passes the values of the screen fields to the identically named ABAP/4 fields. The ABAP/4 processor processes the PBO or PAI modules called by the flow logic. When completed, control is returned to the dialog processor and the values of the ABAP/4 fields are returned to the identically named screen fields. This process is repeated as necessary until all instructions have been executed.
ABAP Training
Dialog Programming
10
ABAP Training
Dialog Programming
11
ABAP Training
Dialog Programming
12
Dialog program development utilizes tools available in the ABAP workbench which are the same tools used in developing the standard SAP applications. * Dialog programs should always be developed via the object browser (SE80). When developed by the object browser, all objects become linked to the main program without having to explicitly point each object. Additionally, advanced navigation techniques speed up the process of moving from one object to another.
ABAP Training
Dialog Programming
13
Object Browser
Individual tools such as screen painter are invoked from within the object browser in one of two ways: Example 1: position the cursor on the main program, choose create, then select an object from the object list. After naming the object to be created and choosing create again, the associated tool will be launched in create mode. Example 2: position the cursor on an object in the object list (i.E. Screen) and choose create. Object browser will then launch the tool associated with the object that was selected.
ABAP Training
Dialog Programming
14
Dialog program objects can also be created using the forward navigation functionality of the SAP system. For example, during the creation of the flow logic for a screen, clicking on the name of an ABAP/4 module that has not yet been created will result in a system prompt stating that the object you have selected does not exist, do you wish to create the object? Choosing yes will launch the appropriate tool. In the case described here, the developer will select a program to include the module in and the ABAP editor (SE38) will be invoked. Creation of objects via standard navigation works for other objects such as global data declarations, include program development, screens, and many other objects. This functionality is available in all phases of development including non-dialog program development. In dialog program development, creating objects via standard navigation ensures that objects reference each other appropriately. Therefore, this is the preferred method for creating objects in a dialog program.
ABAP Training
Dialog Programming
15
ABAP Training
Dialog Programming
16
ABAP Training
Dialog Programming
17
ABAP Training
Dialog Programming
18
From the object browser (SE80) choose the program radio button, enter your program name (SAPMZxxx) and choose display. Message dialog is displayed the program SAPMZxxx does not exist. Do you want to create the object? Choose yes.
ABAP Training
Dialog Programming
19
A create program window is displayed with the name of the main program and a checkbox with top include defaulted to X. To work with an explicit TOP include, leave this box checked. This will cause the system to automatically create a TOP include along with the main program. Choose enter. Another create program window is displayed for the TOP include which the system will now attempt to create. The default name will be MZxxxTOP. Choose enter. The ABAP/4 editor (SE38) is invoked and the ABAP/4 program attributes screen is displayed. As with all program development, provide a short description and assign relevant attributes.
ABAP Training
Dialog Programming
20
Assign the type M (default) for module pool. Unlike type 1 programs (reports, some utility programs, etc.), Type M programs cannot be executed directly. They must first have a transaction code assigned to them (discussed later). After saving the main program and leaving the program attributes screen (i.E. Choosing back from the menu) you will again be prompted with the create object catalog entry screen where a development class is assigned. This time the name of the TOP include program MZxxxTOP will be displayed. You must save from this screen or the TOP include program will not be created.
ABAP Training
Dialog Programming
21
After saving the TOP include, the object list is displayed from within the object browser. The main program and the TOP include are displayed in a tree format. All objects added to the dialog program will be displayed in this hierarchy. Objects displayed here include: dictionary structures, global data, macros, PBO modules, PAI modules, subroutines, screens, GUI status, GUI title, transactions, and includes. Although dictionary structures, global data, macros, PBO modules, PAI modules, and subroutines are displayed as independent objects belonging to the main program, they are actually objects defined within the include programs which are also listed. For example, if a PBO module is added to an include program for PBO modules, that module will be displayed underneath the main program under PBO modules and the include program containing that module will be displayed with the include programs.
ABAP Training
Dialog Programming
22
Creating Screens
Create the first screen, usually numbered 0100, by positioning the cursor on the main program and choosing create, or by double clicking on the program object types entry of the object browser. The program objects list is displayed with the various types of objects which can be created. Choose the screen radio button, supply the screen number, and choose create at the bottom left of the screen. Assign the screen attributes. Provide a short description. Choose a screen type (default normal). Enter the follow-up screen to be processed after completion of current screen. Save the screen attributes. Choose the full screen button from the top to define the screen layout (paint the screen).
ABAP Training
Dialog Programming
23
Elements are added to screens using screen painter. Two editors are available in screen painter, the alphanumeric screen painter and the graphical screen painter (as of v3.0 and requires windows 95, windows NT, or UNIX). In the alphanumeric mode fields are input/OUPUT fields are represented by underlines _ and text fields are types on the screen. Additionally, graphical elements can be added to the screen (i.E. Group boxes, radio buttons, check boxes, icons, buttons, control tables, step loops) by placing a field on the screen, placing the cursor on the field and choosing graphical element. With the graphical screen painter, screen elements are chosen from a graphical list of elements and are placed on the screen using the mouse. Screen fields and objects can then be manipulated in a drag and drop fashion. To add fields from the data dictionary, choose dictionary/program fields from the GOTO menu. As a general rule, screen fields should reference dictionary fields whenever possible.
ABAP Training
Dialog Programming
24
Attributes must be defined for all screen fields. Objects taken from the dictionary retain the attributes assigned in the data dictionary unless otherwise specified. These attributes include field name, length, type, etc. And are taken from the data element and data domain. There are six field list views for defining field attributes. They are located in the menu path Goto > field list views and include: field types, text/templates, general attributes, display attributes, modification groups, and list/mc currencies.
ABAP Training
Dialog Programming
25
Additionally, field attributes can be assigned and displayed by selecting the field and choosing attributes from the screen painter or by choosing field list from the flow logic portion of screen painter. Field types Tests/templates General attributes Display attribute Modification groups List/mc currencies
ABAP Training
Dialog Programming
26
Flow logic is defined from the screen painter by choosing flow from the screen painter, or by navigating to the desired screen from the object list. Flow logic consists of a limited syntax which is different than ABAP/4. Its general purpose is to define the flow of execution of dialog programs. Module statements are inserted in the flow logic to designate which ABAP/4 modules will be executed. By double clicking on the module name, forward navigation will create the empty ABAP/4 module for you in the appropriate include program.
ABAP Training
Dialog Programming
27
PBO and PAI modules are developed in ABAP/4. PBO module statements are followed by OUTPUT and PAI module statements are followed by INPUT. PBO and PAI modules should be placed in separate include programs. All ABAP/4 statements are placed between the MODULE and ENDMODULE statements.
ABAP Training
Dialog Programming
28
Global data is defined in the TOP include. Field names must be identical to screen field names for values to pass between the dialog processor and ABAP/4 processor at runtime. Fields can be created via forward navigation or by going directly to TOP include in the ABAP editor. If a TOP include is not defined explicitly, data is placed in the global data area and the TOP include is used implicitly.
ABAP Training
Dialog Programming
29
ABAP Training
Dialog Programming
30
The following steps are the same in either case: Specify the type of program. For dialog programs, choose dialog. Choose enter. Provide a short description/transaction text. Specify the program name that the transaction will execute. Specify the first screen number that should be called by the transaction. Authorization object should be specified but is not required. For this case, leave the 'maintenance of standard transaction variant allowed' check box on (allows specification of a customer defined variant to be used each time the transaction is called - see transaction SHD0).
ABAP Training
Dialog Programming
31
Choose save to create the transaction. To execute the program, enter the transaction code you have created in the system command line with the appropriate system command prefix (/n to overwrite current session with new session, /o to open a new session).
ABAP Training
Dialog Programming
32
Transaction Types
Dialog transaction: Used to start a dialog program Report transaction: Used to start a type 1, on-line/report program (can refer to reports, conversion programs, interface programs, utility type programs etc.) Variant transaction: Used to start a program using a predefined variant Area menu transaction: Used to start an area menu. Area menus will be discussed with menu painter. Area menus are developed via transaction SE43 and can be used in place of or along with the standard SAP menu (S000). The menu that a user sees when they first logon is defined at the user level in the user profile. Parameter transaction: Used to start a program to which parameters can be passed.
ABAP Training
Dialog Programming
33
Module pool/program name: SAPMZxxx or SAPMYxxx (where xxx can be freely defined characters) TOP include: first 5 characters correspond to last five characters of first main program name. Last three characters are TOP. Example: MZxxxTOP PBO include: first 5 characters correspond to last five characters of main program name. Last three characters are Onn, where 'O' stands for output and 'nn' is a number identifying first, second, etc. Include for PBO modules. Example: mzxxxo01, mzxxxo02, etc.
ABAP Training
Dialog Programming
34
PAI include: first 5 characters correspond to last five characters of main program name. Last three characters are inn, where 'I' stands for output and 'nn' is a number identifying first, second, etc. Include for PAI modules. Example: mzxxxi01, mzxxxi02, etc. All other includes begin with last 5 characters of main program followed by a three character description.
ABAP Training
Dialog Programming
35
ABAP Training
Dialog Programming
36
ABAP Training
Dialog Programming
37
Choose the copy button and position the field on the screen with the mouse. When using a dictionary field in a dialog program, the field receives the same attributes as defined in the data dictionary. Field type and length will be the same as defined by the domain of the field chosen. All entries to the field will then be verified against the type and permitted values as determined by the domain. If a check table exists, all entries to this field during program execution will be verified in reference to the check table. Invalid entries will produce an error message.
ABAP Training
Dialog Programming
38
Radio buttons are mutually exclusive fields. Radio buttons must be assigned to a graphical group within which exclusivity is decided. For radio buttons defined by a graphical group, the system only allows one radio button to be activated within that group. Within the programming logic, radio buttons and check boxes can be interrogated using their field name to determine whether they are active or not. If the radio button or check box has been activated by the user, the value is 'X' (can be read as anything other than space), otherwise, the value will be space.
ABAP Training
Dialog Programming
39
Icons can be added to text fields in the screen painter by double clicking on the field and assigning one of the icons from the icon list. Additionally, status icons can be added to the screen (new with graphical screen painter). A status field is an output field with an icon. Status fields are used when the actual icon that will be used is not decided until runtime. Status icons are assigned via the function module ICON_CREATE (see transaction SE37 for further details). Status icons must have an internal length of at least 6 (6 does not include any text). Visualized length must be at least 2.
ABAP Training
Dialog Programming
40
Every screen by default is given one field of type OK. The OK field is a PAI field which holds the function code invoked by the user at runtime. Remember, the start of the PAI is triggered by the user invoking one of the possible function codes (I.E. Enter, save, back, exit, etc.). The OK field, like SY-UCOMM, can be read at runtime to determine how the program should react. The OK code field receives the value of the function code defined in the menu (to be discussed with menu painter) or by the function code assigned to a pushbutton in screen painter.
ABAP Training
Dialog Programming
41
You must assign a field name for the OK type field. The OK field can be displayed in screen painter by choosing the field list button from the flow logic of screen painter, or by going to field list views -> field types. The OK field is the last field displayed. It has the type OK and no name. You must define a name for the screen field AND declare a field in the ABAP global data. Within the global data declaration (TOP include) this field can by defined LIKE SYUCOMM or as a four character field. This field is commonly named OK_CODE or OKCODE. At runtime, this field will receive the value for the function code that was assigned to the option the user chose.
ABAP Training
Dialog Programming
42
ABAP Training
Dialog Programming
43
ABAP Training
Dialog Programming
44
If the dictionary field's domain has enumerated values, input is validated against these fixed values. F4 functionality (possible entries) is also available for dictionary fields as defined in the data dictionary. Automatic field input checks occur immediately after a function has been invoked (I.E. User presses enter) but before the PAI is processed. Additional field input checks can be programmed. If all entries pass the checks, processing continues with the PAI modules, otherwise message dialog occurs prompting the user for further action.
ABAP Training
Dialog Programming
45
ABAP Training
Dialog Programming
46
ABAP Training
Dialog Programming
47
To perform a field level input check in the module pool, the field statement is used in the flow logic syntax in conjunction with a call to the module where the check is performed. Use of the field statement opens the associated field for input if execution of the called module results in an error or warning message. The screen is redisplayed without processing the PBO modules for that screen. When the screen is redisplayed, only the field identified in the flow logic prior to the module call is ready for input. All other fields have been changed to display only. When the user has corrected any errors, processing resumes at the precise point where the failure occurred.
ABAP Training
Dialog Programming
48
ABAP Training
Dialog Programming
49
Field statements can exist anywhere in the flow logic that preserves the integrity of the process. By default, data transport of field values from the dialog processor (screen work area) to the ABAP processor (ABAP work area) occurs at the beginning of the PAI event for all values not contained in a field statement.
ABAP Training
Dialog Programming
50
For fields placed within a FIELD statement, values are not passed from the screen to the ABAP work area until the field statement is encountered by the dialog processor. Any given field can exist in multiple field statements. Values of fields contained in multiple field statements will remain in the screen work area until all field statements referencing that field have been processed. Values are temporarily transferred to the ABAP processor for the duration of the check performed by the field statement until the last field statement is successfully completed.
ABAP Training
Dialog Programming
51
Chain Statement
The chain statement is available to allow further control of field input checking. By using the chain statement, you can control which fields will become ready for input following a negative result from an input checking module. All fields within the CHAIN, ENDCHAIN statement become ready for input. Fields can be used in more than one chain and/or field statement. Additionally, any manipulation of screen fields that may have occurred in the PAI event prior to the field input check will not show up when the screen is redisplayed unless the manipulated fields were part of the chain statement that resulted in an error (or warning).
ABAP Training
Dialog Programming
52
Chain Statement
ABAP Training
Dialog Programming
53
ABAP Training
Dialog Programming
54
Field input checking does not always needed. For instance, if no input value was entered or the value has not changed since last time the screen was executed, there may not be a need to perform field input validation. Conditional execution of modules techniques allow the developer to control whether field input checking routines should be executed. Two methods are available: ON INPUT (flow logic) will result in execution of validation processing only if those fields are not at their initial value.
ABAP Training
Dialog Programming
55
ON REQUEST/ON CHAIN-REQUEST (flow logic) will result in execution of validation processing only if the value of a screen field has changed since the last time the screen was called using. When utilizing the FIELD statement to perform input checks, using the additional ON INPUT specification will avoid execution of the specified modules unless the fields have a value other than their initial value. Remember, the initial value is dictated by the type definition either in the data dictionary or the screen field attributes. ON CHAIN-INPUT can be used to check if at least one screen field within a CHAIN ENDCHAIN statement is not at its initial value before processing continues.
ABAP Training
Dialog Programming
56
On Request / On Chain-request
ABAP Training
Dialog Programming
57
On Request / On Chain-request
When utilizing the FIELD statement to perform input checks, using the additional ON REQUEST specification will stop the system from processing the specified modules unless the value of the field was changed by the user. ON CHAIN-INPUT can be used to check if at least one screen field within a CHAIN ENDCHAIN statement has been changed by the user before processing continues
ABAP Training
Dialog Programming
58
ABAP Training
Dialog Programming
59
Limited field input checks can also be performed within the flow logic. The basic commands available are select and values. Select within the flow logic performs much like the select single used in ABAP/4. Using the values parameter within the flow logic allows you to enumerate permitted values.
ABAP Training
Dialog Programming
60
(E)rror and (w)arning messages: Have the result of redisplaying the screen where the error occurred, reopening those fields for input that were part of the CHAIN or FIELD statement that produced the error. (A)bend messages: The text of an abend message is displayed on the current screen. After the user presses enter, processing ends and the user is returned to the initial screen. This becomes important in the case of database updates and logical units of work (LUW). (I)nformation messages: Interrupt processing and display on the screen which produced the message. When user hits enter, processing continues from the point of interruption. (S)uccess messages: Displayed on the next screen.
ABAP Training
Dialog Programming
61
ABAP Training
Dialog Programming
62
SAP memory allows for storage of values using parameter ids. If a field is given a parameter ID, its values can be sent to memory or received from memory during runtime. Values sent to memory reside for the term of the current logon session. Therefore, values can be stored beyond the execution time of one program and can be used by many programs. SET and GET parameter are used to send field contents to memory and get field contents from memory.
ABAP Training
Dialog Programming
63
SET parameter id copies field contents to the SAP memory at the PAI event. GET parameter id retrieves contents of the parameter ID from memory and places them in the designated fields at the end of the PBO event if the field is at its initial value. If the field already contains data from a module performed in the PBO of the current screen, GET parameter will not overwrite the contents. SET and GET parameter should not be used for intermediate storage in passing values from one program to another because parameter ids are session independent within a user logon. Therefore, it is possible for a parameter ID to inadvertently be set in one session while being used in another.
ABAP Training
Dialog Programming
64
Many standard SAP programs use parameter ids and SAP memory. Notice that when working with a program in the ABAP/4 editor (SE38), SET and GET parameter are used. Once working with a program in the editor, should the editor be left and restarted, the program parameter will contain the name of the program last worked on. Similarly, the report execution program (SA38), utilizes the same parameter ID. Thus, not only will the name of the last program that was been worked on in the editor default in the program name of the editor after leaving and returning, but it will also display when entering transaction the report execution transaction.
ABAP Training
Dialog Programming
65
In order for SAP memory to receive the contents of fields, SET parameter must be specified for the appropriate fields and parameter ids. Likewise, for fields to receive the contents of SAP memory, GET parameter ID must be specified for the appropriate fields and parameter ids. Not all fields have an associated parameter ID. Parameter ids are defined at the data element level of dictionary fields. If the field you wish to use SET and/or GET parameter with does not have a parameter ID assigned, you can define one in table TPARA. In dialog programs, you can specify SET and GET parameter as field attributes. SPA and GPA checkboxes correspond to set parameter and get parameter respectively.
ABAP Training
Dialog Programming
66
In addition to specifying SET and GET parameter via the field attributes of the screen painter tool, SET and GET parameter can be specified in ABAP/4 programs (i.E. In PBO modules). The above examples indicate the proper syntax for use of SET and GET parameter. Notice the use of MEMORY ID in the above parameters declaration.* * PARAMETER ID and MEMORY ID are very similar. However, when using SAP memory in the parameters statement, notice the requirement of the key word MEMORY ID rather than PARAMETER ID. Likewise, notice the use of PARAMETER ID in the SET and GET statements. Also, notice the use of single quotes for SET and GET parameter, but no quote when using MEMORY ID.
ABAP Training
Dialog Programming
67
ABAP Training
Dialog Programming
68
ABAP Training
Dialog Programming
69
Setting default values in the PBO modules (ABAP/4) Additionally, default values can be assigned within the ABAP/4 modules that are called by the PBO event. This method simply assigns values to the ABAP/4 fields and passes them to the screen fields before the screen is displayed to the user. Utilizing the HOLD DATA screen attribute to set default values Much like the field attributes which can be assigned in screen painter, screens also have attributes which can be maintained. When the HOLD DATA screen attribute has been activated, the system stores all screen field values in memory upon leaving that screen. The stored values then appear as default values the next time that screen is called.
ABAP Training
Dialog Programming
70
In the above example, the PBO event of the current screen calls MODULE INITIALIZTION, which checks to see if a value has been entered in the screen field 'year'. If not (the field is initial), the year is defaulted to the current year. At the end of the PBO event the ABAP/4 field value is sent to the screen field and displayed to the user.
ABAP Training
Dialog Programming
71
From the full screen editor, choose GOTO > SCREEN ATTRIBUTES. By activating the hold data check box, screen field values will be saved. The next time this screen is called, the saved values will again appear. Copying of saved values to the screen fields will occur after the GET parameter instruction and will therefore overwrite contents set by GET parameter. This is only true if the user has not left the current session, as HOLD DATA is only valid during the life of the current session.
ABAP Training
Dialog Programming
72
By default, the cursor will appear on the first input field of a screen. However, a default cursor position other than the first field of a screen can be set by the programmer via screen attributes or within the ABAP/4 modules. Using screen attributes to set the cursor position The screen attributes function of screen painter (GOTO > SCREEN ATTRIBUTES from screen painter) allows you to specify the desired default cursor position. By placing the field name where the cursor should first appear in the 'cursor position' of the screen attributes function, the new default location is set.
ABAP Training
Dialog Programming
73
Using the module pool to set the cursor position Cursor position can be set dynamically in the module pool using the statement SET CURSOR FIELD '<field name>'. Notice that the field name is in single quotes. Field name can be set up as a variable within the PBO module whose value is the appropriate name. If this method is used, the quotes are not necessary. When using a variable to hold the field name, the variable must be defined globally. For more information on SET CURSOR, use the help function of the ABAP editor for the keyword SET.
ABAP Training
Dialog Programming
74
Field attributes can be maintained via screen painter. If you wish for a field to use a matchcode object from the data dictionary, you specify the matchcode name in the matchcode field of dictionary attributes within screen painter.
ABAP Training
Dialog Programming
75
ABAP Training
Dialog Programming
76
Possible entries button Right justified With leading zeros Display attributes Fixed font Bright Invisible 2D display For a full list of field attributes, choose the FIELD LIST button from the full screen editor.
ABAP Training
Dialog Programming
77
Menu Painter
ABAP Training
Dialog Programming
78
Menus (GUI status) allow you to define the processing alternatives a user will have when they come to a screen. When creating a menu, you have the ability to assign functions codes to drop down menus from the menu bar, to buttons in the application tool bars (tool bar always appears at top of screen; I.E. Print, save, etc.), To buttons which will appear across the top of a screen underneath the application tool bar, and to function keys (i.E. F11 for save, shift + F12 for print, etc.) Menus are crated using the menu painter tool of the ABAP development workbench. For dialog programs, the menu painter tool is invoked via the object browser by choosing the create button, selecting the GUI status radio button, naming the status, and choosing the create button again.
ABAP Training
Dialog Programming
79
You must specify the status type: SCREEN used for creating a GUI status for a full screen which has a menu bar, pushbuttons, and input/ouput fields. DIALOG BOX used for screens that do not have a menu bar and that request only pushbuttons LIST used for a full screen with a menu bar, pushbuttons AND LIST FUNCTIONS (i.E. Scrolling) List in dialog box is used for a dialog box that contains a list. Menu buttons available but no menu bar.
ABAP Training
Dialog Programming
80
ABAP Training
Dialog Programming
81
ABAP Training
Dialog Programming
82
To define drop down menus, you double-click on the menu you wish to creator modify (from within the menu painter tool after choosing the status type) You can define up to 6 different drop down menus per GUI status. Each drop down menu can have up to fifteen menu options. Each menu option may have a function code assigned to it by placing a freely defined function code to the left of the test under the FUNC header. Alternately, each menu option may reference a sub-menu which again has 15 menu options. To create a sub-menu, type the name of the sub-menu in the menu line, do not put a function code, and double-click on the line. The a new menu with 15 possible options will appear. Again, function codes or other sub-menus can be assigned.
ABAP Training
Dialog Programming
83
To add a separator line to a menu line, position the cursor on the line you wish to add the separator to, navigate to EDIT > INSERT > SEPARATOR LINE. Menu items can be activated or deactivated using the active <-> inactive button of menu painter. If the menu option has been deactivated, the user sees the option but it is greyed out and cannot be chosen.
ABAP Training
Dialog Programming
84
ABAP Training
Dialog Programming
85
The next section of menu painter allows you to assign function codes to the tool bars at the top of the screen. The first tool bar is considered the standard tool bar (navigate back, exit, cancel, or print, save, etc.). These buttons should not be changed from their standard use. They can be activated by placing the appropriate function codes in them or removing them. The application toolbar lies immediately below the standard tool bar. These are the options that appear and are specific to the application the GUI status is used for. These are also activated by placing the function codes in the appropriate places. You can assign an icon to the function codes of the application toolbar. They can appear with text or without.
ABAP Training
Dialog Programming
86
The next part of the menu painter allows you to define function codes for the function keys. By placing function codes in the appropriate fields, those function key/code combinations will be activated within the program that references the GUI status. You define function keys in the 'freely assigned function keys' section of the menu painter.
ABAP Training
Dialog Programming
87
ABAP Training
Dialog Programming
88
Each screen may have a different menu created for it. One screen may even have multiple menus defined for it. The menu that is displayed to the user is specified in the ABAP/4 program. The GUI status must be invoked in the PBO modules. The proper syntax is SET PF-STATUS '<status name>'. The status must belong to the dialog program that is calling it.
ABAP Training
Dialog Programming
89
It is also possible to create title bars which can be set dynamically by the PBO modules. By setting the titlebar in the program the default titlebar taken from screen attributes is overwritten. Titlebars are created from the object browser like all other objects. Place the cursor on the highest node of the dialog program hierarchical structure (main program) and choose create. Choose titlebar and give the titlebar a name. Choose create again and create your titlebar. To set the titlebar in the module, use the statement: SET TITLEBAR '<titlebar name>
ABAP Training
Dialog Programming
90
To assign function code attributes, place cursor on function code from menu painter and double click. Exit type function codes can be assigned type E for exit. This allows use of the AT EXIT-COMMAND statement in the PAI flow logic. AT EXITCOMMAND is a conditional execution statement. Only when a function code with type E is invoked will that module be executed. All function codes which will be used to allow the user to exit out of the current program should be assigned type E. The default function type is blank which allows the developer to freely define how the program will react that function. Additional types are transaction and system. For a full list of available function types choose help from the attribute assignment screen of menu painter.
ABAP Training
Dialog Programming
91
ABAP Training
Dialog Programming
92
There are four commands available for updating the database: INSERT - adds new records to the database table UPDATE - changes one or more fields of specified records MODIFY - changes existing records or adds new ones DELETE - deletes specified table records With all four options, SY-SUBRC is set to 0 for success and something other than 0 for failure. When database changes occur, the SAP database triggers a command in the underlying database system. Updates occur in a sequence of related steps which are grouped together to make up a logical unit of work (LUW).
ABAP Training
Dialog Programming
93
INSERT <dbtab> adds the contents of the table work area (defined in the tables statement) to the database table. Note that authorization checks are not supported by the INSERT statement. These must be included by the programmer if required.
ABAP Training
Dialog Programming
94
INSERT INTO <dbtab> VALUES <identically structured work area> adds the contents of the identically structured work area to the table. Tables: SFLIGHT. Data: FS_SFLIGHT like SFLIGHT. Move 570 to FS_SFLIGHT-MANDT. Move 'LH' to FS_SFLIGHT-CARRID. Move ... Insert into SFLIGHT values FS_flight.
ABAP Training
Dialog Programming
95
INSERT <dbtab> FROM TABLE <itab> adds the contents of the internal table to the database table. Tables: SFLIGHT. Data: begin of INT_SFLIGHT. Include structure SFLIGHT. Data: end of INT_SFLIGHT. . . Move 570 to INT_SFLIGHT-MANDT. Move 'LH' to INT_SFLIGHT-CARRID. Move ... Append INT_SFLIGHT. . . Insert SFLIGHT from table INT_SFLIGHT.
ABAP Training
Dialog Programming
96
UPDATE <dbtab> changes a record in the database table. If not suitable record is found, the update will fail with a return code (SY-SUBRC) not equal to 0. Note that authorization checks are not supported by the UPDATE statement. These must be included by the programmer if required. Tables: SFLIGHT. Select * from SFLIGHT Where CARRID like 'l%'. Move '*' to SFLIGHT-CARRID. Update SFLIGHT. If SY-SUBRC NE 0. Message e001 with text-001. "Update failed ENDIF. ENDSELECT. If SY-SUBRC NE 0. Message e001 with text-002. "No records updated ENDIF.
ABAP Training
Dialog Programming
97
UPDATE <dbtab> FROM TABLE <itab> changes the corresponding records of the database table to the values of the internal table. Tables: SFLIGHT. Data: begin of INT_SFLIGHT. Include structure SFLIGHT. Data: end of INT_SFLIGHT. Select * from SFLIGHT into INT_SFLIGHT. Loop at INT_SFLIGHT where ... If INT_SFLIGHT-CARRID = ... Move 'LH' to INT_SFLIGHT-CARRID. Move ... Modify INT_SFLIGHT. ENDIF. Endloop. . Update SFLIGHT from table INT_SFLIGHT.
ABAP Training
Dialog Programming
98
UPDATE <dbtab> SET <field x> = <value> WHERE <field y> = <value> changes only those table fields specified with SET for all records in which the WHERE condition is met. Tables: SFLIGHT. Update SFLIGHT Set CONNID = '0064' Currency = 'USD' Where CARRID = 'LH' And PLANETYPE = 'a319'. If SY-SUBRC NE 0. Message e003 with text-003. "No records updated ENDIF.
ABAP Training
Dialog Programming
99
DELETE <dbtab> deletes only the table record with the key which corresponds to the key values of the dbtab work area. Note that authorization checks are not supported by the DELETE statement. These must be included by the programmer if required. Tables: SFLIGHT. Move 'LH' to SFLIGHT-CARRID. Move '0064' to SFLIGHT-CONNID. Move '19990324' to SFLIGHT-FLDATE. Delete SFLIGHT.
ABAP Training
Dialog Programming
100
DELETE <dbtab> WHERE deletes all table entries for which the WHERE condition is met. Tables: SFLIGHT. Delete from SFLIGHT Where CARRID = 'LH' And CONNID = '0064'.
ABAP Training
Dialog Programming
101
DELETE <dbtab> FROM TABLE <itab> deletes all database table entries for which the key matches one of the keys from the internal table itab. Tables: SFLIGHT. Data: begin of INT_SFLIGHT. Include structure SFLIGHT. Data: end of INT_SFLIGHT. Select * from SFLIGHT Where ... into INT_SFLIGHT. . . . Delete SFLIGHT from table INT_SFLIGHT.
ABAP Training
Dialog Programming
102
ABAP Training
Dialog Programming
103
SAP dialog programs (transactions) are broken down into several dialog steps. A dialog step consists of the part of the program that begins immediately following the users choice of a function (i.E. Enter, continue, etc.) With the PAI event and ends immediately following the completion of the last instruction of the PBO event for the next screen. Although several update commands may be included in one dialog step, changes to the database for those commands do not occur until the SAP system issues a COMMIT WORK or a ROLL BACK WORK command. At that point, the database connection is closed.
ABAP Training
Dialog Programming
104
After COMMIT WORK has occurred the database has been transformed to its new state. In the case of ROLL BACK WORK the database remains in the same state it would be in if no update commands were executed. In the R/3 system, COMMIT WORK or ROLL BACK WORK commands are processed at the end of each dialog step (after each screen, just before the next screen is displayed) by default. ROLL BACK WORK, which backs out any database change instructions that have occurred since the last database commit, is executed in place of COMMIT WORK if an append message has been output any time prior to the closing of the database connection for the current COMMIT WORK event. When a rollback occurs, the system keeps the log entries for the current commit. These entries can be maintained via transaction SM13. COMMIT WORK and ROLL BACK WORK can both be stated explicitly in an ABAP/4 program and thus will trigger the COMMIT WORK event. This method is used in ASYNCHRONOUS UPDATES.
ABAP Training
Dialog Programming
105
SAP dialog programs (transactions) are also broken down into logical units of work (LUWs). A logical unit of work consists of the time time immediately following one database COMMIT through the end of the next database COMMIT. If no specific program instructions specify otherwise (i.E. As in the case of asynchronous update commands), an LUW directly corresponds to a dialog step. From the functional perspective it is possible that the committing of database changes is not suitable after each dialog step (after each screen). For this purpose, asynchronous updates are possible which allow several consecutive dialog steps to be grouped together into one LUW.
ABAP Training
Dialog Programming
106
Asynchronous Updates
Asynchronous updates are used when the developer wishes to combine several consecutive dialog steps into one logical unit of work (one database level commit). Two methods are available for performing asynchronous updates: CALL FUNCTION '<function name>' IN UPDATE TASK - in this case, the function called is designated as an update type function. All database update commands (INSERT, MODIFY, CHANGE, DELETE) are placed inside the function to be called. Within the program, rather than specifying UPDATE <dbtab> etc., The update function with the relevant open SQL statements will be called. This places the update requests into a log table rather than passing them to the database. All entries remain in the log table until COMMIT WORK is explicitly specified in the ABAP/4 program (syntax: COMMIT WORK). At this point, all update requests placed in the log table since the last COMMIT WORK will be sent to the database. Likewise, if any updates failed in any of the function calls and the program handled the failing return code (IF SY-SUBRC NE 0...) With an append (type a) message, the log entries are flagged with an error and no database changes occur for the current LUW.
ABAP Training
Dialog Programming
107
PERFORM <subroutine name> ON COMMIT - in this case, the subroutines contain the database update commands. By specifying ON COMMIT, the update requests are not sent to the database until the COMMIT event is triggered by an explicitly stated COMMIT WORK in the ABAP/4. Like calling a function IN UPDATE TASK, any append messages prior to closing the database connection will result in a rollback.
ABAP Training
Dialog Programming
108
ABAP Training
Dialog Programming
109
ABAP Training
Dialog Programming
110
Lock objects are created in the ABAP/4 dictionary (TOOLS > ABAP/4 WORKBENCH > ABAP/4 DICTIONARY pushbutton or transaction SE11). You can also defined lock objects in the object browser (TOOLS > ABAP/4 WORKBENCH > OBJECT BROWSER pushbutton. From the object browser click on the dictionary objects radio button from the single objects section of the screen, and click on the EDIT pushbutton. Customer defined lock objects begin with 'EZ'. By creating a lock object, you create a view for one or more records or several tables and selected fields. When a lock object is created, the system automatically creates two function modules. ENQUEUE_<lock object> and DEQUEUE_<lock object>. Information on existing lock objects can be found in the ABAP/4 dictionary information system. SAP locking logic
ABAP Training
Dialog Programming
111
Two modes are available for lock objects: Exclusive - only one user can have a lock at a time. Shared - only one user can have change access, others may share access in view mode
ABAP Training
Dialog Programming
112
Within your program, locks entries must be set and deleted. Locks should be set prior to perform the read access. Locks must be deleted after the update has been performed. You must also set lock objects to be deleted for the BACK and CANCEL functions, the system does not do this automatically.
ABAP Training
Dialog Programming
113
ENQUEUE_,lock object> checks whether a lock was set for the same object. If so, the exception FOREIGN_LOCK is raised. If the object is not locked, the lock is set by the function module.
ABAP Training
Dialog Programming
114
By specifying _WAIT = 'X', the system automatically continues trying to set a lick at regular intervals until it succeeds or exceeds the time limit set in the profile parameters.
ABAP Training
Dialog Programming
115
ABAP Training
Dialog Programming
116
ABAP Training
Dialog Programming
117
ABAP Training
Dialog Programming
118
ABAP Training
Dialog Programming
119
Screen fields and their modifiable attributes are automatically stored in a system internal table named SCREEN. The initial values of the table fields are set by the attributes defined in screen painter. To determine the current attributes of the screen from within the ABAP/4 modules, you can LOOP at the SCREEN table where the field is the one you wish to obtain information for to get the value. You can also change the value by modifying the values in the SCREEN internal table.
ABAP Training
Dialog Programming
120
Screen modifications must be programmed in the PROCESS BEFORE OUTPUT modules. When reading the SCREEN table, the WHERE condition is NOT supported (you also cannot READ from the screen table). When modifying screen fields, the value 1 indicates true, or on, and the value 0 indicates false, or off. SCREEN ACTIVE* = 0 makes the field invisible and not ready for input. It has the same effect as the 3 combined statements SCREEN-INVISIBLE = 1, SCREEN-INPUT = 0, and SCREEN-OUTPUT = 0. *SCREEN-ACTIVE can only maintained from the module pool as long as it has not been set to invisible in the field attributes of screen painter.
ABAP Training
Dialog Programming
121
ABAP Training
Dialog Programming
122
Default follow-up screens are set in the screen attributes when a screen is first created. Screen sequence can be set dynamically at runtime in the module pool. Methods for dynamically setting screen sequence include: Set screen Call screen Leave screen
ABAP Training
Dialog Programming
123
SET SCREEN nnnn temporarily overwrites the default next screen with SCREEN nnnn. After processing of called screen, follow-up screen of calling screen is invoked unless current screen is terminated with the LEAVE SCREEN statement. Screen nnnn must be in same module pool as calling screen. To leave the current screen for good you can also use LEAVE TO SCREEN nnnn.
ABAP Training
Dialog Programming
124
SET SCREEN 0 LEAVE SCREEN and LEAVE TO SCREEN 0 take program back to location that screen was called from. Set screen 0100. . Set screen 0100. Leave screen. . Leave to screen 0100. . Set screen 0. Leave screen. . Leave to screen 0.
ABAP Training
Dialog Programming
125
CALL SCREEN nnnn interrupts the current screen, inserting screen nnnn and any of its subsequent screens. Called screen nnnn must be a screen in the same module pool as calling screen. LEAVE PROGRAM can be used to terminate current program and return to the place where terminated program was called. . . Call screen 100. . . . Leave program. . .
ABAP Training
Dialog Programming
126
By calling a screen defined as a modal dialog box and specifying STARTING AT and ENDING AT you can specify position and size of the called screen. If ENDING AT is left out, the size of the dialog box is taken from the USED size in its screen attributes.
ABAP Training
Dialog Programming
127
Processing is taken to PBO of called dialog screen. SET SCREEN 0, LEAVE SCREEN could be placed in the program logic of the PAI for the dialog screen to return to the called screen. . . Call screen 100 Starting at 20 10 Ending at 60 30. . . Called screen must be defined as a modal dialog box in the screen attributes
ABAP Training
Dialog Programming
128
ABAP Training
Dialog Programming
129
By linking program components, dialog (screen) processing and list (report) processing and be combined. List programs (reports) can call a sequence of screens, and dialog programs can interrupt screen processing to perform list processing. When called from a dialog program, list processing can occur in a full screen or in a modal dialog box. All interactive reporting techniques (drill-down, list modification, etc.) Are available.
ABAP Training
Dialog Programming
130
LEAVE TO LIST-PROCESSING will cause the system to branch from dialog processing to list processing. All PAI modules of the calling screen are processed BEFORE the list is output to the screen. In order to invoke the standard list menu, use the command SET PFSTATUS SPACE. By specifying AND RETURN TO SCREEN nnnn, processing will resume at screen nnnn after list processing. List processing ends when the user has chosen the BACK (F3) command or when the system encounters the LEAVE LIST-PROCESSING statement.
ABAP Training
Dialog Programming
131
Within a list processing program, CALL SCREEN nnnn can be used to call a dialog box or a full screen. The called screen must be a component of the calling program. Specifying LEAVE TO SCREEN 0 from within a module invoked by the called screen will return control to the calling program.
ABAP Training
Dialog Programming
132
Table Controls
ABAP Training
Dialog Programming
133
Table controls were introduced as a special screen field type with v3.0. The purpose of a table control is to allow multiple lines (rows) of the same type to exist on one screen. When declaring screen fields, dictionary fields may only be used one time on each screen. Table controls are a structure much like an internal table which contains one or more rows of one or more columns. Prior to v3.0 the STEPLOOP structure was used to allow multiple occurrences of one field type to exist on a screen.
ABAP Training
Dialog Programming
134
Table controls are a significant enhancement to the STEPLOOP concept and have the following characteristics: Resizable table grid for displaying and editing data Columns can be resized and repositioned by the user Lines and columns can be selected by the user Single, multiple, and all line selection possible Columns can be selected by header Horizontal and vertical scrolling Key columns can be fixed Individual field (cell) attributes can be modified at runtime.
ABAP Training
Dialog Programming
135
To process table controls, data is read from the database into an intermediary internal table in the module pool. During the PBO event, data is read line by line from the internal table into the control table in screen painter. During the PAI event, the contents and attributes of the control table are once again fed line by line into the internal table in the module pool, and then if necessary, into the database. Table controls are created in screen painter like other fields. With the graphical screen painter table controls can be selected and placed on the screen. In the alphanumeric screen painter choose EDIT -> create element -> table control. From within the ABAP program, the table control is defined of type TABLEVIEW, which is a complex type structure storing all of the attributes of the control table.
ABAP Training
Dialog Programming
136
To process table controls, data is read from the database into an intermediary internal table table in the module pool. During the PBO event, data is read line by line from the internal table into the control table in screen painter. During the PAI event, the contents and attributes of the control table are once again fed line by line into the internal table in the module pool, and then if necessary, into the database. Table controls are created in screen painter like other fields. With the graphical screen painter table controls can be selected and placed on the screen. In the alphanumeric screen painter choose EDIT -> create element -> table control. From within the ABAP program, the table control is defined of type TABLEVIEW, which is a complex type structure.
ABAP Training
Dialog Programming
137
LOOP AT and ENDLOOP statements are used for processing control table in the flow logic. ON REQUEST determines whether the user has manipulated the control table. If not, no modifying of the control table is necessary. If the user has made changes, you must reflect these changes to the fields of the table control in the relevant internal table so they appear after the next PBO is executed (user hits enter or scrolls). By processing the complex structure, field attributes (field selected, visible, etc.) Can be checked and/or changed.