SAP Function SELECT_OPTIONS_RESTRICT - Make use of SELECT-OPTIONS easier on the selection screen

Parameter Reference Type Length Default Optional Text
DB RSSCR-DB C 1 SPACE X X: Call using logical database
PROGRAM SYST-REPID C 40 X Program name (default SY-CPROG or SY-LDBPG)
RESTRICTION SSCR_RESTRICT 0 Description of restrictions

Exception Text
EMPTY_OPTION_LIST One of the options lists is empty
INVALID_KIND One line has a KIND value unequal to A, B, or S
INVALID_SIGN Invalid sign
REPEATED Multiple call using LDB or report
REPEATED_KIND_A More than one line has KIND = 'A'
SELOPT_WITHOUT_OPTIONS One of the select-options contains no valid options
SELOPT_WITHOUT_SIGNS One of the select-options does not have a valid sign
TOO_LATE Call is too late

Functionality
This function module simplifies the handling of SELECT-OPTIONS on theselection screen by restricting possible selection options and signs.
By calling this function module, you can restrict the number ofselectio options available for the chosen selection field. You can alsodisable the function allowing users to enter values to be excluded fromthe selection (SIGN = 'E').
The set of options (and signs) listed here can be extended for the'multiple selection' screen.
You may call this function module once only in any program containingselection screens (if you try to call it a second time, the exceptionREPEATED occurs). This means that if a selection field appears on twodifferent selection screens, you cannot set different restrictions forit each time. You can call the function module before the firstselection screen is displayed (and even before the program is loaded).The latest you can call it is in the PBO of the first selection screento be displayed. If you call it any later, the exception TOO_LATEoccurs.
For a SUBMIT (standard selection screen 1000), the best time to callthe function module is in the INITIALIZATION event. In this case, thereport usually runs with a logical database. Both the logical databaseand the report itself can define restrictions (you can recognize thisfrom the value of the DB parameter). The logical database can only setrestrictions for its own (database-specific) selection criteria. Thereport, on the other hand, can restrict both its own selection criteriaand those of the report. Only options allowed by both the logicaldatabase and the report are valid for the database-specific selectioncriteria.
If you call the function module from the logical database, the callmust occur before the PBO of the first selection screen of the report:The most sensible way to to do this is in the INIT routine, which isprocessed both in a SUBMIT and when you call the selection screens ofthe report independently with CALL SELECTION-SCREEN. As in the report,you can only call the function module once from a logical database.
You pass the following in the RESTRICTION parameter (type SCR_RESTRICT,defined in type pool SSCR):
Component OPT_LIST_TAB:
This is a table of option lists.
Each line contains a field NAME (10 characters) with a
freely-definable name for a list of valid options, and a
field OPTIONS (structure RSOPTIONS), with a character field
of length 1 (for exmample, EQ, BT, ...) foro each of the 10
possible options. The options you select are valid.
Component ASS_TAB:
This is a table in which you assign selection screen objects to
option lists and permitted signs.
In each line, you must specify:
KIND: 'A': The restrictions apply to all SELECT-OPTIONS.
If you call the function module through the logical
database, only the database-specific SELECT-OPTIONS
are affected. If you call it through the program, the
restrictions apply to all SELECT-OPTIONS.
'B': Block on the selection screen. The restrictions apply
to all SELECT-OPTIONS within the selection screen block
specified in the field NAME (database-specific block
if you call the function module through the logical
database). The restrictions also apply to blocks within
the specified block.
'S': The restrictions apply to the single SELECT-OPTIONS
specified in NAME (database-specific field if you call
the function module through the logical database).
NAME: Where KIND = 'B' or 'S': Name of the object
Where KIND = 'A': Empty
SG_MAIN: '*': Do not restrict the sign on the main selection
screen.
'I': Only sign 'I' allowed on the main selection screen.
SG_ADDY: '*': Do not restrict the sign on the 'Multiple selection'
screen.
' ': Apply the same sign restriction to the multiple
selection screen as to the main selection screen.
'N': Multiple selections not allowed.
OP_MAIN: Name of the option list (from RESTRICTION-OPT_LIST_TAB)
for the main selection screen.
OP_ADDY: Name of the option list (from RESTRICTION-OPT_LIST_TAB)
for the multiple selection screen.
There are always at least as many options available on
the multiple selection screen as on the main selection
screen. The options available on the multiple selection
screen are the union of the two lists OP_MAIN and OP_ADDY.
The function module allows you to set 'progressive' restrictions. Forexample, you set restrictions with KIND = 'A', which are thenoverwritten for a block KIND = 'B' (the first set of restrictions nolonger apply to the block). You can also apply further 'B' restrictionsto blocks within the block. Finally, you can set individualrestrictions for each selection option (whether it is part of a blockor not).

