Summary -
In this topic, we described about the below sections -
CHECK statement is used to execute the set of statements code coded under CHECK statement when the specified check-condition is true.
If check-condition condition is true, then the set of statements under the CHECK statement are executed and control passes to the next iteration. Otherwise, the set of statements under the CHECK statement are just ignored and control passes to the next iteration.
CHECK statement is a conditional loop control statement. CHECK statement can't terminate the loop and only bypasses the set of statements under it when check-condition is false.
CHECK statement should be coded with period (.). CHECK statement check-condition can be any logical expression.
Syntax -
CHECK [Check-Condition].
Below diagram decribes the flowchart of CHECK statement -
- Looping condition - Specifies the condition with loop statement(DO/WHILE).
Execution process -
Step1 - If the looping condition is true, then CHECK condition gets validated.
Step2 - If CHECK condition is true, statements-block2 gets executed and control transfers to validate looping condition again.
Step3 - If CHECK condition is false, statements-block1 gets executed and control transfers to validate looping condition again.
Step4 - step-1 to step-3 gets executed repeatedly until the loopking condition is false.
Step5 - If looping condition is false, statements-block3 gets executed and control transfers to next executable statements if any.
Example -
Below example shows how the CHECK statement coded in the application program.
Code -
*&---------------------------------------------------------------------*
*& Report Z_CHECK
*&---------------------------------------------------------------------*
*& Written by TutorialsCampus
*&---------------------------------------------------------------------*
REPORT Z_CHECK.
* Declaring Variable
DATA: W_I TYPE I VALUE 0.
* DO loop iterates 10 times
DO 10 TIMES.
* incrementing Iteration number
W_I = W_I + 1.
* Verifies the condition
CHECK W_I BETWEEN 5 AND 7.
* Executes only when CHECK Condition is true
WRITE : /'Iteration ',W_I.
ENDDO.
Output -
Explaining Example -
In the above example, each and every statement is preceeded with a comment to explain about the statement. Go through them to get clear understanding of example code.
DO 10 TIMES, iterates loop 10 times. W_I = W_I + 1, used to display the iteration number for understanding and have no impact on loop iteration.
CHECK W_I BETWEEN 5 AND 7 condition satisfies, 'Iteration ' text with iteration number gets displayed. So, the iteration numbers gets displayed only for iteration numbers 5, 6 and 7.