无常笔记ABAP Cheat Sheets中文导读全站搜索

英文原文:SAP-samples · 上游版本 d43eb13c4c7c · 原始 Markdown

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]

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

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

⬆️ back to top

Input Checks

⬆️ back to top

Field and Input Help

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

LEAVE SCREEN. and LEAVE TO SCREEN dynnr.

[!NOTE]

"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

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

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]

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

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]


🟢 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:

First dynpro (the "home page"):

Dynpro "Example of screen elements":

Dynpro "Statements I":

Dynpro "Statements II":

Dynpro "Controls":