LOOP AT ITAB用法

文章目录

      • 1 loop at itab

1 loop at itab

Syntax

LOOP AT itab result [cond].

ENDLOOP.

Effect

The LOOP and ENDLOOP statements define a loop around a statement block. The LOOP statement reads lines from internal table itab sequentially. You can either read all the lines or specify conditions cond to restrict which lines to read. The output result determines when and where the line contents are read. The statement block between LOOP and ENDLOOP is executed once for each line. To exit processing of the statement block , you can use the statements described in Section leave loops.

The sequence in which the lines are read depends on the table type:

• Standard tables and sorted tables
The lines are read by ascending table index.

• Hashed Tables
The lines are processed in the sequence in which they were inserted in the table, and in the sort sequence following use of the SORT statement.

The loop continues to run until all the table lines that meet conditition cond have been read or until it is exited with a statement. If no appropriate lines are found or if the internal table is blank, the loop is not run at all.

System Fields
The LOOP ATstatement sets system field sy-tabix to the table index of the current table line for Standard tables and sorted Tables, and to 0 for Hashed-Tables, after every loop pass. It leaves sy-subrc unchanged. When the loop is exited with ENDLOOP, sy-tabix is reset to the value it had before the loop was entered, and the following applies sy-subrc:
sy-subrc Relevance
0 The loop was run at least once.
4 The loop was not run at all.

Changing Internal tables in a loop

If you insert or delete lines in the statement block of a LOOP , this will have the following effects:

• If you insert lines behind the current line, these new lines will be processed in the subsequent loop passes. An endless loop can result.

• If you delete lines behind the current line, the deleted lines will no longer be processed in the subsequent loop passes.

• If you insert lines in front of the current line, the internal loop counter is increased by one with each inserted line. This affects sy-tabix in the subsequent loop pass.

• If you delete lines in front of the current line, the internal loop counter is decreased by one with each deleted line. This affects sy-tabix in the subsequent loop pass.


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部