Tải bản đầy đủ (.pdf) (153 trang)

BC ABAP Programming PHẦN 5 potx

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (7.82 MB, 153 trang )

SAP AG BC - ABAP Programming
Dropdown Boxes
December 1999 615
DEMOF4HELP-CONNID.
ENDIF.
ENDMODULE.
The next screen (statically defined) for screen 100 is 200. It has the following layout:
Cancel
Airline
Air Canada
Air France
Alitalia
American Airlines
British Airways
Continental Airways
The component CARRIER2 of the ABAP Dictionary structure DEMOF4HELP is
assigned to the input field. Its Dropdown attribute is set to
L, and it has the output
length 15. The
Value list attribute is empty, and it has the function code CARRIER.
The pushbutton has the function code CANCEL with function type E.
The screen flow logic is as follows:
PROCESS BEFORE OUTPUT.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
MODULE USER_COMMAND_100.
The next screen (statically defined) for screen 200 is 100. It has the following layout:
Cancel
Flight number
13:30:00 NEW YORK SAN FRANCISCO
09:00:00 SAN FRANCISCO NEW YORK


12:00:00 FRANKFURT MIAMI
13:30:00 NEW YORK SAN FRANCISCO
09:00:00 SAN FRANCISCO NEW YORK
12:00:00 FRANKFURT MIAMI
The component CONNID of the ABAP Dictionary structure DEMOF4HELP is
assigned to the input field. Its
Dropdown attribute is set to L, and it has the output
BC - ABAP Programming SAP AG
Dropdown Boxes
616 December 1999
length 30. The Value list attribute is set to A, and it has the function code
SELECTED. The pushbutton has the function code CANCEL with function type E.
The screen flow logic is as follows:
PROCESS BEFORE OUTPUT.
MODULE INIT_LISTBOX.
PROCESS AFTER INPUT.
MODULE CANCEL AT EXIT-COMMAND.
MODULE USER_COMMAND_200.
The user cannot type any values into the screen fields. When he or she chooses the
input field on screen 100, a value list appears in the list box, compiled from the input
help for the field DEMOF4HELP-CARRIER2. This is the search help H_SCARR,
which is assigned to the check table SCARR. The value list contains the names of
the airlines. When the user chooses an entry, the screen field is filled with the airline
code, and the PAI event is triggered. The module USER_COMMAND_100 checks
the OK_CODE field and calls screen 200.
In the PBO event of screen 200, an internal table LIST is filled with values from the
database table SPFLI. The KEY field is filled with the flight numbers, and other
relevant information is placed in the TEXT field. The table LIST is then passed to the
function module VRM_SET_VALUES. When the user chooses the input field on
screen 200, the TEXT column of the internal table is displayed in the list box. When

the user chooses an entry, the screen field is filled with the corresponding entry from
the KEY field, and the PAI event is triggered. The module USER_COMMAND_200
checks and processes the OK_CODE field.
SAP AG BC - ABAP Programming
Modifying Screens Dynamically
December 1999 617
Modifying Screens Dynamically
The attributes of screen elements are set statically in the Screen Painter when you define them.
However, it is possible to override some of these attributes in ABAP programs with the help of a
special internal table.
The R/3 System contains a function called field selection, which allows you to change the
attributes of screens dynamically.
It is also possible to set the cursor on a screen to a particular position dynamically from your
program.
Setting Attributes Dynamically [Page 618]
The Field Selection Function [Page 626]
Setting the Cursor Position [Page 637]
BC - ABAP Programming SAP AG
Setting Attributes Dynamically
618 December 1999
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.
SAP AG BC - ABAP Programming
Setting Attributes Dynamically
December 1999 619
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
11 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.
11 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.
10 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.
10 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.
BC - ABAP Programming SAP AG
Setting Attributes Dynamically
620 December 1999
11 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 (*).
11 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.

