You are currently viewing AS400 CLP Calculation

AS400 CLP Calculation

I will explain how to use calculations on AS400. The operations that I will explain this time are addition (+), subtraction (-), multiplication (*) and division (/).

Because I used SNDPGMMSG to get the written output in the log, I convert a decimal to character conversion.

PGM                                                          
             DCL        VAR(&DEC1) TYPE(*DEC) LEN(2) VALUE(6)
             DCL        VAR(&DEC2) TYPE(*DEC) LEN(2) VALUE(2)
             DCL        VAR(&CALC) TYPE(*DEC) LEN(2)         
             DCL        VAR(&OUTPUT) TYPE(*CHAR) LEN(2)      
                                                             
/* PLUS '+' SIGN */                                          
             CHGVAR     VAR(&CALC) VALUE(&DEC1 + &DEC2)      
             CHGVAR     VAR(&OUTPUT) VALUE(&CALC)            
             SNDPGMMSG  MSG(&OUTPUT)                         
                                                             
/* MINUS '-' SIGN */                                         
             CHGVAR     VAR(&CALC) VALUE(&DEC1 - &DEC2)      
             CHGVAR     VAR(&OUTPUT) VALUE(&CALC)            
             SNDPGMMSG  MSG(&OUTPUT)                         
                                                             
/* MULTIPLY '*' SIGN */                                      
             CHGVAR     VAR(&CALC) VALUE(&DEC1 * &DEC2)      
             CHGVAR     VAR(&OUTPUT) VALUE(&CALC)            
             SNDPGMMSG  MSG(&OUTPUT)                    
                                                        
/* DIVIDED '*' SIGN */                                  
             CHGVAR     VAR(&CALC) VALUE(&DEC1 / &DEC2) 
             CHGVAR     VAR(&OUTPUT) VALUE(&CALC)       
             SNDPGMMSG  MSG(&OUTPUT)                    
ENDPGM                                                  
Note: This display is a combined two-pages display (to make it easier to read, I join the pages).

Compile and run the program.

Leave a Reply