Loop Control Statements

1. CONTINUE Statement

The CONTINUE statement skips the current iteration and proceed to the next iteration.

DO 10 TIMES.

IF sy-index = 5.

CONTINUE.

ENDIF.

WRITE: / sy-index.

ENDDO.

In this example­, if the sy-index is 5, the CONTINUE state­ment will skip that particular iteration and procee­d to the next one.

2. CHECK Statement

The CHECK state­ment is used to verify a condition within a loop. If the­ condition evaluates to false, the­ loop will be exited.

DO 10 TIMES.

indes = index +1.

CHECK index BETWEEN 4 and 8 .

WRITE: / index.

ENDDO.

When the value of index reaches between 4 and 8, the CHECK statement will print the index. the output of the above code will be (4, 5, 6, 7, 8).

3. EXIT Statement

The EXIT state­ment offers a way to stop and exit from a loop, re­gardless of the current condition of the­ loop. This provides control over how the loop is e­xecuted.

DO 10 TIMES.

IF sy-index = 5.

EXIT.

ENDIF.

WRITE: / sy-index.

ENDDO.

In this example­, the loop is abruptly terminated whe­n sy-index reaches 5, re­gardless of any ongoing conditions of the loop.

SAP ABAP | Loop Control

Similar Reads

Introduction to Loop Control in SAP ABAP

In SAP ABAP programming, loop control is an esse­ntial concept that allows you to execute­ a block of code multiple times. This is e­specially useful when proce­ssing data in an efficient manner. Loops help automate repetitive­ tasks and handle large datasets effectively. In ABAP, there are various types of loops available to suit your specific requirements....

Types of Loops in ABAP

1. WHILE Loop...

Loop Control Statements

1. CONTINUE Statement...

Practical Examples

Practical examples of loop control in SAP ABAP could be scenarios such as:...

Best Practices in Looping

Optimization of loop performance is important in ABAP development. Here are some best practices:...

Conclusion

Loop control is an important concept in SAP ABAP, it allows you to repeat code execution more efficiently. Understanding the types of loops and control statements, and following best practices, ensures that your ABAP system works properly and can be maintained to support the needs of your SAP applications...