Add a Selection Screen to a Table Maintenance Dialog

作者:郑德鼎 约 2 分钟阅读 更新日期:2024-02-22 2 年前更新 标签:ABAP, 开发

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!

来源说明:本文内容由「Add a Selection Screen to a Table Maintenance Dialog.docx」整理生成,仅用于内部技术分享与学习交流。

ABAP Cheat Sheet 补充内容

以下内容整理自 SAP 官方 ABAP 速查表(主题:Dynpro),作为本文的扩展补充资料。

Dynpro

Introduction

[!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).

About Dynpros

[!NOTE] There are special dynpros (selection screens, classic lists). They are created implicitly. See the Selection Screens and Classic Lists cheat sheet.

⬆️ back to top

Dynpro Flow Logic

[!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.

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.

⬆️ back to top

Dialog Modules

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.

⬆️ back to top

Transporting Data between Dynpros and the ABAP Program

Dynpro Fields

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 Field and Function Codes

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.
...

⬆️ back to top

Program-Controlled Data Transport

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 available

⬆️ back to top

Calling Dialog Modules Conditionally

  FIELD dynp_field MODULE mod ON INPUT.
  FIELD dynp_field MODULE mod ON REQUEST.
  CHAIN.
    FIELD dynp_field1.
    FIELD dynp_field2.
    ...
    MODULE mod ON CHAIN-INPUT.  
    "Note: ON REQUEST is also possible
  ENDCHAIN.

⬆️ back to top

Input Checks

    MODULE mod AT EXIT-COMMAND.
    FIELD dynp_field MODULE mod.
    CHAIN.
      FIELD dynp_field1.
      FIELD dynp_field2.
      ...
      MODULE mod.
    ENDCHAIN.

⬆️ back to top

Field and Input Help

    PROCESS ON HELP-REQUEST
      FIELD dynp_field MODULE mod.
    PROCESS ON VALUE-REQUEST
      FIELD dynp_field MODULE mod.

⬆️ back to top

Dnypro Sequence, Calling and Leaving Dynpros

Dynpro Sequence

⬆️ back to top

ABAP Statements for Calling and Leaving Dynpros

SET SCREEN dynnr.

"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.

CALL SCREEN dynnr.

  "Starting a new dynpro sequence

  CALL SCREEN 9300.
  "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.

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.

[!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 a LEAVE statement terminate the dynpro sequence. - A dialog transaction can be started from an ABAP program using the CALL TRANSACTION or LEAVE TO TRANSACTION statements, 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 PROGRAM statements 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.

⬆️ back to top

Modifying Static Attributes of Screen Elements

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.

⬆️ back to top

Statements for the GUI Status and Title

    "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.
    "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.
    "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.

⬆️ back to top

Controls

Table Controls

  CONTROLS contr TYPE TABLEVIEW USING SCREEN dynnr.
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.
...

⬆️ back to top

Tabstrips Controls

  CONTROLS tabstr TYPE TABSTRIP.

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.
  ...

⬆️ back to top

GUI Controls

⬆️ back to top

More Information

Executable Example

After the import of the repository, proceed as follows:

[!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 as zdemo_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:

SCREEN`)

First dynpro (the "home page"):

Dynpro "Example of screen elements":

Dynpro "Statements I":

Dynpro "Statements II":

Dynpro "Controls":

来源说明:本节内容来源:SAP-samples/abap-cheat-sheets (GitHub),原作者 SAP。原 Markdown 文件:18_Dynpro.md。版权归原作者所有。