SAP ABAP provides specific loop control keywords that help in managing the flow of loop iterations efficiently. These are especially useful when dealing with conditional logic inside DO, WHILE, or LOOP AT statements.
π 1. CONTINUE
π Description:
The CONTINUE statement skips the current loop iteration and moves to the next iteration of the loop.
πΉ Syntax:
πΉ Example:
πΈ Output:
π§ Explanation: Only even numbers are printed because CONTINUE skips the iteration if the number is odd.
✅ 2. CHECK
π Description:
The CHECK statement evaluates a condition and:
-
If true, continues with the current loop pass.
If false, skips the current iteration.
πΉ Syntax:
πΉ Example:
πΈ Output:
(No output)
π§ Explanation: Since rem = 2 is never true (MOD 2 will only result in 0 or 1), the CHECK condition always fails, so no iterations write to the screen.
π 3. EXIT
π Description:
The EXIT statement immediately terminates the entire loop, regardless of its iteration state.
πΉ Syntax:
πΉ Example:
πΈ Output:
π§ Explanation: Once SY-INDEX reaches the value of n (10), the loop stops executing entirely.
π§Ύ Summary Table
| Keyword | Behavior | Effect |
|---|---|---|
CONTINUE | Skips current iteration | Moves to the next loop pass |
CHECK | Evaluates a condition | Continues if true, skips if false |
EXIT | Terminates entire loop | No further iterations are executed |
These keywords are extremely useful for optimizing loop logic, especially in performance-sensitive programs. Use them wisely to make your ABAP code clean and efficient.
No comments:
Post a Comment