Previous Topic: &FILE GET Statement and Unmapped Format UDBs

Next Topic: Key and Data Differentiation

Data Conversion and Unmapped Format UDBs

If data on an unmapped format UDB is expected to contain non-printable characters it is wise after reading the data into variables to convert it to an expanded hexadecimal form to preserve the non-printables (this is because many NCL verbs automatically translate non-printables to blanks-X'40's).

Regardless of the data representation format selected on the &FILE OPEN/SET statement, data read from or written to an unmapped format UDB might require conversion from expanded hexadecimal format to character format, or conversion from character to expanded hexadecimal format. Two NCL statements, &HEXPACK and &HEXEXP provide this facility.

For example, where &HEXEXP is being used for file processing and data is being read from a file which has records which consist of a 1 byte error code followed by text. If the error code is not X'00', then there is a problem with the record.

A record could be read from the file as follows:

&FILE OPEN ID=MSGFILE FORMAT=UNMAPPED
&FILE GET ID=MSGFILE KEY='00000001'X VARS=(ERRCODE(1),MSGTEXT)
&TEMP = &HEXEXP &ERRCODE
&IF &TEMP GT 00 &THEN &GOTO .ERROR
   .
   .
   .
&WRITE DATA=FOLLOWING MESSAGE READ FROM FILE: &MSGTEXT

The record with a key of X'00000001' was read into two variables, &ERRCODE and &MSGTEXT. A subscript was used to indicate that the first byte was to go into &ERRCODE, and the remaining bytes (up to 256) were to be placed into the variable &MSGTEXT.

An &HEXEXP statement was used to convert the &ERRCODE variable from binary (Packed hexadecimal) format into NCL format. (For example, if &ERRCODE was X'00', &HEXEXP would convert it to X'F0F0'). This enabled the value of it to be tested for an error condition.

Note: A map could be used to describe the file, and then the record could be read into an MDO using mapped format.