Application Development 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: 

range's

Former Member
0 Kudos

HOW TO POPULATE THE RANGES IN PROGRAM

10 REPLIES 10

Former Member
0 Kudos

ASSIGN - range_spec

Syntax

... { }

| {RANGE range}.

Alternatives:

1. ... { }

2. ... RANGE range

Effect

The range_spec specification defines the area limits within which a storage area can be assigned to the field symbol. Either there is no specification or you specify the RANGE addition.

At the same time, the statement ASSIGN assigns these area limits to the field symbol <fs>. If the field symbol <fs> is itself used in a subsequent ASSIGN statement to specify a storage area mem_area, the assigned storage areas in Unicode programs are used for determining the area limits of the field symbol that is followed by the assignment (see below).

Note

The area limits assigned in a field symbol using range_spec only apply to the following ASSIGN statements. In other statements, with the exception of ADD UNTIL, the general rules apply.

Alternative 1

... { }

Effect

Effect in Unicode Programs

If there is no specification made for range_spec, the area limits in Unicode programs are defined as follows:

If you have specified an elementary data object for dobj in mem_area, the storage area of this data object determines the area limits.

If you have specified a field symbol for dobj in mem_area, and this field symbol has an elementary data object assigned to it, the field symbol <fs> of the current statement takes on the area limits assigned to this field symbol.

If you have a structure or a field symbol specified for dobj in mem_area, and one of these points to a structure, the system checks whether the structure has a character-type initial section (up to the first alignment gap). This then determines the area limits.

If these area limits are exceeded, no storage area is assigned for the static variant of mem_area after the ASSIGN statement. Also, the logical expression <fs> IS ASSIGNED is incorrect, while sy-subrc is set to 4 in the dynamic variant

Effect in Non-Unicode Programs

If no specification is made for range_spec, the area limits in non-Unicode programs are defined as follows:

If the name of a data object is not specified directly in the specification of the storage area mem_area, , the area limits are determined by the data area of the ABAP program.

If the name of a data object is specified dynamically for the specification of the storage area mem_area, the area limits are determined by the dynamically specified data object.

If these area limits are exceeded, an exception that cannot be handled will be triggered.

Notes

If the area limits are the same as the data area of the ABAP program, you must ensure that this data area also contains the administration information for deep data objects because otherwise errors could occur if these are exceeded unintentionally.

Up to Release 6.10, the specification of range_spec was not possible. The area limits were independent of the name of the data object and were determined by the data area of the ABAP program. If the data area of the ABAP program has been exceeded, it can trigger an exception that cannot be handled.

Example

In the first ASSIGN statement, the area limits of the data object text are assigned to <fs1>. In the second ASSIGN statement, <fs2> takes on these limits. Starting from the second loop run, the system will attempt to assign a larger storage area to <fs2>. However, in Unicode programs, the logical expression after IF is no longer true, while in non-Unicode programs the larger storage area is assigned.

DATA text TYPE c LENGTH 8 VALUE '12345678'.

FIELD-SYMBOLS: <fs1> TYPE ANY,

<fs2> TYPE ANY.

ASSIGN text+3(3) TO <fs1>.

DO 8 TIMES.

ASSIGN <fs1>(sy-index) TO <fs2>.

IF <fs2> IS ASSIGNED.

WRITE / <fs2>.

ENDIF.

ENDDO.

Alternative 2

... RANGE range

Effect

If the RANGE addition is specified in range_spec, the area limits are limited by the data area of a data object range. For range, a data object of any data type must be specified. It must cover the area limits that result in Unicode programs if the RANGE addition is not specified (see above). If the runtime is defined so that range does not cover these area limits, an exception that cannot be handled can be triggered.

If the RANGE addition is used, only subareas of the range data object can be assigned to the field symbol. If these area limits are exceeded, no storage area is assigned in the static variant of mem_area after the ASSIGN statement (the logical expression <fs> IS ASSIGNED is incorrect), while sy-subrc is set to 4 in the dynamic variants.

Example

