Return to the RPG Tips
ASCII/EBCDIC Conversion
Define arrays and work fields: D ASCII S 1 DIM(255) D EBCDIC S 1 DIM(255) D WrkStr1 s 255 D WrkStr2 s 255 D DS D BinValue 1 2B 0 INZ(0) D BinChar 2 2 At program startup (one time) I load the ASCII and EBCDIC arrays: C do 255 N C z-add N BinValue C eval %subst(WrkStr1:N:1) = BinChar C enddo C move WrkStr1 WrkStr2 C CALL 'QDCXLATE' 68 C PARM 255 DataLen C PARM WrkStr1 C PARM 'QEBCDIC' XLateTable C PARM 'QSYS' XLateTblLib C CALL 'QDCXLATE' 68 C PARM 255 DataLen C PARM WrkStr2 C PARM 'QASCII' XLateTable C PARM 'QSYS' XLateTblLib C do 255 N C eval EBCDIC(N) = %subst(WrkStr1:N:1) C eval ASCII(N) = %subst(WrkStr2:N:1) C enddo Then I convert the data by offsetting into the table: C ToASCII begsr C do XlateLen P C eval BinChar = %subst(Buffer:P:1) C eval N = BinValue C N ifne 0 C move ASCII(N) BinChar C endif C eval %subst(Buffer:P:1) = BinChar C enddo C endsr
[report a broken link by clicking here]