ABAPDO_VARYING - DO VARYING
rdisp/max_wprun_time - Maximum work process run time Addresses (Business Address Services)This documentation is copyright by SAP AG.
DO - VARYING
Obsolete Syntax
DO ... VARYING dobj FROM dobj1 NEXT dobj2 [RANGE range]
[VARYING ...].
[statement_block]
ENDDO.
Effect
The VARYING addition assigns a new value to a dobj variable for each run of a DOloop. It can be used more than once in a DO statement.
dobj1 and dobj2 are the first two data objects in a sequence of data objects that are the same distance apart in the memory. The data types of data objects dobj, dobj1, and dobj2 must beflat.
In Unicode programs, dobj, dobj1, and dobj2 must becompatible.Furthermore, in Unicode programs, dobj1 and dobj2 must either be structure components that belong to the same structure, or subareas of the same data object specified by offset/length specifications.
In the first loop pass, the content of data object dobj1 is assigned to dobj. In the secondloop pass, the content of data object dobj2 is assigned. In the subsequent loops, dobjis assigned the content of the data object that is the same distance in the memory from the data object previously assigned, as dobj2 is from dobj1. Type conversion does not take place.
If the processing block is exited correctly using ENDDO, CHECK,or EXIT, the content of variable dobj is assigned to the data object previously assigned(dobj1 or dobj2) without conversion at the end of the loop pass. If it is exited usinga different statement such as RETURNor RAISE EXCEPTION, this assignment does not take place.
The RANGE addition determines the memory area that can be processed using the VARYINGaddition. After RANGE, an elementary data object range of type c, n, or x or a structure can be specified. The memory area of range must include those of dobj1 and dobj2. Indeepstructures, the deep components are excluded from the area permitted. The DO loop must be endedbefore non-permitted memory areas are accessed, that is, areas outside of range or its deep components. Otherwise, an untreatable exception may occur.
If RANGE is not specified explicitly, the memory area permitted is determined as follows:
- In non-Unicode programs, the permitted memory area of dobj1 extends to the limit of the currentdataarea of the ABAP program. If the RANGE addition is not specified, there is a danger of unintentionally overwriting the memory.
- In Unicodeprograms, RANGE can only be omitted if it can be statically determined that dobj1and dobj2 are components of the same structure. The memory area permitted is then determined from the smallest substructure that contains dobj1 and dobj2.
Note
: Instead of the VARYING addition, the ASSIGNstatement should be used in the loop with the INCREMENT addition.
Example
: In the first DO loop, subareas of data object text are processed by means of offset/lengthaccess. In Unicode programs, the RANGE addition must be specified here. In the second DOloop, the program accesses the components of data object text. In this case, it is not necessaryto specify RANGE. The third DO loop shows how the functions of the second loop can beprogrammed using the ASSIGN INCREMENT statement.
DATA: BEGIN OF text,
word1 TYPE c LENGTH 4 VALUE 'AAAA',
word2 TYPE c LENGTH 4 VALUE 'BBBB',
word3 TYPE c LENGTH 4 VALUE 'CCCC',
word4 TYPE c LENGTH 4 VALUE 'DDDD',
END OF text.
DATA: word TYPE c LENGTH 4,
char1 TYPE c LENGTH 1,
char2 TYPE c LENGTH 1,
leng TYPE i.
FIELD-SYMBOLS <word> LIKE text-word1.
DATA inc TYPE i.
DESCRIBE FIELD text LENGTH leng IN CHARACTER MODE.
leng = leng / 2.
DO leng TIMES VARYING char1 FROM text(1)
NEXT text+2(1) RANGE text
VARYING char2 FROM text+1(1)
NEXT text+3(1) RANGE text.
WRITE: char1, char2.
char1 = 'x'.
char2 = 'y'.
ENDDO.
DO 4 TIMES VARYING word FROM text-word1 NEXT text-word2.
WRITE / word.
ENDDO.
DO.
inc = sy-index - 1.
ASSIGN text-word1 INCREMENT inc TO <word> RANGE text.
IF sy-subrc = 0.
WRITE / <word>.
ELSE.
EXIT.
ENDIF.
ENDDO.
Exceptions
Non-Catchable Exceptions
- Cause: Illegal access todeep components within the area specified by the RANGE addition.
Runtime Error: DO_WHILE_VARY_ILLEGAL_ACCESS - Cause: Access to data outside the area specified by the RANGE addition.
Runtime Error: DO_WHILE_VARY_NOT_IN_RANGE
BAL_S_LOG - Application Log: Log header data ABAP Short Reference
This documentation is copyright by SAP AG.
Length: 8286 Date: 20120522 Time: 052040 triton ( 222 ms )






