Translation Tables
How to Translate Data  
  Prior Next
 

File input and output directives (READ, WRITE, etc.) and the TBL function provide the ability to translate data from one format to another. This translation process allows the user to convert data strings on a byte by byte basis based on the contents of a transliteration table . The transliteration table to use is identified via the TBL= nnnn option in the file input/output directive or within the TBL function, where nnnn is the line number of the table.

A transliteration table is defined by a statement with the TABLE directive followed by a series of hex digits. Each two hex digits represent a single byte. The first byte in the table (first two hex digits) is the transliteration AND mask. It is ANDed with the hex value of each byte as it is being converted. The results of this AND operation is then used as an offset (base zero) into the rest of the transliteration table. The byte at this offset is the resultant data byte which is either returned in the case of the TBL function and file input or is written to a file in the case of a file output.

Transliteration tables are usually used to convert one character set to another such as ASCII to EBCDIC or for data encryption.

Example:

Sample translation table to generate numbers

0010 TABLE 0F30313233343536373839414243444546

The above table would result in:

Input

After

Output

ASCII

Hex

AND

ASCII

Hex

A

41

01

1

31

B

42

02

2

32

z

7A

0A

A

41

[

5B

0B

B

42

P

50

00

0

30

  Prior Next