Effect at runtime
On the selection screen, only the specified selection fields and (ifset) only the sign 'I' are permitted. If you exclude the options 'BT'(interval) and 'NB' (exclude interval), the HIGH field of the selectioncriterion is deactivated.
Similarly, the 'Multiple selection' screen only permits the specifiedoptions and sign.If the field 'SG_ADDY' has the value 'N' (no multipleselections allowed), the multiple selection pushbutton is notdisplayed.This corresponds to the statuic 'NO-EXTENSION' addition inthe SELECT-OPTIONS statement. If intervals are not allowed on the mainselection screen, the 'to' text and the 'HIGH' field are not displayed.
Since more is usually allowed with 'multiple selections' than on themain selection screen, it is possible that a user may enter a selectionon the multiple selection screen that is not allowed on the mainselectiion screen. In this case, the main selection screen displays thefirst valid line. If none of the lines from the multiple selectionscreen are valid on the main selection screen, it remains empty, butthe 'multiple selection arrow' at the end of the line turns green toindicate that selections have been made.
If selections exist that are not valid on either the 'main selectionscreen' or on the 'multiple selection screen' (for example, due to anobsolete variant), a runtime error occurs.

Example
REPORT TESTREP.
* Include type pool SSCR
TYPE-POOLS SSCR.
* Define the object to be passed to the RESTRICTION parameter
DATA RESTRICT TYPE SSCR_RESTRICT.
* Auxiliary objects for filling RESTRICT
DATA OPT_LIST TYPE SSCR_OPT_LIST.
DATA ASS TYPE SSCR_ASS.
* Define the selection screen objects
* First block: 3 SELECT-OPTIONS
SELECTION-SCREEN BEGIN OF BLOCK BLOCK_0 WITH FRAME TITLE TEXT-BL0.
SELECT-OPTIONS SEL_0_0 FOR SY-TVAR0.
SELECT-OPTIONS SEL_0_1 FOR SY-TVAR1.
SELECT-OPTIONS SEL_0_2 FOR SY-TVAR2.
SELECT-OPTIONS SEL_0_3 FOR SY-TVAR3.
SELECTION-SCREEN END OF BLOCK BLOCK_0.
* Second block: 2 SELECT-OPTIONS
SELECTION-SCREEN BEGIN OF BLOCK BLOCK_1 WITH FRAME TITLE TEXT-BL1.
SELECT-OPTIONS SEL_1_0 FOR SY-SUBRC.
SELECT-OPTIONS SEL_1_1 FOR SY-REPID.
SELECTION-SCREEN END OF BLOCK BLOCK_1.
INITIALIZATION.
* Define the option list
* ALL: All options allowed
MOVE 'ALL' TO OPT_LIST-NAME.
MOVE 'X' TO: OPT_LIST-OPTIONS-BT,
OPT_LIST-OPTIONS-CP,
OPT_LIST-OPTIONS-EQ,
OPT_LIST-OPTIONS-GE,
OPT_LIST-OPTIONS-GT,
OPT_LIST-OPTIONS-LE,
OPT_LIST-OPTIONS-LT,
OPT_LIST-OPTIONS-NB,
OPT_LIST-OPTIONS-NE,
OPT_LIST-OPTIONS-NP.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
* NOPATTERN: CP and NP not allowed
CLEAR OPT_LIST.
MOVE 'NOPATTERN' TO OPT_LIST-NAME.
MOVE 'X' TO: OPT_LIST-OPTIONS-BT,
OPT_LIST-OPTIONS-EQ,
OPT_LIST-OPTIONS-GE,
OPT_LIST-OPTIONS-GT,
OPT_LIST-OPTIONS-LE,
OPT_LIST-OPTIONS-LT,
OPT_LIST-OPTIONS-NB,
OPT_LIST-OPTIONS-NE.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
* NOINTERVLS: BT and NB not allowed
CLEAR OPT_LIST.
MOVE 'NOINTERVLS' TO OPT_LIST-NAME.
MOVE 'X' TO: OPT_LIST-OPTIONS-CP,
OPT_LIST-OPTIONS-EQ,
OPT_LIST-OPTIONS-GE,
OPT_LIST-OPTIONS-GT,
OPT_LIST-OPTIONS-LE,
OPT_LIST-OPTIONS-LT,
OPT_LIST-OPTIONS-NE,
OPT_LIST-OPTIONS-NP.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
* EQ_AND_CP: only EQ and CP allowed
CLEAR OPT_LIST.
MOVE 'EQ_AND_CP' TO OPT_LIST-NAME.
MOVE 'X' TO: OPT_LIST-OPTIONS-CP,
OPT_LIST-OPTIONS-EQ.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
* JUST_EQ: Only EQ allowed
CLEAR OPT_LIST.
MOVE 'JUST_EQ' TO OPT_LIST-NAME.
MOVE 'X' TO OPT_LIST-OPTIONS-EQ.
APPEND OPT_LIST TO RESTRICT-OPT_LIST_TAB.
* Assign selection screen objects to option list and sign
* KIND = 'A': applies to all SELECT-OPTIONS
MOVE: 'A' TO ASS-KIND,
'*' TO ASS-SG_MAIN,
'NOPATTERN' TO ASS-OP_MAIN,
'NOINTERVLS' TO ASS-OP_ADDY.
APPEND ASS TO RESTRICT-ASS_TAB.
* KIND = 'B': applies to all SELECT-OPTIONS in block BLOCK_0,
* that is, SEL_0_0, SEL_0_1, SEL_0_2
CLEAR ASS.
MOVE: 'B' TO ASS-KIND,
'BLOCK_0' TO ASS-NAME,
'I' TO ASS-SG_MAIN,
'*' TO ASS-SG_ADDY,
'NOINTERVLS' TO ASS-OP_MAIN.
APPEND ASS TO RESTRICT-ASS_TAB.
* KIND = 'S': applies to SELECT-OPTION SEL-0-2
CLEAR ASS.
MOVE: 'S' TO ASS-KIND,
'SEL_0_2' TO ASS-NAME,
'I' TO ASS-SG_MAIN,
'*' TO ASS-SG_ADDY,
'EQ_AND_CP' TO ASS-OP_MAIN,
'ALL' TO ASS-OP_ADDY.
APPEND ASS TO RESTRICT-ASS_TAB.
* KIND = 'S': Applies to SELECT-OPTION SEL_0_3
CLEAR ASS.
MOVE: 'S' TO ASS-KIND,
'SEL_0_3' TO ASS-NAME,
'I' TO ASS-SG_MAIN,
'N' TO ASS-SG_ADDY,
'JUST_EQ' TO ASS-OP_MAIN.
APPEND ASS TO RESTRICT-ASS_TAB.
* Call function module
CALL FUNCTION 'SELECT_OPTIONS_RESTRICT'
EXPORTING
RESTRICTION = RESTRICT
* DB = ' '
EXCEPTIONS
TOO_LATE = 1
REPEATED = 2
NOT_DURING_SUBMIT = 3
DB_CALL_AFTER_REPORT_CALL = 4
SELOPT_WITHOUT_OPTIONS = 5
SELOPT_WITHOUT_SIGNS = 6
INVALID_SIGN = 7
REPORT_CALL_AFTER_DB_ERROR = 8
EMPTY_OPTION_LIST = 9
INVALID_KIND = 10
REPEATED_KIND_A = 11
OTHERS = 12.
* Exception handling
IF SY-SUBRC NE 0.
...
ENDIF.
...
START-OF-SELECTION.
...
There is an explicit assignment for SEL_0_2: On the main selectionscreen, only the options EQ and CP and the sign I are allowed, while onthe multiple selection scren, all options (option list 'ALL') and bothsigns (SG_ADDY = '*') are allowed.
There is also an explicit assignment for SELECT-OPTION SEL_0_3: Onlythe option EQ and the sign I is allowed on the main selection screen,and multiple selections are not allowed at all. The multiple selectionspushbutton is not displayed. On the main selection screen, whereintervals are not allowed, the 'to' text and the HIGH field are notdisplayed. Consequently, the selection criterion appears on the screenlike a parameter.
For the two other SELECT-OPTIONS in BLOCK_0, that is, SEL_0_0 andSEL_0_1, the restriction for BLOCK_0 applies: Only sign I, with nointervals on the main selection screen, and both signs, but still nointervals on the multiple selection screen.
For all SELECT-OPTIONS not in block BLOCK_0, that is, SEL_1_0 andSEL_1_1, the restrictions defined for KIND = 'A' apply: No patterns onthe main selection screen, but both signs are allowed. All options areallowed on the multiple selection screen (union of NOPATTERN andNOINTERVLS), and again, both signs.

