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

ranges

Former Member
0 Likes
1,220

Hi could anyone explain what are the step to use ranges .

How to do the declaration and write the perform

And give me in what circumstances you can use ranges

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,053

Hi,

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.

Difference between select-options and Ranges: -

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

Reward points for helpful answers.

Regards,

hari krishna

7 REPLIES 7
Read only

Former Member
0 Likes
1,054

Hi,

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.

Difference between select-options and Ranges: -

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

Reward points for helpful answers.

Regards,

hari krishna

Read only

Former Member
0 Likes
1,053

hi,

<a href="http://www.sap-img.com/abap/difference-between-select-options-ranges.htm">Difference Between Select-Options & Ranges</a>

check this thread for more info..

Cheers

Alfred

Read only

Former Member
0 Likes
1,053

Hi,

Ranges and select-options both are same for declaration but main difference is

when u declare ranges it won't appear in selection screen.

where as in select-options it will show selection screen for entering values.

<b>reward me a points if it use full answer.</b>

praveen

Read only

Former Member
0 Likes
1,053

Hi,

The ranges are like the select-options ... you can declare the ranges as follows...

Ranges: r_matnr for mara-matnr.

Where you exactly use this ranges means when ever there is a requirement for the range or set of value to restrict the selection of reocrds...

means you can use the ranges in the same way how you can use select-options...

Ex:RANGES: r_eqtyp FOR equi-eqtyp.

MOVE: 'I' TO r_eqtyp-sign,

'EQ' TO r_eqtyp-option,

value1 TO r_eqtyp-low.

APPEND r_eqtyp.

MOVE: 'I' TO r_eqtyp-sign,

'EQ' TO r_eqtyp-option,

value2 TO r_eqtyp-low.

APPEND r_eqtyp.

SELECT equnr eqtyp eqart objnr FROM equi INTO TABLE it_equi

FOR ALL ENTRIES IN t_mpos

WHERE equnr = t_mpos-equnr

AND eqtyp IN r_eqtyp.

Satya.

Read only

Former Member
0 Likes
1,053

hi

jus try this

selection-screen : begin of block blk1 with frame title text-001.

select-options : s_werks for marc-werks obligatory.

selection-screen : end of block blk1.

data : p_werks like s_werks default value '0010'.

p_werks-sign = 'WERKS'.

p_werks-option = 'EG'.

p_werks-low = '0010'.

p_werks-high = '0100'.

REWARD IF USEFUL...!!

Read only

varma_narayana
Active Contributor
0 Likes
1,053

Hi

Ranges will create the Same type of internal table as Select-options (with the fields SIGN, OPTION, LOW, HIGH) .

So we can store the selection criteria in the Ranges.

But Ranges will not any Element in the selection screen.

Eg: This is a typical example where we can use RANGES

TABLES: MARC.

SELECT-OPTIONS S_PLANT FOR MARC-PLANT.

RANGES: R_PLANT1 FOR MARC-PLANT. "To Store plants with authorization

RANGES: R_PLANT2 FOR MARC-PLANT. "To Store plants without authorization

START-OF-SELECTION.

LOOP AT S_PLANT.

**Check the authorization sampe code

AUTHORITY-CHECK 'PLANT'.

if SY-SUBRC = 0.

APPEND S_PLANT TO R_PLANT1.

ELSE.

APPEND S_PLANT TO R_PLANT2.

ENDIF.

ENDLOOP.

select * from MARC INTO TABLE ITAB WHERE WERKS IN R_PLANT1.

<b>Reward if Helpful.</b>

Read only

Former Member
0 Likes
1,053

Hi Newbie82,

Ranges would be defined in the data section of your program. See below:

<b><i>RANGES r_vkorg FOR vbak-vkorg.</i></b>

It will provide a data structure of the same type as a select-option. See below:

<i><b>DATA: BEGIN OF r_vkorg OCCURS {10|n},

sign TYPE c LENGTH 1,

option TYPE c LENGTH 2,

low LIKE dobj,

high LIKE dobj,

END OF r_vkorg.</b></i>

You can populate this structure with the same values as within a select-option and use it in your SQL. See example below.

<b><i>move: 'I' to r_vkorg-sign,

'EQ' to r_vkorg-option,

'SO01' to r_vkorg-low. append r_vkorg.

move: 'I' to r_vkorg-sign,

'BT' to r_vkorg-option,

'SO05' to r_vkorg-low.

'SO09' to r_vkorg-low.append r_vkorg.

select vbeln from vbak into lt_vbeln

where vkorg in r_vkorg.</i></b>

This will return orders with a sales organization of SO01 or between SO05 and SO05. You can also use as you would any select-option e.g. in a Check statement.

<b><i>Check vbak-vkorg in r_vkorg</i></b>