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

Difference between Select-options and ranges

Former Member
0 Likes
3,191

Can anyone explain me what is the difference between select-option and ranges.

Regards,

Phyrose.

8 REPLIES 8
Read only

Former Member
0 Likes
1,570

Here both SELECT-OPTIONS & RANGES works for the same purpose. They both are used for the range selection from selection screen. The main diff. between them is, while we use SELECT-OPTIONS system implicitly creates the select options internal table which contains the fields of SIGN,OPTION,LOW & HIGH. But in case of RANGES, this internal table should be defined explicitly.

Eg. to SELECT-OPTIONS :————————————————————-

REPORT YARSELECT.

TABLES YTXLFA1.

SELECT-OPTIONS : VENDOR FOR YTXLFA1-LIFNR.

INITIALIZATION.

VENDOR-LOW = 1000. ” It specifies the range starting value

VENDOR-HIGH = 2000. ” It specifies the range ending value.

VENDOR-OPTION = ‘BT’. ” specifies ranges value is in between.

VENDOR-SIGN = ‘I’. “specifies both inclussive.

APPEND VENDOR.

– - – - – - – -

SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB

WHERE LIFNR IN VENDOR.

Eg. to RANGES:————————————-

REPORT YARRANGE.

TABLES YTXLFA1.

RANGES: VENDOR FOR YTXFLA1-LIFNR.

– - – - – - -—- – - –

SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB

WHERE LIFNR IN VENDOR.

Here with RANGES user has to design an internal table with fields – SIGN,OPTION,LOW and HIGH EXPLICITLY.

————————————————————————————————————————————————————->

Example:

select-options: bukrs for zstock-bukrs.

Should the user fill in ‘ABFI’ in BUKRS on the selection screen, BUKRS will look like this:

IEQABFI

This is because BUKRS is set as a table as follows:

begin of bukrs occurs 0,

SIGN type c, OPTION type c, LOW like bukrs, HIGH like bukrs,

end of bukrs.

Now, when you create the following range, it will have the exact same fields set inside its table:

Ranges: bukrs for zstock-bukrs.

The difference is, because ranges doesn’t show on the selection screen, you will have to fill it yourself, meaning you will have to fill bukrs-sign, bukrs-option, bukrs-low & bukrs-high all manually.

Some tips:

Sign is always I (for Include) or E (for Exclude)

Option can be a whole range, which includes:

EQ (Equal)

BT (Between))

CP (Contain Pattern)

So let’s say you want to have the range check for all company codes not starting with AB, you will set your code as follow:

ranges: bukrs for zstock-bukrs.

bukrs-sign = ‘E’. “Exclude

bukrs-option = ‘CP’. “Pattern

bukrs-low = ‘AB*’. “Low Value

bukrs-high = ‘’. “High Value

append bukrs.

Always remember to APPEND your range when you fill it, as the WHERE clause checks against the lines of the range table, not against the header line.

Hope this explains it well enough.

————————————————————————————————————————————————————->

What does SIGN “I” & “E” mean?

The “I” stands for Include, and the “E” for Exclude.

The easiest way to learn how the range selections work is, create the following dummy program:

report dummy.

tables: mara.

select-options: matnr for mara-matnr.

start-of-selection.

loop at matnr.

write: / matnr-sign,

matnr-option, matnr-low, matnr-high.

endloop.

Run this program, and fill in a lot of junk into MATNR. Fill in some includes, some excludes, some ranges, etc., and you will soon realise how the system builds ranges (select-options). Once you know that, you can fill your own ranges quickly and efficiently.

Read only

0 Likes
1,570

· SELECT-OPTIONS: To declare an internal table that is also linked to input fields on a selection screen

· RANGES: To declare an internal table with the same structure as in SELECT-OPTIONS, but without linking it to a selection screen.

Read only

Former Member
0 Likes
1,570

SELECT-OPTIONS: Declare an internal table that is also linked to input fields on a selection screen

RANGES: Declare an internal table with the same structure as in select-options, but without linking it to a selection screen.

FOR FURTHER DOCUMENTATION PLEASE GO THROUGH THE LINK

http://72.14.203.104/search?q=cache:btyoj86smhEJ:www.sap-img.com/abap/difference-between-select-opti...Select-optionsandrangesIN+ABAP&hl=en&gl=in&ct=clnk&cd=1

Regards

Vasu

Read only

Former Member
0 Likes
1,570

IF you declare a variable with select-options it will be displayed in the selection screen..

A small difference between the two is that select-options can be used with the CHECK statement, while ranges cannot. This is documented for logical databases, but I have seen it used with select statements as well.

Otherwise both are same..

check out this link

http://www.sap-img.com/abap/difference-between-select-options-ranges.htm

Select-options are the normal select options that you define on Selection screen.

While Ranges are similar to Select options in the way it creates a internal table of the same form as that of Select-options. The internal table that is created has the fields

HIGH

LOW

SIGN

OPTION.

