You are currently viewing AS400 CLP How to Loop

AS400 CLP How to Loop

I will discuss about using looping on AS400. If in other programming we can use the for, do-while or other functions. Looping on the CLP AS400 uses the LABEL function and IF function.

PGM                                                               
             DCL        VAR(&COUNTER) TYPE(*DEC) LEN(2) VALUE(1)  
             DCL        VAR(&PRINT) TYPE(*CHAR) LEN(2)            
                                                                  
 LOOP:       IF         COND(&COUNTER = 10) THEN(GOTO CMDLBL(EOP))
             ELSE       CMD(DO)                                   
             CHGVAR     VAR(&PRINT) VALUE(&COUNTER)               
             SNDPGMMSG  MSG(&PRINT)                               
             CHGVAR     VAR(&COUNTER) VALUE(&COUNTER + 1)         
             ENDDO                                                
             GOTO       CMDLBL(LOOP)                              
 EOP:        ENDPGM                                                                                        

Compile and run the program.

Leave a Reply