You are currently viewing AS400 CLP Convert from Decimal to Character

AS400 CLP Convert from Decimal to Character

Converting value of an integer variable to a character is fairly simple. The simplest way is by displaying the value of a decimal using SNDPGMMSG. The SNDPGMMSG command can only display values from *CHAR variables, it needs to be converted from *DEC to *CHAR. The good thing, CLP can automatically convert only by using the CHGVAR (Change Variable) command.

/* DECLARE 2 VAR, CHARACTER AND DECIMAL */                  
/* DEFINE VALUE &DEC = 1 */                                 
             DCL        VAR(&DEC) TYPE(*DEC) LEN(2) VALUE(1)
             DCL        VAR(&OUTPUT) TYPE(*CHAR) LEN(2)     
/* CONVERT FROM INT TO CHAR */                              
/* SET VALUE &OUTPUT FROM &DEC VALUE */                     
             CHGVAR     VAR(&OUTPUT) VALUE(&DEC)            
/* SHOW THE VALUE */                                        
             SNDPGMMSG  MSG(&OUTPUT)                        

Compile and run the program.

Leave a Reply