The struc structure is built from ten components col1_1, col2_1, ..., col1_5, col2_5. The ASSIGN statement assigns the storage area of two neighboring components to the structure-typed field symbol <sub>, one after the other. Here the storage area is determined by the common name of the first two components comp1 in the structure struc and the specification of INCREMENT. Without the RANGE addition, the WHILE loop would only run once in Unicode programs since it would only be possible to access the storage area of struc-comp1. The loop is run through five times with the RANGE addition. After the assignment, the system can access the components of the field symbol.

TYPES: BEGIN OF sub_struc,

col1 TYPE c LENGTH 10,

col2 TYPE c LENGTH 10,

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.

TYPES: BEGIN OF sub_struc,

col1 TYPE c LENGTH 10,

col2 TYPE c LENGTH 10,

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.

Message was edited by:

Karthikeyan Pandurangan

former_member223537
Active Contributor
0 Kudos
REPORT report2. 

DATA: text       TYPE c LENGTH 10, 
      rspar_tab  TYPE TABLE OF rsparams, 
      rspar_line LIKE LINE OF rspar_tab, 
      range_tab  LIKE RANGE OF text, 
      range_line LIKE LINE OF range_tab. 

 

rspar_line-selname = 'SELCRIT1'. 
rspar_line-kind    = 'S'. 
rspar_line-sign    = 'I'. 
rspar_line-option  = 'EQ'. 
rspar_line-low     = 'ABAP'. 
APPEND rspar_line TO rspar_tab. 

range_line-sign   = 'E'. 
range_line-option = 'EQ'. 
range_line-low    = 'H'. 
APPEND range_line TO range_tab. 

range_line-sign   = 'E'. 
range_line-option = 'EQ'. 
range_line-low    = 'K'. 
APPEND range_line TO range_tab. 

SUBMIT report1 USING SELECTION-SCREEN '1100' 
               WITH SELECTION-TABLE rspar_tab 
               WITH selcrit2 BETWEEN 'H' AND 'K' 
               WITH selcrit2 IN range_tab 
               AND RETURN.

Former Member
0 Kudos

Can you give some detail as what is your need.

Regards,

Atish

0 Kudos

i have some set of values , i have to create range and by using submit statement i have to pass that details .so can u pls help for this

0 Kudos

Hi,

Just Use

r_tab-sign = 'I'.

r_tab-option = 'EQ'.

r_tab-low = <value>.

APPEND r_tab.

In this way append ranges with your values.

Regards,

Atish

0 Kudos

HI I USED RENGES IN SUBMIT STATEMENT BUT NEXT TIME IF I PROCESSED GETTING SAME OUTPUT WHAT I GOT PREVIOULY CAN U HELP ME

0 Kudos

Hi ...

To avoid this problem you have to REFRESH the RANGEs Table after the Submit.

<<fill Ranges table>>

SUBMIT <REPORT> .................

<b>REFRESH R_EBELN. "Refresh the Ranges table</b>

Then it works properly.

REWARD IF HELPFUL.

Former Member
0 Kudos

Ranges work in the same way as select option.

Rages: R_matnr for mara-matnr.

r_matnr-sign = 'I'. "Sign can Be I for Inclusive, E for ExclusiVe

r_matnr-option = 'BT'. "EQ = Equal, BT = Between, LT = Less than etc...

r_matnr-low = '0000000010'.

r_matnr-high = '0000000100'.

append r_matnr.

Reward is useful.

former_member404244
Active Contributor
0 Kudos

Hi,

check the below link.

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

Reward if helpful.

Regards,

Nagaraj

Former Member
0 Kudos

Hi

Define a range:

Ranges: r_field for <table>.

if not field1 is initial.

r_field-sign = 'I'.

r_field-option = 'EQ'.

r_field-option-low = field1.

append r_field.

endif.

if not field2 is initial.

r_field-sign = 'I'.

r_field-option = 'EQ'.

r_field-option-low = field2.

append r_field.

endif.

if field1 is initial and field2 is initial.

r_field-sign = 'I'.

r_field-option = 'EQ'.

append r_field.

endif.

select * from <table> where field1 in r_field.

The 'I' value in the SIGN field denotes 'Include', that means to Include the values given in the LOW and HIGH fields.

U may use 'E' here to exclude these values, when u r using the range in a SELECT query.

1. select-options is for screen.

2. If we dont want to display anything on screen,

we can use RANGES

having the same functionality

and us it

in sql using IN statement.

<b>Reward if usefull</b>