‎2008 May 08 11:09 AM
Hi experts,
I am new to sap i want to know
Difference Between Select-Options & Ranges ,,, with example code,,
‎2008 May 08 11:11 AM
hi,
What are the difference between SELECT-OPTIONS & RANGES?
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.
Regards,
Shiva.
‎2008 May 08 11:11 AM
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.
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.
Check the link
https://forums.sdn.sap.com/click.jspa?searchID=11573205&messageID=1372432
Regards,
Balaji.
‎2008 May 08 11:13 AM
Try this link
http://www.sap-img.com/abap/difference-between-select-options-ranges.htm
Maybe those cutting and pasting from the link should at least give credit to the originator of their reply?
Edited by: Kevin Bowmer on May 8, 2008 11:16 AM
‎2008 May 08 11:13 AM
Difference Between Select-Options & Ranges
What are the difference between SELECT-OPTIONS & RANGES?
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.
‎2008 May 08 11:14 AM
Hi G.K,
SELECT-OPTIONS - On the selection screen, you can declare RANGES on the selection screen.
RANGES - Inside the program, if you want to have variable with RANGES option, use the RANGES variable. You cannot declare and use SELECT-OPTIONS inside the program.
Check the below theard
https://forums.sdn.sap.com/click.jspa?searchID=11573054&messageID=5312328
http://www.sap-img.com/abap/difference-between-select-options-ranges.htm \
Regards
Kiran Sure
‎2008 May 08 11:14 AM
Tecnically select-options and ranges are same. When the perticular element is not a selection-screen element then we use ranges.
In case of select-option, the selection-option table get created autometically ( Containings the fields sign, option, high, low) when you populate the select option from selection screen. But in case of ranges you need to populate the range table by your coding.
afther population , the range table and selection-option table behave similarly.
‎2008 May 08 11:15 AM
hi,
It is one and the same. Ranges is a global internal table with a header line, the columns SIGN, OPTION, LOW and HIGH and the name of a selection criterion. It is used for the internal storage of selection conditions. Declared with the statement SELECT-OPTIONS; it can be evaluated in logical expressions using the language element IN.
regards,
madhumitha
‎2008 May 08 11:19 AM
Hi,
Functionality wise there is no difference except SELECT-OPTIONS are visible in the selection screen while Ranges are not visible.
Both have same structure.
One restriction in Ranges is u can't use Range in Select query if it has more than 2000 entries.
Ranges are used just like we use temporary internal tables.
eg: If u want to check for say 10 ranges in select query for some field which is not there in ur selection screen then u will populate the ranges and use it in the select query. Syntax will remain same as select option.
RANGES: r_vbeln FOR vbak-vbeln.
r_range-sign = 'I'.
r_range-option = 'BT'.
r_range-low = 123.
r_range-high = 321.
APPEND r_range.
like this append all the ranges u want.
SELECT field list FROm vbak INTO TABLE i_vbak
WHERE vbeln IN r_vbeln.
Hope this is clear.
Thanks,
Vinod.
Thanks,
Vinod.