SAP AG BC - ABAP Programming
Setting Attributes Dynamically
December 1999 621
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 [Page 578]
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.
BC - ABAP Programming SAP AG
Setting Attributes Dynamically
622 December 1999
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.
SAP AG BC - ABAP Programming
Setting Attributes Dynamically
December 1999 623
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:
BC - ABAP Programming SAP AG
Setting Attributes Dynamically
624 December 1999
Demonstration of dynamic screen modifications
List
Visible input/output field
Visible output field
Visible output only field
Invisible input/output field
Invisible output field
Invisible output only field
Modification Refresh
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.


MODULE CANCEL AT EXIT-COMMAND.
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',
SAP AG BC - ABAP Programming
Setting Attributes Dynamically
December 1999 625
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.
BC - ABAP Programming SAP AG
The Field Selection Function
626 December 1999
The Field Selection Function
This topic describes how a special function Field selection (transaction SFAW and some function
modules) support you in changing screen field attributes dynamically.
Field Selection - Overview

The function Field selection allows you to change the attributes of screen fields dynamically at
runtime. However, you should only use this option if you often need to assign different field
attributes to the same screen for technical reasons. In this case, the same rules apply for all
fields, so any field modification is clear.
The following basic rules apply:
• All fields involved in the field selection process are grouped together in field selection
tables and maintained using the
Field selection function.
• You can maintain fields for an ABAP program or screen group (see below).
• On screens belonging to the screen group "blank" ('_'), there is no dynamic field
selection.
• Central field selection uses the modification group SCREEN-GROUP1, which therefore
cannot be used for anything else.
• If you use fixed special rules in the field selection which are the same as changing the
program, you should make the changes directly in the program, not in the maintenance
transaction.
With field selection, you can activate or deactivate the following attributes at runtime:
• Input
• Output
• Required
• Active
• Highlighted
• Invisible
You can also determine the conditions and the type of changes involved. During the event
PROCESS BEFORE OUTPUT, you call a function module which checks the conditions and, if
necessary, changes the attributes.
Field selection distinguishes between influencing fields and modified fields. Modified fields must,
of course, be screen fields. All fields should relate to the ABAP Dictionary. You can do this by
creating corresponding interface work areas in the ABAP program using TABLES. At runtime, a
function module analyzes the field contents of the influencing fields and then sets the attributes of

the modified fields accordingly.
Combining Screens into Screen Groups
Rather than maintaining field selection separately for each screen of a program, you can
combine logically associated screens together in a screen group. This reduces the amount of
maintenance required. To assign a screen to a screen group, enter the group in the field
Screen
group
on the attributes screen in the Screen Painter.
SAP AG BC - ABAP Programming
The Field Selection Function
December 1999 627
Calling Field Selection
To call field selection, choose Tools

ABAP Workbench

Development

Other tools

Field selection. Maintenance is by program and screen group.
Module pool
Screen group
?
Selection
Influencing fields
Modified fields
Assignment of tables to field groups
Display Change
First, you must declare the ABAP Dictionary names of the fields involved. Choose Assign tables

to screen group
and enter the tables, for example:
Module pool
Screen group
SAPMTXXX
BILD
Delete entry
Tables allowed for field selection
Table name Text
Flight connectionsSPFLI
Save your entries and choose Influencing fields to enter the desired influencing fields into the list
and optionally specify a NOT condition, a default value, and a field
Cust, for example:
BC - ABAP Programming SAP AG
The Field Selection Function
628 December 1999
Module pool
Screen group
SAPMTXXX
BILD
Choose
Influencing fld.
Text
Airline
SPFLI-CARRID
Delete field Copy template
Influencing fields
Op.
NE
Not condition

