Setting Attributes Dynamically 
Each field on a screen has a set of attributes that are fixed when you define the screen in the Screen Painter. When an ABAP program is running, a subset of the attributes of each screen field can be addressed using the system table SCREEN.
The SCREEN Table
SCREEN is like an internal table with a header line. However, you do not have to declare it in your program. You cannot display it in the Debugger, and cannot use any work area other than its header line to address it. It has the following structure:
Component |
Length |
Type |
Description |
Attribute |
NAME |
30 |
C |
Name of the screen field |
Name |
GROUP1 |
3 |
C |
Modification group 1 |
Group 1 |
GROUP2 |
3 |
C |
Modification group 2 |
Group2 |
GROUP3 |
3 |
C |
Modification group 3 |
Group3 |
GROUP4 |
3 |
C |
Modification group 4 |
Group4 |
REQUIRED |
1 |
C |
Field input is mandatory |
Mandatory field |
INPUT |
1 |
C |
Field is ready for input |
Input |
OUTPUT |
1 |
C |
Field is for display only |
Output |
INTENSIFIED |
1 |
C |
Field is highlighted |
Highlighted |
INVISIBLE |
1 |
C |
Field is suppressed |
Invisible |
LENGTH |
1 |
X |
Field length |
VisLg |
ACTIVE |
1 |
C |
Field is active |
Input/Output/Invisible |
DISPLAY_3D |
1 |
C |
Three-dimensional box |
Two-dimensional |
VALUE_HELP |
1 |
C |
Input help button display |
Input help |
REQUEST |
1 |
C |
Input exists |
- |
The final column contains the corresponding attributes of the screen fields in the Screen Painter.
You can modify SCREEN in your ABAP program during the PBO event of a screen. Its contents override the static attributes of the screen fields for a single screen call. The only statements that you can use with SCREEN are:
LOOP AT SCREEN.
...
MODIFY SCREEN.
...
ENDLOOP.
You cannot use any further additions in the LOOP AT SCREEN statement.
The component NAME contains the name of the screen field. The components GROUP1 to GROUP4 can contain any three-character code. These codes allow you to include screen fields in up to four modification groups. Modification groups are like an extra key field for the table SCREEN that allow you to change the attributes of all of the elements in a group simultaneously. You assign elements to modification groups statically in the Screen Painter, although you can overwrite them dynamically in a program.
The remaining components are for reading and activating or deactivating the display attributes of screen fields. For all components other than LENGTH, 1 means active and 0 means inactive.
ACTIVE, INPUT, OUTPUT, and INVISIBLE
There are certain hierarchy rules between the components ACTIVE, INPUT, OUTPUT, and INVISIBLE. They also have different effects depending on their respective static settings.
The ACTIVE component has no equivalent in the element attributes. Instead, it changes the components INPUT, OUTPUT, and INVISIBLE.
At the beginning of the PBO, ACTIVE is always set to 1, regardless of the static attribute settings. Setting ACTIVE to 0 automatically sets INPUT = 0, OUTPUT = 0, and INVISIBLE = 1. Any other changes to the settings of INPUT; OUTPUT, and INVISIBLE for the same table row are ignored. Conversely, setting INPUT = 0, OUTPUT = 0, and INVISIBLE = 1 sets ACTIVE to 0, and any further assignment to ACTIVE for the same table row will also be ignored. The setting ACTIVE = 1 has no other effect on the attributes. The only purpose of the ACTIVE component is to allow you to make a screen field inactive through a single assignment. You should particularly note that a module call linked to a FIELD statement in the screen flow logic is always executed, even when SCREEN-ACTIVE = 0 for the field in question. If you want to prevent a module from being processed for an inactive field, you must specify the FIELD and MODULE statements separately.
There are eight possible combinations of ACTIVE, INPUT, OUTPUT, and INVISIBLE, that have the following effect on screen fields:
ACTIVE |
INPUT |
OUTPUT |
INVISIBLE |
Effect |
1 |
1 |
1 |
0 |
Screen field is displayed, even if Invisible is set statically. Field contents are displayed. Ready for input, even if Input is not set statically. However, not ready for input if the Output only is set statically. |
1 |
1 |
0 |
0 |
Screen field is displayed, even if Invisible is set statically, except when Output only is set statically. Field contents are not displayed. Ready for input, even if Input is not set statically. |
1 |
0 |
1 |
0 |
Screen field is displayed, even if Invisible is set statically. Field contents are displayed. Not ready for input, even if Input is set statically. |
1 |
0 |
0 |
0 |
Screen field is displayed, even if Invisible is set statically, except when Output only is set statically. Field contents are not displayed. Not ready for input, even if Input is set statically. |
1 |
1 |
1 |
1 |
Screen field is displayed, even if Invisible is set statically, except when Output only is set statically. Field contents are not displayed. Ready for input, even if Input is not set statically. User input is masked by asterisks (*). |
1 |
1 |
0 |
1 |
Screen field is displayed, even if Invisible is set statically, except when Output only is set statically. Output is masked by asterisks (*). Ready for input, even if Input is not set statically. User input is masked by asterisks (*). |
1 |
0 |
1 |
1 |
Screen field inactive. Screen field is not displayed, regardless of the static attributes. |
0 |
0 |
0 |
1 |
Screen field inactive. Screen field is not displayed, regardless of the static attributes. |
If a field is statically-defined as Output only, setting INPUT = 1 has no effect. INPUT is always 0 for these fields. Masking user input by asterisks can be used for entering user passwords.
If a whole line becomes invisible when you make fields invisible, the screen is automatically made smaller. You can, however, switch off this attribute in the static screen attributes by selecting Switch off runtime compression.
REQUIRED
When you set REQUIRED = 1, a field that is ready for input is made mandatory. Users can only leave the screen when all mandatory fields contain an entry. Exception: Function codes with type E and modules with the AT EXIT-COMMAND addition.
DISPLAY_3D
When you set DISPLAY_3D = 0, the three-dimensional frame for input/output fields is removed. You cannot use DISPLAY_3D = 1 to create a three-dimensional effect for text fields or screen fields with the Output only attribute.
VALUE_HELP
Setting VALUE_HELP to 0 or 1 switches the input help button off and on respectively.
INTENSIFIED
If you set INTENSIFIED = 1, the field contents of input fields are changed from black to red. The contents of output fields are changed from black to blue.
LENGTH
You can set the LENGTH component to a value shorter than the statically-defined output length (vislength) for input/output fields and Output only fields. This allows you to shorten their output length. You cannot shorten other screen elements, or lengthen any screen elements.
REQUEST
Setting REQUEST = 1 for a field that is ready for input has the same effect in the PAI event as if the user had changed the field contents. This means that a
conditional module call using ON REQUEST or ON CHAIN-REQUEST would be executed regardless of whether the user really changed the field. REQUEST is automatically reset to 0. 
Dynamic screen modifications.
REPORT DEMO_DYNPRO_MODIFY_SCREEN.
INCLUDE DEMO_DYNPRO_MODIFY_SCREEN_SEL.
DATA: FIELD1(10), FIELD2(10), FIELD3(10),
FIELD4(10), FIELD5(10), FIELD6(10).
DATA: OK_CODE LIKE SY-UCOMM,
SAVE_OK LIKE SY-UCOMM.
DATA: ITAB LIKE TABLE OF SCREEN WITH HEADER LINE.
DATA LENGTH(2) TYPE C.
FIELD1 = FIELD2 = FIELD3 = '0123456789'.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT.
CLEAR: ITAB, ITAB[].
SET PF-STATUS 'SCREEN_100'.
IF SAVE_OK = 'MODIFY'.
ITAB-NAME = TEXT-001.
APPEND ITAB.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'MOD'.
MOVE-CORRESPONDING SCREEN TO ITAB.
APPEND ITAB.
ENDIF.
ENDLOOP.
PERFORM CHANGE_INPUT USING:
ACT, INP, OUT, INV, REQ, INT, D3D, HLP, RQS.
CALL SELECTION-SCREEN 1100 STARTING AT 45 5.
PERFORM CHANGE_INPUT USING:
ACT, INP, OUT, INV, REQ, INT, D3D, HLP, RQS.
MESSAGE S159(AT) WITH ACT INP OUT INV.
CLEAR ITAB.
APPEND ITAB.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'MOD'.
SCREEN-ACTIVE = ACT.
SCREEN-INPUT = INP.
SCREEN-OUTPUT = OUT.
SCREEN-INVISIBLE = INV.
SCREEN-REQUIRED = REQ.
SCREEN-INTENSIFIED = INT.
SCREEN-DISPLAY_3D = D3D.
SCREEN-VALUE_HELP = HLP.
SCREEN-REQUEST = RQS.
SCREEN-LENGTH = LEN.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
CLEAR ITAB.
ITAB-NAME = TEXT-002.
ITAB-ACTIVE = ACT.
ITAB-INPUT = INP.
ITAB-OUTPUT = OUT.
ITAB-INVISIBLE = INV.
ITAB-REQUIRED = REQ.
ITAB-INTENSIFIED = INT.
ITAB-DISPLAY_3D = D3D.
ITAB-VALUE_HELP = HLP.
ITAB-REQUEST = RQS.
ITAB-LENGTH = LEN.
APPEND ITAB.
CLEAR ITAB.
APPEND ITAB.
ENDIF.
ENDMODULE.
MODULE CANCEL INPUT.
LEAVE PROGRAM.
ENDMODULE.
MODULE USER_COMMAND_0100 INPUT.
SAVE_OK = OK_CODE.
CLEAR OK_CODE.
CASE SAVE_OK.
WHEN 'MODIFY'.
LEAVE TO SCREEN 100.
WHEN 'LIST'.
CLEAR ITAB.
ITAB-NAME = TEXT-003.
APPEND ITAB.
LOOP AT SCREEN.
IF SCREEN-GROUP1 = 'MOD'.
MOVE-CORRESPONDING SCREEN TO ITAB.
APPEND ITAB.
ENDIF.
ENDLOOP.
CALL SCREEN 200 STARTING AT 45 5
ENDING AT 95 22.
ENDCASE.
ENDMODULE.
MODULE REQUESTED INPUT.
MESSAGE S888(SABAPDOCU) WITH TEXT-004.
ENDMODULE.
MODULE STATUS_0200 OUTPUT.
SET PF-STATUS 'SCREEN_200'.
SUPPRESS DIALOG.
LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN 0.
FORMAT COLOR COL_HEADING ON.
WRITE: 10 'ACT', 14 'INP', 18 'OUT', 22 'INV', 26 'REQ',
30 'INT', 34 'D3D', 38 'HLP', 42 'RQS', 46 'LEN'.
FORMAT COLOR COL_HEADING OFF.
ULINE.
LOOP AT ITAB.
IF ITAB-NAME = ' '.
ULINE.
ELSEIF ITAB-NAME = TEXT-001 OR ITAB-NAME = TEXT-003.
FORMAT COLOR COL_NORMAL ON.
ELSE.
FORMAT COLOR COL_NORMAL OFF.
ENDIF.
LEN = ITAB-LENGTH.
LENGTH = ' '.
IF LEN NE 0.
LENGTH = LEN.
ENDIF.
WRITE: /(8) ITAB-NAME,
11 ITAB-ACTIVE,
15 ITAB-INPUT,
19 ITAB-OUTPUT,
23 ITAB-INVISIBLE,
27 ITAB-REQUIRED,
31 ITAB-INTENSIFIED,
35 ITAB-DISPLAY_3D,
39 ITAB-VALUE_HELP,
43 ITAB-REQUEST,
47 LENGTH.
ENDLOOP.
ENDMODULE.
FORM CHANGE_INPUT CHANGING VAL.
IF VAL = 'X'.
VAL = '1'.
ELSEIF VAL = ' '.
VAL = '0'.
ELSEIF VAL = '1'.
VAL = 'X'.
ELSEIF VAL = '0'.
VAL = ' '.
ENDIF.
ENDFORM.
The next screen (statically defined) for screen 100 is itself, and it has the following layout:
The input/output fields are assigned to the fields FIELD1 to FIELD6 in the ABAP program. These fields, along with the text field TEXT in the top line, are assigned to the modification group MOD. The remaining screen elements are not assigned to a modification group. The function codes of the pushbuttons are MODIFY, UNDO, and LIST.
The screen flow logic is as follows:
PROCESS BEFORE OUTPUT.
MODULE STATUS_0100.
PROCESS AFTER INPUT.
FIELD FIELD1 MODULE REQUESTED ON REQUEST.
MODULE USER_COMMAND_0100.
If you choose Modification, a selection screen appears, on which you can select which of the components of the SCREEN table should be set to active or inactive. In the subroutine CHANGE_INPUT, the user input from the checkboxes is converted into the digits 0 and 1. Selection screen 1100 is defined in the following include program:
*----------------------------------------------------------------*
* INCLUDE DEMO_DYNPRO_MODIFY_SCREEN_SEL *
*----------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF SCREEN 1100.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME NO INTERVALS.
PARAMETERS: ACT AS CHECKBOX DEFAULT '1',
INP AS CHECKBOX DEFAULT '1',
OUT AS CHECKBOX DEFAULT '1',
INV AS CHECKBOX DEFAULT '0'.
SELECTION-SCREEN END OF BLOCK B1.
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME NO INTERVALS.
PARAMETERS: REQ AS CHECKBOX DEFAULT '0',
D3D AS CHECKBOX DEFAULT '1',
HLP AS CHECKBOX DEFAULT '0',
INT AS CHECKBOX DEFAULT '0'.
SELECTION-SCREEN END OF BLOCK B2.
SELECTION-SCREEN BEGIN OF BLOCK B3 WITH FRAME NO INTERVALS.
PARAMETERS RQS AS CHECKBOX DEFAULT '0'.
SELECTION-SCREEN END OF BLOCK B3.
SELECTION-SCREEN BEGIN OF BLOCK B4 WITH FRAME NO INTERVALS.
PARAMETERS LEN TYPE I DEFAULT 10.
SELECTION-SCREEN END OF BLOCK B4.
SELECTION-SCREEN END OF SCREEN 1100.
When you modify the screen, the current contents of the table SCREEN for the modification group MOD are placed in the auxiliary table ITAB in the PBO event. This represents the static settings of the corresponding screen fields. SCREEN is then modified according to the settings chosen by the user. The user input is also stored in ITAB.
The screen is displayed, and the fields that belong to the modification group MOD are displayed according to the new attributes stored in SCREEN. The contents of the entries for ACTIVE, INPUT, OUTPUT, and INVISIBLE are visible in the status bar.
In the PAI event, the module REQUESTED is called if the user changes the contents of FIELD1 or sets the REQUEST component of the table SCREEN.
If the user chooses List, the current contents of the table SCREEN are appended to ITAB in the PAI module USER_COMMAND_0100. Screen 200 is then called as a modal dialog box. Screen 200 is used to display the list of table ITAB. The contents of the table SCREEN are displayed before and after modification. This makes it possible to compare directly the effects of the input on the individual components and the dependencies between the entries.