SAP ASSIGN RANGE ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• RANGE ASSIGN

ASSIGN, range_spec
Short Reference

ABAP_SYNTAX
... ${ $}
$| ${RANGE range$}.

ABAP_ALTERNATIVES:
1 ... ${ $}
2 ... RANGE range

What does it do?
The specification range_spec defines the area limits within which a memory area can be assigned to the field symbol. Either nothing can be specified here or the addition RANGE.
At the same time, the statement ASSIGN assigns these area limits to the field symbol <(><)>. If the field symbol <(><)> is itself used in a subsequent ASSIGN statement to specify a memory area mem_area , the assigned memory areas are used to determine the area limits of the field symbol to which the assignment is made.



Latest notes:

The area limits assigned to a field symbol using range_spec only apply to the following ASSIGN statements. In other statements the general rules apply.
NON_V5_HINTS
The exception is ADD UNTIL, where the general rules do not apply.
ABAP_HINT_END

ABAP Alternative 1 ... ${ $}

What does it do?
If no value is specified for range_spec, the area limits are defined as follows:
If an elementary data object was specified for dobj in mem_area, the memory area of this data object determines the area limits.
If a field symbol was specified for dobj in mem_area, and an elementary data object is assigned to it, the field symbol <(><)> of the current statement inherits the area limits assigned to this field symbol.
If a structure or a field symbol that points to a structure was specified for dobj in mem_area, the system checks whether the structure has a character-like initial part up to the first alignment gap. This then determines the area limits.
If these area limits are exceeded, no memory area is assigned for the static variant of mem_area after the ASSIGN statement and the predicate expression <(><)> IS ASSIGNED is false, while sy-subrc is set to 4 in the dynamic variant.

ABAP_EXAMPLE_VX5
In the first ASSIGN statement, the area limits of the data object text are assigned to < fs1>. In the second ASSIGN statement, < fs2> inherits these limits. From the sixth loop pass, an attempt is made to assign a larger memory area to < fs2> , which makes the logical expression after IF false.
ABEXA 00039
ABAP_EXAMPLE_END

ABAP Alternative 2 ... RANGE range

What does it do?
If the addition RANGE is specified in range_spec, the area limits are defined by the data area of the data object range. range expects a data object of any data type that covers the area limits that result when the RANGE addition is not specified (see above). If it is established at runtime that range does not cover these area limits, a catchable exception is raised.
When 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 memory area is assigned for the static variant of mem_area after the ASSIGN statement and the predicate expression <(><)> IS ASSIGNED is false, while sy-subrc is set to 4 in the dynamic variants.
The addition RANGE cannot be used with the addition CASTING TYPE HANDLE or for assigning table expressions.



Latest notes:

A RANGE addition does not remove the type-specific rules for substring accesses. To enable subfield access beyond the field limits of a specified data object dobj, subfield access must be possible in principle. In particular, substring access is never possible beyond the limits of a structure, since the character-like initial part would not be accessed.
If a structure is specified for range that contains dynamic data objects, they only contribute the internal reference to the data area of the structure. The actual data area of the dynamic data objects is paged out and is ignored by RANGE. This also applies to substructures that are declared as boxed components.
NON_V5_HINTS
ABAP_HINT_END

ABAP_EXAMPLE_VX
The struc structure is constructed from ten components col1_1 , col2_1, ..., col1_5, col2_5. The ASSIGN statement assigns the memory area of two neighboring components to the structure-typed field symbol < sub>, one after the other, whereby the memory 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 be run once since it is only possible to access the memory area of struc-comp1. With the RANGE addition the loop runs five times. The components of the field symbol can be accessed after the assignment.
ABEXA 00040
ABAP_EXAMPLE_END

ABAP_EXAMPLE_V5
The second dynamic assignment fails because the RANGE condition is violated.
ABEXA 01727
ABAP_EXAMPLE_END


Return to menu