LH
Def. val.
Cust
The NOT condition is to be understood as a preselection. If one of the fields satisfies the NOT
condition, it is not relevant for the following screen modification. Using the NOT condition may
improve performance.
Influencing field: SPFLI-CARRID
NOT condition: NE LH
SPFLI-CARRID is relevant for the field selection only if its contents are not equal to
LH at runtime.
At runtime, the system uses the default value for the field modification if it cannot find the current
value of the influencing field in the list of maintained values. To achieve this, you need to define
an influence for the default value. This option allows you to maintain all the forms of an
influencing field, which have the same influence, with a single entry.
By setting the field
Cust accordingly, you can decide whether to allow customers to use the
corresponding field for field selection or not. This field selection option is based on the predefined
SAP field selection and allows customers to set screen attributes to suit their own requirements
within a framework determined by application development. Many application areas have their
own special Customizing transactions for this purpose (these are parameter transactions related
to the Transaction SFAC; refer here to the documentation on the function module
FIELD_SELECTION_CUSTOMIZE)
Then, choose
Modified fields to enter all modifiable fields into a list, for example:
SAP AG BC - ABAP Programming
The Field Selection Function
December 1999 629
Module pool
Screen group
SAPMTXXX

*
Choose
Modified field
Text
Departure airport
SPFLI-AIRPFROM
Delete field Copy template
Modifiable fields
Field no.
Cust
2
You can again set the field Cust accordingly if you want to allow customers to use these
modifiable fields in special Customizing transactions. If
Cust is selected, customers can also
modify the field.
Each of these influencing and modifiable fields has an internal number which is unique for each
program. When it is generated, the number is automatically placed in SCREEN-GROUP1 of the
appropriate screens and cannot be changed in Screen Painter. This enables the system to
establish a one-to-one relationship between the field name and SCREEN-GROUP1.
Finally, you create links between influencing and modifiable fields from the two lists: specify
which contents of an influencing field influences the modifiable field in which way.
To link fields, select the fields from both lists with
Choose or double-click. If you select an
influencing field, the list of modifiable fields appears and vice versa. From this list, select the
desired link. A list appears in which you can enter the relevant conditions, for example:
Module pool
Screen group
SAPMTXXX
*
Mod. field+ I nfl. field+ Delete entry

Influencing val. Input Output Active Oblig. Intens. Invisible
Influencing field
Modifiable field
SPFLI-CARRID
SPFLI-AIRPFROM
Airline
Departure airport
LH XX
The entry above results in suppressing the display of field SPFLI-AIRPFROM on those screens,
in whose PBO the corresponding field selection function modules are called and if SPFLI-
CARRID then contains 'LH'.
BC - ABAP Programming SAP AG
The Field Selection Function
630 December 1999
Combination Rules For Attributes
If several influencing fields influence the same modified field, there must be a combination rule to
determine how these influences are linked. You use the tables to below establish how a single
field attribute is set, if it is activated and/or deactivated by different influences. The screen
processor controls the combination of several attributes.
Input
Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ ‘_’
'X' ‘_’ 'X'
Output
Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ ‘_’
'X' ‘_’ 'X'
Active

Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ ‘_’
'X' ‘_’ 'X'
Mandatory
Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ 'X'
'X' 'X' 'X'
Highlighted
Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ 'X'
'X' 'X' 'X'
Invisible
Field 1
‘_’ 'X'
Field 2 ‘_’ ‘_’ 'X'
'X' 'X' 'X'
Description of characters:
_ = switched off , X = switched on
SAP AG BC - ABAP Programming
The Field Selection Function
December 1999 631
If Field 1 makes a screen field invisible (X), Field 2 cannot change this.
Static Attributes in the Screen Painter
In screen modifications, the system takes into account not only the entries you make during field
selection, but also any entries made in Screen Painter. This means that the result of the above
combination is linked to the screen field attributes according to the same linking rules as
individual attributes.

To take advantage of the full dynamic modification range, you should use the following attributes
in the Screen Painter:
Input = 'X'
Output = 'X'
Mandatory = '_'
Invisible = '_'
Highlighted = '_'.
Conversely, you cannot change the values defined on the screen in the following manner:
Input = '_'
Output = '_'
Mandatory = 'X'
Invisible= 'X'
Highlighted = 'X'
Furthermore, the following applies: If you enter the following combination of influences, it is not
really a valid combination, since the combination rules stipulate that the specified display
attributes cannot be changed by another influencing field (or the screen).
Input = 'X'
Output = 'X'
Active = 'X'
Mandatory = '_'
Highlighted = '_'
Invisible = '_'
When you reenter the field selection, influences that have no effect, such as the one above, are
not displayed. However, if you have defined a default value for the influencing field, it can make
sense to display and maintain influences of this kind.
Generating the Field Selection
If the list of modified fields has changed at all, you must generate the field selection. This
produces consecutive numbers for the modified SCREEN-GROUP1 fields in the screens of the
relevant ABAP program.
To generate the field selection, choose

