Ansicht
Dokumentation

ABAPDO_VARYING - DO VARYING

ABAPDO_VARYING - DO VARYING

TXBHW - Original Tax Base Amount in Local Currency   Fill RESBD Structure from EBP Component Structure  
This documentation is copyright by SAP AG.
SAP E-Book

DO, VARYING

Short Reference



DO ... VARYING dobj FROM dobj1 NEXT dobj2 $[RANGE range$]
      $[VARYING ...$].
  $[statement_block$]
ENDDO.


Effect

The addition VARYING assigns a new value to a variable dobj for each pass of a DO loop. 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 dobj, dobj1, and dobj2 must be flat and compatible with each other. dobj1 and dobj2 must be parts of a flat data object. These parts are either structure components of the same structure or substrings of the same data object specified using offsets/lengths.

In the first loop pass, the content of the data object dobj1 is assigned to dobj. In the second loop pass, the content of the data object dobj2 is assigned. In the subsequent loop passes, dobj is assigned the content of the data object that is the same distance in the memory from the previously assigned data object, as dobj2 is from dobj1. There is no type conversion.

If the processing block is exited correctly using ENDDO, CHECK, or EXIT, the content of the variable dobj at the end of the loop pass is assigned to the previously assigned data object dobj1 or dobj2 without conversion. If it is exited using another statement, such as RETURN or RAISE EXCEPTION, no assignment takes place.

The addition RANGE defines the memory area that can be processed using the addition VARYING. 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 the memory range of dobj1 and dobj2. In deep structures, the deep components are excluded from the allowed area. The DO loop must be ended before forbidden memory areas are accessed, that is, areas outside of range or its deep components. If not, an uncatchable exception is raised.

The addition RANGE can be omitted only if it can be known statically that dobj1 and dobj2 are components from the same structure. The allowed memory area is then determined from the smallest substructure that contains dobj1 and dobj2.

Notes

  • The way the addition VARYING works depends on the internal layout of the working memory, which itself can be affected by alignment gaps.
  • Instead of the addition VARYING, the statement ASSIGN should be used in the loop with the addition INCREMENT.

Example

In the first DO loop, subareas of the data object text are processed using offset/length access. The addition RANGE must be specified here. In the second DO loop, the program accesses the components of the data object text. In this case, it is not necessary to specify RANGE. The third DO loop shows how the functions of the second loop can be programmed using the statement ASSIGN INCREMENT.

Exceptions

Non-Catchable Exceptions

  • Cause: Invalid access to deep components within the area specified by the RANGE-addition.
    Runtime Error: DO_WHILE_VARY_ILLEGAL_ACCESS
  • Cause: Access to data outside the range specified by the RANGE addition.
    Runtime Error: DO_WHILE_VARY_NOT_IN_RANGE






CPI1466 during Backup   Addresses (Business Address Services)  
This documentation is copyright by SAP AG.

Length: 5227 Date: 20240614 Time: 043350     sap01-206 ( 98 ms )