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

Doubt about RANGES

Former Member
0 Likes
780

Hi all.

1) I need list out which records already exits in database table (ALV report) depending upon user input(screen has 5 input field like Empno,Brance,job,joining date,Dob) by one single select statement.

2) please give some idea abt RANGES

Thanks.

Jay.

6 REPLIES 6
Read only

Former Member
0 Likes
740

ranges are like select-option only you have to define it programmitacly

ranges : r_matnr for mara-matnr.

r-matnr-sign = 'I'.

R_MATNR-OPTION = 'EQ'.

R_MATNR-LOW = '004500'.

APPEND R_MATNR.

LIKE THIS YOU HAVE TO USE SAME WAY IN SELECT QUERY ALSO.

BUT THE DIFFERENCE IT WILL NOT APPEAR AT THE SELECTION SCREEN. SO USER CANNOT GIVE THE INPUT BUT YOU HAVE TO SPECIFY VALUE IN YOUR PROGRAM ITSELF.

Read only

Former Member
0 Likes
740

well it wont work.

if you need to list out all the records matching your selection criteria which already are in DB, you cant use a SELECT SINGLE since it only will give you ecactly one record, or even zero.

Ranges are internal tables with a special definition.

the have 4 fields, Sign, Option, Low, High.

Sign stores the operator you want to use to compare records, while option stores the compare method like "<" or "NE" or "CS".

Read only

seshatalpasai_madala
Product and Topic Expert
Product and Topic Expert
0 Likes
740

Hi,

1) I think what you need to check is execute the select statement and then use sy-dbcnt to find out the number of records returned. Then you can check aginst the number of records you are expecting may be size of the select options.

2) RANGES is used to create a data structure similar to the one created by SELECT-OPTIONS. Only difference is you will not have any screen fields.

You can also use TYPE RANGE OF instead of RANGES.

Regards,

Sesh

Read only

0 Likes
740

Hi Sesh,

Could you send me the sample code for RANGES with SELECT-OPTIONS.

Regards,

Rajesh

Read only

0 Likes
740

Hi,

DATA: spfli_wa TYPE spfli,

r_carrid TYPE RANGE OF spfli-carrid,

r_carrid_line LIKE LINE OF r_carrid.

SELECT-OPTIONS: sel_opt for spfli-carrid.

loop at sel_opt into r_carrid_line.

append r_carrid_line to r_carrid.

endloop.

Now if you want to send the data to any function module then this r_carrid is useful since you cannot send SELECT-OPTIONS directly.

Regards,

Sesh

Read only

Former Member
0 Likes
740

hi

good

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(1) type c,

OPTION(2) 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.

thanks

mrutyun^