Notes
You should take care when using this function module, sinceinconsistencies can arise if you use it with the 'NO INTERVALS' or'NO-EXTENSION' additions.
The problem may also occur that the HIGH field for a selection field isnot displayed (so no intervals can be entered). However, if you haveused this function module to specify that only intervals are allowedfor that particular selection field (only 'BT' and 'NB'), no entry atall is possible. In this case, the LOW field is deactivated as well.
When you call the report, you should also remember that the logicaldatabase may already have defined restrictions for its SELECT-OPTIONS.Since the system allows only those options allowed by both the logicaldatabase and the program, a situation can occur where the'SELOPT_WITHOUT_OPTIONS' exception occurs.

Exceptions
If an exception occurs when you call the function module through thelogical database, the database-specific restrictions are ignored, butany report-specific restrictions are retained.
If an exception occurs when you call the function module through thereport, any database-specific restrictions are retained, butreport-specific restrictions are ignored.
Restrictions are never activated in a call that ends in an exception.

Description
'X': Called by the logical database
SPACE: Called by the report
The selection screens of a report contain objects that are definedthrough the logical database ("database-specific") and others that aredefined in the report ("report-specific").
The logical database can define restrictions for database-specificselection criteria, and the report can define restrictions forreport-specific selection criteria. The only options and signspermitted for database-specific fields are those allowed by both thelogical database and the program.
This parameter indicates whether the function module was called by thelogical database or by the report.

Value range
'X', SPACE

Default
SPACE

Description
Name of the program to whose selection screens the restrictions shouldapply.

Default
The default value of PROGRAM depends on the value of the parameter DB:
DB = SPACE: Default SY-CPROG, the name of the main program of the
transaction, or report in the case of SUBMIT.
DB = 'X': Default SY-LDBPG, the name of the database program of
the logical database associated with the program.
Caution: If the selection screen of a report is processed
using logical database ldb, but the report is not
started using SUBMIT or a report transaction,
SY-LDBPG does not contain the name (SAPDBldb) of
the corresponding database program.

Description
This object contains information about the restrictions for theSELECT-OPTIONS both on the main selection screen and on the multipleselections screen.
The exact meaning of the individual components is described in thefunction module documentation.