Add a Selection Screen to a Table Maintenance Dialog
FollowRSS feedLike
13 Likes 26,261 Views 18 Comments
When end users will maintain a z-table with 100+ rows, it helps to be able to restrict the selection by any number of selection criteria. This document attempts to define a “best practice” method for calling a table maintenance dialog from a selection screen.
Current Table Maintenance
The standard way to show a table maintenance dialog is via SM30, Call View Maintenance –
– or a custom parameter transaction that calls SM30 for a specific table, with parameters VIEWNAME and UPDATE = ‘X’.
Neither of these provide an initial selection screen. Entries can be restricted by checking the “Enter conditions” radiobutton, but users are more familiar with selection screens than with the dialog box that pops up. Therefore it is good UI to use a selection screen instead of the “Enter conditions” radiobutton.
Example Selection Screen Definition
In this example, an executable report has been created with selection screen.
REPORT z_maintain_mytable.DATA mytable TYPE z_mytable.
DATA selections TYPE TABLE OF vimsellist.
DATA selection TYPE vimsellist.
SELECT-OPTIONS: so_selop1 FOR mytable–myfield1,so_selop2 FOR mytable–myfield2.
PARAMETERS: p_param1 TYPE z_mytable–myfield3,p_param2 TYPE z_mytable–myfield4.
Calling Function Modules
When the user clicks execute, the program needs to read their selections and call the table maintenance dialog. The following code shows how this is easily done by using function modules ‘VIEW_RANGETAB_TO_SELLIST’ and ‘VIEW_MAINTENANCE_CALL’.
START-OF-SELECTION.
DEFINE addsel.
CALL FUNCTION ‘VIEW_RANGETAB_TO_SELLIST’EXPORTING
fieldname = &1
append_conjunction = ‘AND’
TABLES
sellist = selections
rangetab = &2[].
END-OF-DEFINITION.DEFINE addparam.
IF &2 IS NOT INITIAL.
CLEAR selection.
selection–viewfield = &1.
selection–value = &2.
selection–and_or = ‘AND’.
selection–operator = ‘EQ’.
APPEND selection TO selections.ENDIF.END-OF-DEFINITION.add_sel ‘MYFIELD1’ so_selop1.
add_sel ‘MYFIELD2’ so_selop2.
add_par ‘MYFIELD3′ p_param1.
add_par ‘MYFIELD4′ p_param2.
CALL FUNCTION ‘VIEW_MAINTENANCE_CALL’EXPORTING
action = ‘U’ “for Update
view_name = ‘Z_MYTABLE’
complex_selconds_used = ‘X’
TABLES
dba_sellist = selections
EXCEPTIONS
OTHERS = 1.
IF sy–subrc = 1.
MESSAGE ID sy–msgid TYPE sy–msgty NUMBER sy–msgno
WITH sy–msgv1 sy–msgv2 sy–msgv3 sy–msgv4.
ENDIF.Horray! That is all. In only 46 lines (plus two for every select-option or parameter), this will bring the user to from the selection-screen to the table maintenance screen.
This is a collaborative document. If there are better ways of achieving this functionality don’t hesitate to chime in and contribute!
以下内容整理自 SAP 官方 ABAP 速查表(主题:Dynpro),作为本文的扩展补充资料。
[!NOTE] The content of this cheat sheet and the executable example are only relevant to classic ABAP.
User interfaces (UI) are not limited to displaying some information, they must also allow the user to interact with the program. In modern UI technologies, this can be achieved through events, i.e. user actions on a UI trigger events, and UI methods register these events and react accordingly. In this way, users control the program flow through their actions. In the early days of ABAP, classes, methods, and events did not exist. Program flow control had to be achieved in other ways. This is where dynpros (dynamic programs) representing a classic ABAP UI technology come into play.
This cheat sheet provides a high-level overview of classic dynpro topics with a focus on dynpro-related statements, supported by an executable example to check the syntax in action.
[!NOTE] - Classic dynpros are outdated for application programs. New developments should use web-based UIs, such as SAPUI5. - Dynpros cannot be created in ABAP Cloud. - This cheat sheet ... - is not intended to encourage you to start creating classic dynpros for programming new applications. - does not cover all facets, techniques, and keywords in great detail. - is intended to cover a selection of dynpro-related topics and syntax that you may encounter in older ABAP code. If you need more information, always consult the ABAP Keyword Documentation. - The statements covered in the dynpro flow logic are specific to dynpros. - Links to the ABAP Keyword Documentation in this cheat sheet refer to the documentation for Standard ABAP (latest version).
sy-dynnr.CALL SCREEN). Several dynpros in a single ABAP program can be called in sequence to form a dynpro sequence.[!NOTE] There are special dynpros (selection screens, classic lists). They are created implicitly. See the Selection Screens and Classic Lists cheat sheet.
PROCESS BEFORE OUTPUT (often also abbreviated as PBO): PROCESS AFTER INPUT (PAI): [!NOTE] - The PAI processing of the current dynpro and the PBO processing of the next dynpro take place one after the other in the same work process on the application server and together form a dialog step. - As soon as the screen is ready for input again, only the presentation server is active until the next user action. During this time, the ABAP program waiting for user input does not occupy a work process on the application server.
PROCESS ON HELP-REQUEST (POH) PROCESS ON VALUE-REQUEST (POV) Example:
PROCESS BEFORE OUTPUT.
... "Here, for example, modules can be called.
PROCESS AFTER INPUT.
...
"When you implement field or value helps, use the following processing blocks.
PROCESS ON HELP-REQUEST.
...
PROCESS ON VALUE-REQUEST.
...The following statements are among the non-ABAP statements in the dynpro flow logic. They are covered briefly below.
MODULE for calling dialog modulesFIELD for controlling the data transport between dynpro fields and the ABAP programCHAIN and ENDCHAIN for combining module callsLOOP and ENDLOOP for processing lines of a table control (similar to the ABAP statement LOOP)CALL SUBSCREEN for calling the flow logic of a subscreenMODULE and ENDMODULE. MODULE some_module_9000. statement, which calls an ABAP processing block called some_module_9000. PROCESS BEFORE OUTPUT, the dynpro statement MODULE can only be used to call dialog modules that were defined with the OUTPUT addition. PROCESS AFTER INPUT, PROCESS ON HELP-REQUEST, and PROCESS ON VALUE-REQUEST, only the dialog modules defined with the INPUT addition can be called.Calling dialog modules in the dynpro flow logic:
"Flow Logic tab in the screen painter
PROCESS BEFORE OUTPUT.
MODULE pbo_9000.
PROCESS AFTER INPUT.
MODULE pai_9000.Implementation of the dialog modules in the ABAP program:
MODULE pbo_9000 OUTPUT.
...
ENDMODULE.
MODULE pai_9000 INPUT.
...
ENDMODULE.CLNT and FLTP) or by reference to global data objects of the ABAP program. An advantage of DDIC types is that additional properties are available for display on the user interface, including description texts, field help, and input help.DATA or a public static attribute of a local class with CLASS-DATA.TABLES statement: DATA or CLASS-DATA. TABLES.Example:
PROGRAM some_program.
"Variable declarations
DATA some_dobj TYPE abap_bool.
TABLES some_struct.
CLASS local_class DEFINITION.
PUBLIC SECTION.
CLASS-DATA: another_dobj TYPE i.
...
ENDCLASS.
CLASS local_class IMPLEMENTATION.
...
ENDCLASS.ok_code.CASE control structure if you have multiple function codes for different control elements, and implement a response accordingly.sy-ucomm automatically receives the value of the function code. However, it is recommended that you work with the OK field instead of sy-ucomm. You have full control over the fields you declare. Also, the value of an ABAP system field should not be changed.CASE structure) and control the program flow from there.Example:
PROGRAM zdemo_program.
"OK field declaration and auxiliary variable, assuming the OK field is called
"ok_code in the Element List tab of the dynpro.
DATA: ok_code LIKE sy-ucomm,
save_ok LIKE ok_code.
...
"Dialog modules in the program
"PBO
MODULE pbo_9000 OUTPUT.
...
"Prefill the value for a screen element, e.g. input field
some_input_field = 'Hallo'.
...
ENDMODULE.
"PAI
MODULE pai_9000 INPUT.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
"For example, a button is linked with a function code named PUSH
WHEN 'PUSH'.
...
WHEN 'ENTER'.
...
WHEN 'CANCEL'.
...
WHEN OTHERS.
...
ENDCASE.
ENDMODULE.
...FIELD statements for program-controlled data transport in the Flow Logic tab. FIELD statement are transported directly. FIELD statements are possible, that is, the contents of dynpro fields specified after FIELD are transported to the global ABAP data object of the same name when the corresponding FIELD statement is executed.PROCESS AFTER INPUT.Example:
"Note: More syntax options are possible with the FIELD statement.
"See some of them below and more details in the ABAP Keyword Documentation.
PROCESS AFTER INPUT.
MODULE pai_9000. "neither field_a nor field_b are available
FIELD field_a.
MODULE module_a. "field_a is available, field_b is not
FIELD field_b.
MODULE module_b. "both field_a and field_b are availableFIELD statement with the MODULE statement, you can make the call of PAI modules dependent on conditions. mod only if the dynpro field dynp_field is not empty: FIELD dynp_field MODULE mod ON INPUT.mod only if the value of a dynpro field dynp_field has been changed (or just overwritten with the same value) by the user since the last PBO, use the following: FIELD dynp_field MODULE mod ON REQUEST.CHAIN and ENDCHAIN: CHAIN.
FIELD dynp_field1.
FIELD dynp_field2.
...
MODULE mod ON CHAIN-INPUT.
"Note: ON REQUEST is also possible
ENDCHAIN.required in the screen painter must be filled in by the user.E), which allows you to bypass the automatic input checks. MODULE mod AT EXIT-COMMAND.LEAVE statement. Otherwise, the normal PAI processing, which includes the automatic input checks, starts after the dialog module has been executed.W) or error message (E) using the ABAP statement MESSAGE. FIELD and CHAIN statements.FIELD statement as follows: FIELD dynp_field MODULE mod.mod, program your input validation and trigger a warning or error message if an error occurs. The field in question is the only field that is ready for input again, and users can (in the case of a warning) or must (in the case of an error message) correct their input before the dynpro can be successfully exited.CHAIN statement: CHAIN.
FIELD dynp_field1.
FIELD dynp_field2.
...
MODULE mod.
ENDCHAIN.mod dialog module, all fields listed in the processing chain are ready for input again. In this way, users can correct an input that consists of several closely related individual fields, and where it is not clear from the start which of the individual fields users must change in order to create a valid input as a whole. PROCESS ON HELP-REQUEST
FIELD dynp_field MODULE mod.FIELD statement does not transport any data to the ABAP program, since field help is always independent of user input. In the mod dialog module, you must then display the appropriate help yourself. You can do this by calling the function module HELP_OBJECT_SHOW, for example, or by using GUI controls. PROCESS ON VALUE-REQUEST
FIELD dynp_field MODULE mod.FIELD dynpro statement does not transport data between the dynpro field and the ABAP variable. You must therefore program the data transport yourself by calling the function modules DYNP_VALUES_READ and DYNP_VALUES_UPDATE. The function module F4IF_INT_TABLE_VALUE_REQUEST, which you can call in your dialog module, receives an internal table as a value list and transfers the dialog with the user and the data transport for you. CALL SCREEN statement (the initial dynpro is the dynpro specified in this statement)."Assumption: The static next dynpro is 9100.
"With the statement, the next dynpro is dynamically set and 9100 overwritten.
SET SCREEN 9200.
**********************************************
"The current dynpro sequence is terminated.
SET SCREEN 0.
"Starting a new dynpro sequence
CALL SCREEN 9300.STARTING AT and ENDING AT additions can be used to open a dynpro in a modal dialog box, i.e. a dynpro is displayed in a popup over the previous dynpro. "Opening a dynpro in a modal dialog box
CALL SCREEN dynnr STARTING AT col_up_left line_up.
CALL SCREEN dynnr STARTING AT col_up_left line_up ENDING AT col_up_right line_low.STARTING AT and ENDING AT define the position of the dialog box with respect to the previous dynpro and its size:col_up_left and line_up stand for values for the column for the upper left corner and the upper line of the dialog box. The values refer to the GUI window with popup level 0 (maximum popup level is 9). The right column and lower line is set automatically or explicitly by specifying col_up_right and line_low. The values of col_up_left and line_up should be less than col_up_right and line_low, otherwise the behavior will be undefined.
LEAVE SCREEN. and LEAVE TO SCREEN dynnr.
LEAVE SCREEN. exits the current dynpro and enters the next dynpro. This is either statically defined in the properties of the current dynpro or was previously set with the SET SCREEN statement.LEAVE TO SCREEN does the same, but first sets the next dynpro to the specified dynpro number. This statement is a short form of the statements SET SCREEN dynnr. LEAVE SCREEN..[!NOTE] - The statements do not exit the entire dynpro sequence and instead branch to another dynpro in the same sequence. Only if the number 0 is used to branch to the next dynpro does aLEAVEstatement terminate the dynpro sequence. - A dialog transaction can be started from an ABAP program using theCALL TRANSACTIONorLEAVE TO TRANSACTIONstatements, or directly by the user by entering the transaction code in the input field of the standard toolbar. When a dialog transaction is started, the associated ABAP program is loaded and the PBO processing of the initial dynpro is called. -LEAVE PROGRAMstatements terminate the program.
"Assumption: The next dynpro is statically defined as 9100.
"The following statement ends the processing of the current dynpro.
"Dynpro 9100 is called.
LEAVE SCREEN.
**************************************************************************
"The following statement ends the processing of the current dynpro.
"The statically defined dynpro 9100 is overwritten. Dynpro 9200 is called.
SET SCREEN 9200.
LEAVE SCREEN.
**************************************************************************
"The following statement is a shorter form of the one above.
"It has the same effect.
LEAVE TO SCREEN 9200.
**************************************************************************
"Ending the dynpro sequence
SET SCREEN 0.
LEAVE SCREEN.
"Alternative
LEAVE TO SCREEN 0.LOOP AT SCREEN and MODIFY SCREEN. LOOP AT SCREEN: SCREEN should be declared. LOOP statement below.LOOP AT SCREEN statement, the work area contains the properties of the corresponding screen element.MODIFY SCREEN: LOOP AT SCREEN and only makes sense during PBO processing. SCREEN after FROM. MODULE pbo_9000 OUTPUT.
"Assumption: An input field is not marked as required
"(i.e. the value of the component is 0).
"The example makes the input field required.
LOOP AT SCREEN INTO DATA(scr).
IF scr-name = 'SOME_INPUT_FIELD'.
scr-required = '1'.
MODIFY SCREEN FROM scr.
ENDIF.
ENDLOOP.
ENDMODULE.SET PF-STATUS statement and is created using the menu painter. "Setting the GUI status (in PBO)
SET PF-STATUS status.
****************************************************************************
"Setting the GUI status and excluding function codes, i.e. the
"specified function codes are deactivated. fcode expects either
"a character-like data object or an internal table with a flat
"character-like line type.
SET PF-STATUS status EXCLUDING fcode.sy-pfkey system field and from the GET PF-STATUS statement. "Getting the GUI status
GET PF-STATUS status.
st = sy-pfkey.
****************************************************************************
"The following statement inserts the function codes which are
"inactive in the current GUI status line by line into the
"internal table fcode
GET PF-STATUS status EXCLUDING fcode.SET TITLEBAR and created using the menu painter. "Setting a title (in PBO)
"Here, title is not the text content itself, but the name of a GUI title,
"a further UI component of the program.
SET TITLEBAR title.
"The name of the current GUI title is displayed in the system field sy-title.
gui_title = sy-title.
****************************************************************************
"WITH addition
"The placeholders of a GUI title can be replaced by the formatted
"content of data objects text1, and so on.
SET TITLEBAR title WITH text1 ... text9.[!NOTE] By separating the GUI status and title from the dynpro itself, the screen layout can remain constant when switching dynpros, and only the title and available functions can be changed.
CONTROLS statement in the ABAP program (note that wizards are available) CONTROLS contr TYPE TABLEVIEW USING SCREEN dynnr.LOOP WITH CONTROL statements that process table controls. PROCESS BEFORE OUTPUT.
...
LOOP WITH CONTROL contr.
MODULE mod_fill_table.
ENDLOOP.
...
PROCESS AFTER INPUT.
...
LOOP WITH CONTROL contr.
MODULE mod_read_table.
ENDLOOP.
...[!NOTE] - In a modern program, it is more comfortable to use an ALV Grid control. - More additions are available for the statement.
The ABAP statement REFRESH CONTROL initializes the properties of a table control.
"Code in an ABAP Program
...
REFRESH CONTROL contr FROM SCREEN dynnr.
... CONTROLS tabstr TYPE TABSTRIP.activetab is required in the program.CALL SUBSCREEN statements in the flow logic.activetab component. By default, the first tab page is active.CALL SUBSCREEN, there is one variant for the PBO and one variant for the PAI event. CALL SUBSCREEN sub_area INCLUDING prog dynnr.CALL SUBSCREEN statement.CALL SUBSCREEN sub_area.Example:
"Code in a PBO dialog module
...
"Providing a dynpro number
dynnr = '9400'.
"Assign the activetab component
tabstr-activetab = 'SOME_TAB'.
"Providing the prgram name
prog = sy-repid.
...
****************************************************************************
"Code in the flow logic
PROCESS BEFORE OUTPUT.
...
CALL SUBSCREEN sub_area INCLUDING prog dynnr.
...
PROCESS AFTER INPUT.
...
CALL SUBSCREEN sub_area.
...
CL_GUI_TOOLBAR): Implements an application toolbar that is independent of the GUI status. The input elements are created by method calls (for example, ADD_BUTTON). User actions are signaled by raising ABAP Objects events (for example, FUNCTION_SELECTED).CL_GUI_PICTURE): Allows to display images in BMP, JPG, or GIF format. The dynpro to be displayed is loaded using the LOAD_PICTURE_FROM_URL method. Events such as PICTURE_DBLCLICK signal user actions.CL_GUI_HTML_VIEWER): A browser for HTML pages or XML documents on the dynpro. Special links in the document trigger the SAPEVENT event when the user clicks, which can then be evaluated in the ABAP program. CL_GUI_TEXTEDIT): A simple text editor with the basic functions such as select, find, and replace on the dynpro. These functions can also be called in a program-controlled way using methods such as FIND_AND_REPLACE.CL_GUI_SIMPLE_TREE). They allow hierarchical relationships to be displayed in tree structures. CL_GUI_ALV_GRID should no longer be used directly for new developments. Classes such as CL_SALV_TABLE encapsulate the use of the ALV Grid control and simplify the integration. CTRL + SHIFT + A to open the search. Insert demo_dynpro* to get a list of dynpro examples.After the import of the repository, proceed as follows:
CTRL + SHIFT + A.zdemo_abap_dynpro and open the program. F8.[!NOTE] - The examples in the main branch of the ABAP cheat sheet repository are designed to be imported into the SAP BTP ABAP Environment. For Standard ABAP, you can find examples (such aszdemo_abap_dynpro) in the other branches of the repository. - The executable example ... - covers the following topics: - Dynpro flow logic and related statements (MODULE,FIELD,CHAIN/ENDCHAIN,LOOP/ENDLOOP,CALL SUBSCREEN) - ABAP statements for calling and leaving dynpros (SET SCREEN,CALL SCREEN,LEAVE SCREEN) - Modifying static attributes (LOOP AT SCREEN,MODIFY SCREEN), - Statements related to the GUI status and title (GET/SET PF-STATUS,SET TITLEBAR) - Controls (table and tabstrip controls) - does not claim to include meaningful dynpros with meaningful dynpro sequences (the branching to new dynpro sequences occurs through using appropriate statements). - is not intended to be a role model for proper dynpro design. - is not intended to solve concrete programming tasks. You should always work out your own solution for each individual case. - is only intended to demonstrate a selection of keywords and visualize dynpro-related syntax in action on a high level. - is explained in more detail below in the expandable section below. Click to view the details. - The steps to import and run the code are outlined here. - Disclaimer
🟢 Click to expand for more information
The example demonstrates dynpro-related statements. In the dynpros, you can select various options for checking out the effect of the syntax. It covers the following aspects:
MODULE, FIELD, CHAIN/ENDCHAIN, LOOP/ENDLOOP, CALL SUBSCREEN)SET SCREEN, CALL SCREEN, `LEAVESCREEN`)
LOOP AT SCREEN, MODIFY SCREEN),GET/SET PF-STATUS, SET TITLEBAR)First dynpro (the "home page"):
Dynpro "Example of screen elements":
Dynpro "Statements I":
Dynpro "Statements II":
MODULE ... AT EXIT-COMMAND opens another dynpro. It demonstrates the exit command. The input field is required to be filled. This denies the processing after choosing the Close 1 and Cancel buttons. This is not true for the Close 2 button.Dynpro "Controls":
18_Dynpro.md。版权归原作者所有。