Generate from Transaction SFAW.
Function Modules for Field Selection
To activate field selection for a screen in the PROCESS BEFORE OUTPUT event, you can call
one of the function modules FIELD_SELECTION_MODIFY_ALL or
FIELD_SELECTION_MODIFY_SINGLE. Both these function modules determine the contents of
the influencing fields, refer if necessary to the combination rules and execute the screen
modification. FIELD_SELECTION_MODIFY_ALL executes the LOOP AT SCREEN statement
itself. However, with FIELD_SELECTION_MODIFY_SINGLE, you must the LOOP AT SCREEN
BC - ABAP Programming SAP AG
The Field Selection Function
632 December 1999
yourself and call the function module within the loop. You can thus perform your own additional
screen modifications within the LOOP.
Examples of calling the function modules in the event PBO:
1.
CALL FUNCTION 'FIELD_SELECTION_MODIFY_ALL'
EXPORTING MODULPOOL = MODULPOOL
DYNPROGRUPPE = DYNGRP.
2.
LOOP AT SCREEN.
IF SCREEN_GROUP1 NE SPACE AND
SCREEN-GROUP1 NE '000'.
CALL FUNCTION 'FIELD_SELECTION_MODIFY_SINGLE'
EXPORTING MODULPOOL = MODULPOOL
DYNPROGRUPPE = DYNGRP.
* Special rules
MODIFY SCREEN.
ENDIF.
ENDLOOP.
3.

as 1, but includes your own LOOP AT SCREEN for special rules.
You must decide in each individual case which of the options 2 or 3 produces the best
performance.
Since the
Module pool and Screen group parameters determine the field selection, you must
maintain influences for these.
The
Module pool parameter defines, in main memory, which loaded module pool you use to
search for the current values of the influencing fields.
When you call the function modules, you may not use the system fields SY-REPID or SY-
DYNGR directly as actual parameters. Instead, you must assign them to other fields at an
appropriate point. For example:
MODULPOOL = SY-REPID.
DYNGRP = SY-DYNGR
Sometimes, the
Module pool values may differ from the current SY_REPID value.
If the
Screen group parameter is blank, the system uses the current contents of SY-DYNGR. This
is not possible for the
Module pool parameter because the value '_' (blank) prevents any field
modification.

Let us consider an ABAP program in which the second screen contains the following
module call in its PBO event:
PROCESS BEFORE OUTPUT.

MODULE MODIFY_SCREEN.
Suppose the module MODIFY_SCREEN contains the following function call:
SAP AG BC - ABAP Programming
The Field Selection Function

December 1999 633
MODULE MODIFY_SCREEN OUTPUT.
CALL FUNCTION 'FIELD_SELECTION_MODIFY_ALL'
EXPORTING
DYNPROGRUPPE = 'BILD'
MODULPOOL = 'SAPMTXXX'
EXCEPTIONS
OTHERS = 1.
Let us also suppose that the influences for the screen group BILD and the
corresponding ABAP program are maintained as described above.
After calling the transaction, suppose these entries are made:
Airline
Flight number
LH
Display
Change
400
After choosing
Change, the following screen appears:
From
Flight data
LUFTHANSA
FRANKFURT
Airline
Flight number
LH
400
To
NEW YORK
Departure airport

JFK
Duration
08:24:00
Departure time
10:10:00
Arrival time
11:34:00
in
KM
Distance
6.162
BC - ABAP Programming SAP AG
The Field Selection Function
634 December 1999
However, if instead of 'LH' as airline carrier 'AA' is entered, the following screen
appears:
From
Flight data
AMERICAN AIRLINES
NEW YORK
Airline
Flight number
AA
17
To
SAN FRANCISCO
Arrival airport
SFO
Flight time
06:01:00

