Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

select-option

Former Member
0 Likes
4,387

Hi All,

i am new to abap and facing some difficulty in understanding the use of select-option. can anyone explain me the need and use of select-option. quick response will be highly appreciated.

Regards

Victor

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
3,472

Hi victor,

1. In select-options (as compared to parameter),

we can enter

a) more than one value

b) we can enter range of values eg. 5 - 10

c) we can EXCLUDE values

d) we can enter >=, <=, etc.

regards,

amit m.

7 REPLIES 7
Read only

Former Member
0 Likes
3,472

Hi Victor,

Check this info.

Make use of SELECT-OPTIONS easier on the selection screen

Functionality

This function module simplifies the handling of SELECT-OPTIONS on the selection screen by restricting possible selection options and signs.

By calling this function module, you can restrict the number of selectio options available for the chosen selection field. You can also disable the function allowing users to enter values to be excluded from the 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 containing selection screens (if you try to call it a second time, the exception REPEATED occurs). This means that if a selection field appears on two different selection screens, you cannot set different restrictions for it each time. You can call the function module before the first selection screen is displayed (and even before the program is loaded). The latest you can call it is in the PBO of the first selection screen to be displayed. If you call it any later, the exception TOO_LATE occurs.

For a SUBMIT (standard selection screen 1000), the best time to call the function module is in the INITIALIZATION event. In this case, the report usually runs with a logical database. Both the logical database and the report itself can define restrictions (you can recognize this from the value of the DB parameter). The logical database can only set restrictions for its own (database-specific) selection criteria. The report, on the other hand, can restrict both its own selection criteria and those of the report. Only options allowed by both the logical database and the report are valid for the database-specific selection criteria.

If you call the function module from the logical database, the call must 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 is processed both in a SUBMIT and when you call the selection screens of the 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. For example, you set restrictions with KIND = 'A', which are then overwritten for a block KIND = 'B' (the first set of restrictions no longer apply to the block). You can also apply further 'B' restrictions to blocks within the block. Finally, you can set individual restrictions for each selection option (whether it is part of a block or not).

Effect at runtime

On the selection screen, only the specified selection fields and (if set) only the sign 'I' are permitted. If you exclude the options 'BT' (interval) and 'NB' (exclude interval), the HIGH field of the selection criterion is deactivated.

Similarly, the 'Multiple selection' screen only permits the specified options and sign.If the field 'SG_ADDY' has the value 'N' (no multiple selections allowed), the multiple selection pushbutton is not displayed.This corresponds to the statuic 'NO-EXTENSION' addition in the SELECT-OPTIONS statement. If intervals are not allowed on the main selection screen, the 'to' text and the 'HIGH' field are not displayed.

Since more is usually allowed with 'multiple selections' than on the main selection screen, it is possible that a user may enter a selection on the multiple selection screen that is not allowed on the main selectiion screen. In this case, the main selection screen displays the first valid line. If none of the lines from the multiple selection screen are valid on the main selection screen, it remains empty, but the 'multiple selection arrow' at the end of the line turns green to indicate that selections have been made.

If selections exist that are not valid on either the 'main selection screen' or on the 'multiple selection screen' (for example, due to an obsolete 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.

...

Hope this resolves your query.

Reward all the helpful answers.

Regards

Read only

Former Member
0 Likes
3,473

Hi victor,

1. In select-options (as compared to parameter),

we can enter

a) more than one value

b) we can enter range of values eg. 5 - 10

c) we can EXCLUDE values

d) we can enter >=, <=, etc.

regards,

amit m.

Read only

Former Member
0 Likes
3,472

hi,

You use the statement

SELECT-OPTIONS <seltab> for <f>.

to declare a selection table in the program that is linked to the <f> column of a database table, or to an internal <f> field in the program. A selection table is an internal table object of the standard table type that has a standard key and a header line. Selection tables are used to store complex selections using a standardized procedure. They can be used in several ways. Their main purpose is to directly translate the selection criteria into database selections using the WHERE addition in Open SQL statements.

In addition to selection tables that you create using SELECT-OPTIONS, you can use the RANGES statement to create internal tables that have the structure of selection tables. You can use these tables with certain restrictions the same way you use actual selection tables.

Structure of Selection Tables

The row type of a selection table is a structure that consists of four components: SIGN, OPTION, LOW, and HIGH. Each row of a selection table that contains values represents a sub-condition for the complete selection criterion. Description of the individual components:

SIGN

