ABAP Dynamic setting of selection screen

  Selection Screen and Events

Each field of the selection screen has attributes, and you can use certain statements to read some of the attributes of each screen field into the predefined structure screen when you execute the ABAP program. You can then change these attributes.

Structure:SCREEN

Field NameLengthTypeExplanation
NAME132  Char Screen field name
GROUP1 3 Char Modification Group 1
GROUP2 3 Char Modification Group 2
GROUP3 3 Char Modification Group 3
GROUP4 3 Char Modification Group 4
REQUIRED 1 CharRequired input filed
INPUT 1 Char Input field
OUTPUT 1 Char Output-only field
INTENSIFIED 1 Char Highlighting
INVISIBLE 1 CharHidden
LENGTH1XDisplay length
ACTIVE1CharEffectiveness
DISPLAY_3D1CharThree-dimensional box
VALUE_HELP1CharInput help button display
REQUEST1CharWith input
VALUE_IN_COMBO1Char
COLOR4I

Description

There is no problem if it is in the program, but it is common to change it dynamically while the selection screen is displayed before it is displayed. If it is before the selection screen is displayed, describe it in the INITIALIZATION event. If it is displayed, you can change it based on the value entered in the SELECTION-SCREEN OUTPUT event. Let’s also refer to dynamically changing the selection items with radio buttons.

Sample Code:SCREEN-NAME (Field Name)

PARAMETER:
  P_SEL1 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_SEL1'.
*     処理記述
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.

The name defined by Parameter and Select-Options is stored in SCREEN-NAME. Since SCREEN contains data with various names in the automatically generated selection screen, be sure to make a conditional branch with an IF statement/CASE statement so that the logic only works for specific items with NAME when making changes. ..

Sample Code:SCREEN-GROUP1 ~GROUP4 (Modification group)

PARAMETER:
  P_SEL1 TYPE MATNR MODIF ID G1,
  P_SEL2 TYPE MATNR.
  P_SEL3 TYPE MATNR MODIF ID G1.

INITIALIZATION.
  LOOP AT SCREEN.
    IF SCREEN-GROUP1 = 'G1'.
* Process
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.

By setting the same group ID in multiple selection items as described above, the value can be set in SCREEN-GROUP1, and it is easy to execute the same processing. For GROUP2-4, there are cases where the value is set when the selection screen is automatically generated. SE51: Let’s check with Screen Painter. If it is a screen that you make your own selection screen, make full use of GROUP 1 to 4 to create a simple screen.

Sample Code:SCREEN-REQUIRED(Required input items)

PARAMETER:
  P_SEL1 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_SEL1'.
      SCREEN-REQUIRED = 1. "Required
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.

By setting SCREEN-REQUIRED to ‘1’ as described above, the selection item becomes a mandatory input, and the same effect as when the OBLIGATORY option is present. Also, if SCREEN-REQUIRED is set to ‘0’ for items that have the OBLIGATORY option, they are not required input items.

Sample Code:SCREEN-INPUT(Input Field)

PARAMETER:
  P_SEL1 TYPE MATNR,
  P_SEL2 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
    IF SCREEN-NAME = 'P_SEL1'.
      SCREEN-INPUT = 1. "Can be entered
    ENDIF.
    IF SCREEN-NAME = 'P_SEL2'.
      SCREEN-INPUT = 0. "Cannot be entered
    ENDIF.
    MODIFY SCREEN.
  ENDLOOP.

As described above, setting SCREEN-INPUT to ‘1’ enables input of the selection item (default), and setting SCREEN-INPUT to ‘0’ disables input. Input disabled is displayed in gray when the screen item is displayed.

Sample Code:SCREEN-OUTPUT(Output-only field)

Setting SCREEN-OUPUT to ‘1’ or ‘0’ does not change.
It is unclear how it can be used.

Sample Code:SCREEN-INTENSIFIED(Highlighting)

PARAMETER:
  P_SEL1 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-NAME = 'P_SEL1'.
    SCREEN-INTENSIFIED = 1. "Highlighting
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

When SCREEN-INTENSIFIED is set to ‘1’ and a value is entered from the screen, it is displayed in red.

Sample Code:SCREEN-INVISIBLE(Hidden)

PARAMETER:
  P_SEL1 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-NAME = 'P_SEL1'.
    SCREEN-INVISIBLE = 1. "Hidden
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

When SCREEN-INVISIBLE is set to ‘1’, the input field becomes “*“. For the password entry field when logging in to the GUI, the characters being entered are hidden.

Sample Code:SCREEN-LENGTH(Display Length)

PARAMETER:
  P_SEL1 TYPE MATNR.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-NAME = 'P_SEL1'.
    SCREEN-LENGTH = 5. "5 length 
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

The number of displayed digits can be set in SCREEN-LENGTH. MATNR (item code) is an 18-digit item, so an 18-digit input field is displayed, but if you set 5 as above, you can only enter up to 5 digits. Setting a value of 18 digits (maximum number of digits) or more will have no effect.

Sample Code:SCREEN-ACTIVE(Activity)

PARAMETER:
  P_SEL1 TYPE MATNR,
  P_SEL2 TYPE MATNR MODIF ID MOD.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-NAME = 'P_SEL1'.
    SCREEN-ACTIVE = 0. 
  ENDIF.
  IF SCREEN-GROUP1 = 'MOD'.
    SCREEN-ACTIVE = 0. 
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

When SCREEN-ACTIVE is set to ‘0’, the input field disappears (it disappears). However, note that the selected text is displayed, so the line itself does not disappear. If you want to hide everything, specify the MODIF ID and set.

Sample Code:SCREEN-DISPLAY_3D(3D dimension)

PARAMETER:
  P_SEL1 TYPE MATNR MODIF ID MOD.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-GROUP1 = 'MOD'.
    SCREEN-DISPLAY_3D = 1.
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

Since it is an item for displaying the selected text in 3D, set the value so that the entire line is applied with MODIF ID. When it comes to 3D display, the text frame is displayed like a hollow.

Sample Code:SCREEN-VALUE_HELP(Search help)

PARAMETER:
  P_SEL1 TYPE MATNR MODIF ID MOD.

INITIALIZATION.
  LOOP AT SCREEN.
  IF SCREEN-GROUP1 = 'MOD'.
    SCREEN-VALUE_HELP = 0.
  ENDIF.
  MODIFY SCREEN.
ENDLOOP.

Search help can be disabled. If you set ‘1’ to an item for which search help is not originally set, it has no effect.

サンプルコード:SCREEN-REQUEST(With input)

サンプルコード:SCREEN-VALUES_IN_COMBO()

サンプルコード:SCREEN-COLOR()