AS400 CLP IF-ELSE Function

IF-ELSE or IF on AS400 is no different from other programming languages. Following is the use of the IF-ELSE function on AS400:

PGM                                                                 
             DCL        VAR(&DATA1) TYPE(*DEC) LEN(1) VALUE(1)      
             DCL        VAR(&DATA2) TYPE(*CHAR) LEN(5) VALUE('YES') 
                                                                    
/* IF USING DECIMAL VARIABLE */                                     
             IF         COND(&DATA1 = 1) THEN(SNDPGMMSG MSG('Value +
                          match'))                                  
             ELSE       CMD(SNDPGMMSG MSG('Value not match'))       
                                                                    
/* IF USING CHARACTER VARIABLE */                                   
             IF         COND(&DATA2 = 'YES') THEN(SNDPGMMSG +       
                          MSG('VALUE YES'))                         
             ELSE       CMD(SNDPGMMSG MSG('VALUE NOT YES'))         
                                                                    
/* IF USING CHARACTER - RETURN FALSE */                             
             IF         COND(&DATA2 = 'NO') THEN(SNDPGMMSG +        
                          MSG('VALUE YES'))                         
             ELSE       CMD(SNDPGMMSG MSG('FALSE VALUE'))           
ENDPGM                                                              

Compile and run the program.

Leave a Reply