The data type of SIGN is C with length 1. The contents of SIGN determine for each row whether the result of the row condition is to be included in or excluded from the resulting set of all rows. Possible values are I and E.

– I stands for "inclusive" (inclusion criterion - operators are not inverted)

– E stands for "exclusive" (exclusion criterion - operators are inverted)

OPTION

The data type of OPTION is C with length 2. OPTION contains the selection operator. The following operators are available:

– If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. Yet operators CP and NP do not have the full functional scope they have in normal logical expressions. They are only allowed if wildcards ( '*' or '+' ) are used in the input fields. If wildcards are entered on the selection screen, the system automatically uses the operator CP. The escape character is defined as #.

– If HIGH is filled, you can use BT (BeTween) and NB (Not Between). These operators correspond to BETWEEN and NOT BETWEEN that you use when you check if a field belongs to a range. You cannot use wildcard characters.

LOW

The data type of LOW is the same as the column type of the database table, to which the selection criterion is linked.

– If HIGH is empty, the contents of LOW define a single field comparison. In combination with the operator in OPTION, it specifies a condition for the database selection.

– If HIGH is filled, the contents of LOW and HIGH specify the upper and lower limits for a range. In combination with the operator in OPTION, the range specifies a condition for the database selection.

HIGH

The data type of HIGH is the same as the column type of the database table, to which the selection criterion is linked. The contents of HIGH specify the upper limit for a range selection.

If the selection table contains more than one row, the system applies the following rules when creating the complete selection criterion:

Form the union of sets defined on the rows that have SIGN field equal to I (inclusion).

Subtract the union of sets defined on the rows that have SIGN field equal to E (exclusion).

If the selection table consists only of rows in which the SIGN field equals E, the system selects all data outside the set specified in the rows.

Read only

Former Member
0 Likes
3,472

Hi Victor,

<b>Select-options :</b>

This is used in the selection screen when you need to<b> enter a range of values for an input </b>field.

For example:

When u need to enter a date range, you can use the select-options.

Declaration of select-options.

<b>data : so_date type sy-datum.</b>

With this,

in the select statement , we can select the records which lie in the date range given in the select options.

Regards,

Thasneem

Hope this helps u.

reward if useful

Read only

Former Member
0 Likes
3,472

Hi viks,

SELECT OPTION is nothing but an <b>internal table</b> with these fields

1. sign ( Including OR Excluding )

2.option ( LT,GT,LE,NE,EQ,GE.....)

3.low (Lower value)

4.high (Higher value).

SELECT OPTION is one of the beautiful feature provided by SAP for Complex Selection.

<b>

For detail desc. go through the following link :</b>

http://help.sap.com/saphelp_46c/helpdata/en/d3/2e974d35c511d1829f0000e829fbfe/frameset.htm

<b>

This info. is very helpful for you.

Reward all helpful answers.</b>

Regards,

V.Raghavender.

Read only

Former Member
0 Likes
3,472

victor,

You use the statement

SELECT-OPTIONS <seltab> for <f>.

to declare a selection table in the program that is linked to the <f> column of a database table, or to an internal <f> field in the program. A selection table is an internal table object of the standard table type that has a standard key and a header line. Selection tables are used to store complex selections using a standardized procedure. They can be used in several ways. Their main purpose is to directly translate the selection criteria into database selections using the WHERE addition in Open SQL statements.

In addition to selection tables that you create using SELECT-OPTIONS, you can use the RANGES statement to create internal tables that have the structure of selection tables. You can use these tables with certain restrictions the same way you use actual selection tables.

Structure of Selection Tables

The row type of a selection table is a structure that consists of four components: SIGN, OPTION, LOW, and HIGH. Each row of a selection table that contains values represents a sub-condition for the complete selection criterion. Description of the individual components:

SIGN

The data type of SIGN is C with length 1. The contents of SIGN determine for each row whether the result of the row condition is to be included in or excluded from the resulting set of all rows. Possible values are I and E.

– I stands for "inclusive" (inclusion criterion - operators are not inverted)

– E stands for "exclusive" (exclusion criterion - operators are inverted)

OPTION

The data type of OPTION is C with length 2. OPTION contains the selection operator. The following operators are available:

– If HIGH is empty, you can use EQ, NE, GT, LE, LT,CP, and NP. These operators are the same as those that are used for logical expressions. Yet operators CP and NP do not have the full functional scope they have in normal logical expressions. They are only allowed if wildcards ( '*' or '+' ) are used in the input fields. If wildcards are entered on the selection screen, the system automatically uses the operator CP. The escape character is defined as #.