Departure time
13:30:00
Arrival time
16:31:00
In
MLS
Distance
2.572
Departure airport
JFK
When entering 'LH', the field SPFLI-AIRPFROM is invisible. When entering 'AA', it is
visible as
Dep. airport.
Linking Fields
Every influencing field influences a field which can be modified regardless of other fields. Linking
influencing fields can be desirable in some cases but then only possible by defining help fields,
which you must set in the application program before calling the function module.
This restriction helps the transparency of the field selection.
Examples of Links
Suppose we have the following fields:
• Influencing fields: F4711, F4712
Field that can be modified: M4711
The following cases can only be implemented using a workaround:
OR Condition and "Ready for Input"
• IfF4711 = 'A' OR F4712 = 'B’, then
M4711 is ready for input.
Solution:
• Define H4711 as an influencing field in SFAW;
define the following condition in SFAW:
if H4711 = 'AB'

then M4711 input on (that is, input = 'X')
SAP AG BC - ABAP Programming
The Field Selection Function
December 1999 635
In the application program, you must program the following before calling the function module:
IF F4711 = 'A' OR F4712 = 'B'.
H4711 = 'AB'.
ENDIF.
AND Condition and "Mandatory"
• IfF4711 = 'A' AND F4712 = 'B',
then M4711 obligatory and only then.
Solution:
• Maintenance in the field selection:
If H4711 = 'AB',
then M4711 is a required-entry field
(H4711 = 'AB' only precisely with the above AND condition)
In the application program, you would write the following:
IF F4711 = 'A' AND F4712 = 'B'
H4711 = 'AB'
ELSE.
H4711 =
ENDIF.
The following cases, on the other hand, can be represented directly:
AND Condition and "Ready for Input"
• If F4711 = 'A' AND F4712 = 'B',
then M4711 is ready for input. F4711 <> ‘A’ OR F4712 <> ‘B’,
then M4711 is not ready for input.
Solution:
Screen: M4711 ready for
input

Field selection:
Influencing field F4711 Value
'A'
Input = 'X'
Value 'A1' Input = ' '
Value 'AX' Input = ' '
Influencing field F4712 Value
'B'
Input = 'X'
Value 'B1' Input = ' '
Value 'BX' Input = ' '
OR Condition and "Mandatory"
IfF4711 = 'A' OR F4712 = 'B’, then
M4711 is a required-entry field.
Solution:
Screen: Mandatory is switched
off
Influencing field F4711 Value 'A'
BC - ABAP Programming SAP AG
The Field Selection Function
636 December 1999
mandatory = 'X'
Influencing field F4712 Value 'B'
mandatory = 'X'
The possibility to define a NOT condition for an influencing field gives further variants of the field
selection definition.
Authorization for Field Selection
The authorization object for Field selection is "central field selection" (S-FIELDSEL). This object
consists of an activity and a program authorization group. The latter is taken from the program
authorizations (ABAP Editor).

Possible activities:
'02' = Change
'03' = Display
'14' = Generate field selection information on screens
'15' = Assign relevant tables to field selection
Changing a field selection modifies the program flow. It is also possible in some applications to
change the screen attributes of a field from within Customizing. This kind of change does not
count as a modification.
SAP AG BC - ABAP Programming
Setting the Cursor Position
December 1999 637
Setting the Cursor Position
When a screen is displayed, the system automatically places the cursor in the first field that is
ready for input. However, you can also define on which screen element the cursor should appear
in your program. The screen element does not have to be an input field. Positioning the cursor
can make applications more user-friendly.
You can set the cursor position either statically in the Screen Painter or dynamically in your
ABAP program.
Static Cursor Position
To define the cursor position statically, enter the name of the required screen element in the
Cursor position screen attribute [Page 531] in the Screen Painter.
Dynamic Cursor Position
To set the cursor position dynamically, use the following statement in an ABAP dialog module in
the PBO event:
SET CURSOR FIELD <f> [OFFSET <off>].
<f> can be a literal or a variable containing the name of a screen element. You can use the
OFFSET addition to place the cursor at a particular point within an input/output field.