But the difference between Select-options and ranges are that we don't need to define the ranges in Selection screen. It is created by explicitly coding in the Program. (see Example below). And we can fill the internal table for ranges in the program code itself and then can use it in the same manner as we use Select-option of screen

Example: Here r_belnr is range while s_bukrs and s_gsber is Select-options.

Here i have defined a range and then filling it internally in the program coding and then using it in select query.

TYPES: ty_belnr TYPE RANGE OF bkpf-belnr.

DATA: r_belnr TYPE ty_belnr WITH HEADER LINE.

LOOP AT i_bkpf INTO wa_bkpf.

r_belnr-sign = 'I'.

r_belnr-option = 'EQ'.

r_belnr-low = wa_bkpf-belnr.

APPEND r_belnr.

ENDLOOP.

CLEAR r_belnr.

SELECT belnr

aufnr

FROM bseg

INTO TABLE i_bseg

FOR ALL ENTRIES IN i_aufk

WHERE bukrs IN s_bukrs

AND belnr IN r_belnr

AND gjahr EQ p_gjahr

AND gsber IN s_gsber

AND aufnr EQ i_aufk-aufnr.

Hope now u have got the difference between Select-options and ranges. Get back to me if u still ahve doubts.

Please give me reward points.

Thanks

Murali Poli

Read only

Former Member
0 Likes
1,570

Hi

Select-options is used mostly for the continuous range of values for a field on the selection screen.

Ranges is not used on selection screen, but is used to cumulate the values which are not in order and to club the values for that field and to use in where condition of select.

In both cases a Selection table with sign,option,low and High fields is created and stores the values

Regards

Anji

Read only

Former Member
0 Likes
1,570

A select-option is a table of selection values which permits both individual values and ranges as well as negative (i.e. not-equal-to) values of the same. This table can be defined with a RANGES statement. However, if the table is a parameter to a program a SELECT-OPTIONS statement must be used. SELECT-OPTIONS declares the parameter and defines the table automatically.

If you do need this option for a program parameter and only need a single-value parameter, a PARAMETERS statement is used.

Thus, program parameters are specified by either SELECT-OPTIONS or PARAMETERS.

Select options which are not parameters are defined by the RANGES statement.

Another way of explaining it would be to say simply that a select option is a range used as a parameter.

Read only

Former Member
0 Likes
1,570

hi

May be as per my knw,

In select-option you can provide minimun and max value.and fetch the data in between them.

range is generally used in loop it means upto what range we want to fetch the data if means that

Hera is one exp of range.

TYPES: BEGIN OF sub_struc,

col1(10) TYPE c,

col2(10) TYPE c,

END OF sub_struc.

DATA BEGIN OF struc.

INCLUDE TYPE: sub_struc AS comp1 RENAMING WITH SUFFIX _1,

sub_struc AS comp2 RENAMING WITH SUFFIX _2,

sub_struc AS comp3 RENAMING WITH SUFFIX _3,

sub_struc AS comp4 RENAMING WITH SUFFIX _4,

sub_struc AS comp5 RENAMING WITH SUFFIX _5.

DATA END OF struc.

FIELD-SYMBOLS <sub> TYPE sub_struc.

DATA inc TYPE i.

WHILE sy-subrc = 0.

inc = sy-index - 1.

ASSIGN struc-comp1 INCREMENT inc TO <sub> CASTING

RANGE struc.

IF sy-subrc = 0.

WRITE: <sub>-col1, <sub>-col2 ...

ENDIF.

ENDWHILE.

Read only

Former Member
0 Likes
1,570

Hi,

Select-options are the normal select options that you define on Selection screen.

While Ranges are similar to Select options in the way it creates a internal table of the same form as that of Select-options. The internal table that is created has the fields

HIGH

LOW

SIGN

OPTION.

But the difference between Select-options and ranges are that we don't need to define the ranges in Selection screen. It is created by explicitly coding in the Program. (see Example below). And we can fill the internal table for ranges in the program code itself and then can use it in the same manner as we use Select-option of screen

Example: Here r_belnr is range while s_bukrs and s_gsber is Select-options.

Here i have defined a range and then filling it internally in the program coding and then using it in select query.

TYPES: ty_belnr TYPE RANGE OF bkpf-belnr.

DATA: r_belnr TYPE ty_belnr WITH HEADER LINE.

LOOP AT i_bkpf INTO wa_bkpf.

r_belnr-sign = 'I'.

r_belnr-option = 'EQ'.

r_belnr-low = wa_bkpf-belnr.

APPEND r_belnr.

ENDLOOP.

CLEAR r_belnr.

SELECT belnr

aufnr

FROM bseg

INTO TABLE i_bseg

FOR ALL ENTRIES IN i_aufk

WHERE bukrs IN s_bukrs

AND belnr IN r_belnr

AND gjahr EQ p_gjahr

AND gsber IN s_gsber

AND aufnr EQ i_aufk-aufnr.

Hope now u have got the difference between Select-options and ranges. Get back to me if u still ahve doubts.

<b>Reward if useful</b>