– If HIGH is filled, you can use BT (BeTween) and NB (Not Between). These operators correspond to BETWEEN and NOT BETWEEN that you use when you check if a field belongs to a range. You cannot use wildcard characters.

LOW

The data type of LOW is the same as the column type of the database table, to which the selection criterion is linked.

– If HIGH is empty, the contents of LOW define a single field comparison. In combination with the operator in OPTION, it specifies a condition for the database selection.

– If HIGH is filled, the contents of LOW and HIGH specify the upper and lower limits for a range. In combination with the operator in OPTION, the range specifies a condition for the database selection.

HIGH

The data type of HIGH is the same as the column type of the database table, to which the selection criterion is linked. The contents of HIGH specify the upper limit for a range selection.

If the selection table contains more than one row, the system applies the following rules when creating the complete selection criterion:

Form the union of sets defined on the rows that have SIGN field equal to I (inclusion).

Subtract the union of sets defined on the rows that have SIGN field equal to E (exclusion).

If the selection table consists only of rows in which the SIGN field equals E, the system selects all data outside the set specified in the rows.

RANGES tables

You can use the following variants of the TYPES and DATA statements to create internal tables of the same type as selection tables.

TYPES|DATA <rangetab> TYPE RANGE OF <type>.

or

TYPES|DATA <rangetab> LIKE RANGE OF <obj>.

This defines internal standard tables whose line type is a structure as follows:

SIGN(1) TYPE C

OPTION(2) TYPE C

LOW TYPE <type> bzw. LIKE <obj>

HIGH TYPE <type> bzw. LIKE <obj>

You can also use the RANGES statement to create internal tables of the same type as selection tables.

RANGES <rangetab> FOR <f>.

This statement is simply a shortened form of the following statements:

DATA: BEGIN OF <rangetab> OCCURS 0,

sign(1) TYPE c,

option(2) TYPE c,

low LIKE <f>,

high LIKE <f>,

END OF <rangetab>.

Because the statement represents an obsolete form of defining internal tables with headers and headers should not to be used, you should use above variants of TYPES and DATA statements instead of RANGES.

Tables defined in this way have the same structure as selection tables, but they do not have the same functionality. They are not part of the selection screen: No corresponding input fields are generated and these tables cannot be used as a data interface in a program <prog> called using

SUBMIT <prog> WITH <rangetab> IN <table>.

. However, you can use the above statements to create the table <table> in the calling program. The main function of these tables is to pass data to the actual selection tables without displaying the selection screen when executable programs are called.

The above tables are like actual selection tables in the WHERE clause of Open SQL statements and can be used in combination with the IN operator in logical expressions, but they are not linked to a database table. They:

are not passed like selection criteria to logical databases

cannot be used with the shortened form of selection tables in logical expressions

cannot be used like selection criteria in GET events

Obsolete version:

REPORT demo_sel_screen_tables_ranges.

RANGES s_carrid1 FOR spfli-carrid.

s_carrid1-sign = 'I'.

s_carrid1-option = 'EQ'.

s_carrid1-low = 'LH'.

APPEND s_carrid1.

SUBMIT demo_selection_screen_ldb_1 WITH carrid IN s_carrid1

VIA SELECTION-SCREEN AND RETURN.

Korrekte Version:

REPORT demo_sel_screen_tables_ranges.

DATA: s_carrid2 TYPE RANGE OF spfli-carrid,

s_carrid2_wa LIKE LINE OF s_carrid2.

s_carrid2_wa-sign = 'I'.

s_carrid2_wa-option = 'EQ'.

s_carrid2_wa-low = 'AA'.

APPEND s_carrid2_wa TO s_carrid2.

SUBMIT demo_selection_screen_ldb_1 WITH carrid IN s_carrid2

VIA SELECTION-SCREEN AND RETURN.

A selection table S_CARRID is created with reference to column CARRID of database table SPFLI. Fields S_CARRID-LOW and S_CARRID-HIGH have the same type as CARRID. The work area of the internal table S_CARRID is filled and appended to the table. Program DEMO2 is called. If DEMO2 is linked to logical database F1S, its selections screen contains the fields of selection criterion CARRID from the logical database. These fields are filled with the contents of the internal table.

Don't forget ot reward if useful...

Read only

Former Member
0 Likes
3,472