ibm-midrangecontrol-language

Decimal To Character Conversion On AS/400


In a CL, I am trying to convert a number (193) to its alpha representation (A). Coming up with nothing, need a little help. Is there a CHAR function?


Solution

  • This example gives the EBCDIC character "A" in variable &TXT1:

    PGM                                                
    DCL        VAR(&NUM) TYPE(*DEC) LEN(3 0) VALUE(193)
    DCL        VAR(&TXT2) TYPE(*CHAR) LEN(2)           
    DCL        VAR(&TXT1) TYPE(*CHAR) LEN(1)           
    
    CHGVAR     VAR(%BIN(&TXT2 1 2)) VALUE(&NUM)        
    CHGVAR     VAR(&TXT1) VALUE(%SST(&TXT2 2 1))       
    SNDUSRMSG  MSG(&TXT1)                              
    ENDPGM