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?
Decimal To Character Conversion On AS/400
4.8k views Asked by selpatS20 At
3
There are 3 answers
1
On
Simplest in any recent OS release is to redefine, or overlay, the numeric with a character definition:
dcl &numVal *uint 2 value( 193 )
dcl &charVal *char 1 stg( *DEFINED ) defvar( &numVal 2 )
In a simple CL program, it might look like this:
pgm
dcl &numVal *uint 2 value( 193 )
dcl &charVal *char 1 stg( *DEFINED ) defvar( &numVal 2 )
/* Show current character equivalence... */
sndusrmsg msg( &charVal ) msgtype( *INFO )
/* Set a new numeric value... */
chgvar &numVal ( 194 )
/* Show new character equivalence... */
sndusrmsg msg( &charVal ) msgtype( *INFO )
return
endpgm
The &charVal value will be displayed as "A" the first time and "B" the second. The *UINT variable must be defined as a 2-byte or larger variable since CL can't define integer variables of a single byte. The second byte of a 2-byte integer has the needed bit pattern. The binary integer value has a hexadecimal equivalent in memory that corresponds to character "A", "B" or whatever,
This example gives the EBCDIC character "A" in variable &TXT1: