How can I get the character EBCDIC value in RPGLE?

I need to somehow convert individual characters in RPGLE to integers - does anyone know a good way? It should work on all possible inputs and ideally provide a different integer for each input - at least it should provide a different value for all common inputs. I don't care what integers are. In a C-like language, I would take the ASCII value or the like - ideally I want something equivalent to this.

An example to understand how I want it to work:

characterData = "Hello";
for i = 1 to %len(string);
    singleCharacter = %subst(characterData:i:1);
    number = myFunction(singleCharacter);
    dsply 'The value of ' + singleCharacter + ' is ' + %char(number);
endfor;

It will print

The value of H is 72
The value of e is 101
The value of l is 108
The value of l is 108
The value of o is 111

but note that I really don't care what numbers are, they just are different for each input.

- RPGLE, , , .

+4
2

, . 1 1- . , 1, . , EBCDIC. :

DConversion       DS
D CharacterValue          1      1A
D EBCDICValue             1      1U 0

/free
 CharacterValue = 'A';
 //Do something with EBCDICValue
/end-free

, . , -.

fancier, 1- :

DConversionArray  DS                          
D CharacterField          1    100            
D EBCDICArray             1    100U 0 DIM(100)

/free
 CharacterField = 'We the people of the United States...';
 For I = 1 to %Len(%TrimR(CharacterField));
   X = EBCDICArray(I);
   //Do something with X
 EndFor;                                                  
/end-free

- EBCDIC.

, , , . varchar . , 1- . :

DEBCDICValue      S              3U 0 BASED(EBCDICPointer)
DEBCDICPointer    S               *
/free
 For I = 0 to %Len(%TrimR(CharacterField))-1;
   EBCDICPointer = %Addr(CharacterField)+I;
   X = EBCDICValue;
   //Do something with X
 EndFor;
/end-free
+4

ASCII A afaik 65??? , ebcdic . , , .

d*Seen this and wonder why we still use it but its probably already there...
D Lo              c                   const('abcdefghijklmnopqrstuvwxyz')  
D Up              c                   const('ABCDEFGHIJKLMNOPQRSTUVWXYZ')  

eval x=%scan('A':UP)
if x <> 0
eval x +=64
endif
0

Source: https://habr.com/ru/post/1720594/


All Articles