Setting the cursor position
REPORT DEMO_DYNPRO_SET_CURSOR.

DATA: FIELD1(14), FIELD2(14), FIELD3(14),
NAME(10).
SELECTION-SCREEN BEGIN OF BLOCK BLOC WITH FRAME.
PARAMETERS: DEF RADIOBUTTON GROUP RAD,
TXT RADIOBUTTON GROUP RAD,
F1 RADIOBUTTON GROUP RAD,
F2 RADIOBUTTON GROUP RAD,
F3 RADIOBUTTON GROUP RAD.
SELECTION-SCREEN END OF BLOCK BLOC.
PARAMETERS POS TYPE I.
IF TXT = 'X'.
NAME = 'TEXT'.
ELSEIF F1 = 'X'.
NAME = 'FIELD1'.
ELSEIF F2 = 'X'.
NAME = 'FIELD2'.
ELSEIF F3 = 'X'.
NAME = 'FIELD3'.
ENDIF.
CALL SCREEN 100.
BC - ABAP Programming SAP AG
Setting the Cursor Position
638 December 1999
MODULE CURSOR OUTPUT.
IF DEF NE 'X'.
SET CURSOR FIELD NAME OFFSET POS.
ENDIF.
SET PF-STATUS 'SCREEN_100'.
ENDMODULE.
MODULE BACK INPUT.

LEAVE SCREEN.
ENDMODULE.
At the start of the program, a selection screen appears on which you can select a
cursor position.
Screen 100 is then called. The next screen (statically defined) for screen 100 is
itself, and it has the following layout:
Demonstration for cursor position on the screen
Back
Field 1
Field 2
Field 3
The input/output fields are assigned to the fields FIELD1 to FIELD3 in the ABAP
program. The heading is the text field TEXT, and the pushbutton is the screen
element PUSH.
The static cursor position in the screen attributes is set to PUSH.
The screen flow logic is as follows:
PROCESS BEFORE OUTPUT.
MODULE CURSOR.
PROCESS AFTER INPUT.
MODULE BACK AT EXIT-COMMAND.
During the PBO event, before screen 100 is displayed, the cursor is set according to
the user’s choice on the selection screen. If the user chooses the static default, the
cursor is placed on the pushbutton, otherwise on the header or one of the input
fields. The position POS is only taken into account for the input fields.
SAP AG BC - ABAP Programming
Switching on Hold Data Dynamically
December 1999 639
Switching on Hold Data Dynamically
In the attributes of a screen [Page 531], you can enable the following standard menu entries by
setting the Hold data attribute:

• System → User profile → Hold data
Hold data allows users to retain values that they have entered on a screen so that they
appear the next time they start the same transaction. Only values actually entered by
the user are retained. They are placed in the corresponding field as default values each
time the screen is processed, and they overwrite the values transferred from the ABAP
program in the PBO event.
• System → User profile → Set data
This has the same effect as Hold data. Additionally, when the held data is placed in the
screen fields, these fields are no longer ready for input.
• System → User profile → Delete data
This deletes the held data, and makes the relevant fields on the screen ready for input
again.
If
Hold data is not activated in the screen attributes, the above menu entries have no effect.
In the PBO event of a screen, you can overwrite the
Hold data attribute dynamically using the
statement
SET HOLD DATA ON|OFF.
The ON addition activates the attribute, OFF deactivates it.
Example
Hold data
REPORT DEMO_DYNPRO_SET_HOLD_DATA.
DATA FIELD(10).
CALL SCREEN 100.
FIELD = 'XXXXXXXXXX'.
CALL SCREEN 100.
MODULE HOLD_DATA OUTPUT.
SET HOLD DATA ON.
ENDMODULE.
The statically-defined next screen for screen 100 is 0, and it contains a single

input/output field called FIELD.
The flow logic is as follows:
PROCESS BEFORE OUTPUT.
MODULE HOLD_DATA.
PROCESS AFTER INPUT.

×