Ansicht
Dokumentation

ABENITAB_LOOP_CHANGE - ITAB LOOP CHANGE

ABENITAB_LOOP_CHANGE - ITAB LOOP CHANGE

Vendor Master (General Section)   ROGBILLS - Synchronize billing plans  
This documentation is copyright by SAP AG.
SAP E-Book

- Changing Internal Tables in a Loop

Inserting and Deleting Lines

In the statement block of a LOOP control statement, the content of the currently processed internal table can be changed by inserting or deleting lines. The position of inserted or deleted lines with regard to the current line is determined by the line numbers in the corresponding table index in the case of loops across index tables or when using a sorted key. In the case of loops on hashed tables and when using a hash key, the position depends on the order of insertion or the order of lines that might have been established by a previous SORT statement for the table.

  • Inserting lines after the current line causes these new lines to be processed in the subsequent loop passes, which can produce an endless loop.
  • Deleting lines after the current line causes the deleted lines to no longer be processed in the subsequent loop passes.
  • Inserting lines in front of the current line causes the internal loop counter to be increased by one with each inserted line. This affects sy-tabix in the subsequent loop pass in the case of loops across index tables or when using a sorted key, and sy-tabix is increased accordingly.
  • Deleting the current line or lines in front of the current line causes the internal loop counter to be decreased by one with each deleted line. In the case of loops across index tables or when using a sorted key, this affects sy-tabix in the subsequent loop pass, and sy-tabix is decreased accordingly.

Replacing or Clearing the Entire Table Body

As a rule it is not allowed to replace or clear the entire table body of the currently processed internal table in the statement block of a LOOP statement. Such a write access to the table body can be achieved with statements such as CLEAR, FREE, LOCAL, REFRESH, SORT, DELETE ... WHERE, and with all types of assignments.

  • If known statically, clearing or replacing the table body inside a loop results in a syntax error in classes and for LOOP statements with a statically known secondary key. Outside classes and for tables without secondary key, the syntax check gives only a warning for compatibility reasons.
  • If it is not known statically, clearing or replacing the table body inside a loop raises the runtime error TABLE_FREE_IN_LOOP with the following exception: If the output behavior is defined with INTO or TRANSPORTING NO FIELDS, or with the obsolete short form, for compatibility reasons there is no runtime error but the loop is exited in an undefined way.

Since the result of replacing or clearing the entire table body within a loop can result in unpredictable program behavior, the exceptions to the rule should not be exploited.

Loop Processing

Replacing the table body of an internal table within a loop over that table. The syntax check reports errors in classes and warnings outside classes. While the loop with ASSIGNING results in the runtime error TABLE_FREE_IN_LOOP, the loop with INTO is executed without runtime error. The latter is shown for demonstration purposes, but not recommended.

Example

Deleting all lines of an internal table within a loop over that table. while the loop with ASSIGNING results in runtime error TABLE_FREE_IN_LOOP the loop with INTO is executed without runtime error. The latter is shown for demonstration purposes, but not recommended. Since the deletion happens in a method, it is not detected by the syntax check.






PERFORM Short Reference   CPI1466 during Backup  
This documentation is copyright by SAP AG.

Length: 4782 Date: 20240512 Time: 080757     sap01-206 ( 86 ms )