Define a hex constant in the value clause of a PIC X element in the dictionary.

Document ID : KB000044042
Last Modified Date : 14/02/2018
Show Technical Document Details

Question:

Is there a way to define a hex constant in the value clause of a PIC X element in the dictionary, similar to the following COBOL statement: FIELD-NAME PIC X(01) VALUE X'C0'.
 

Answer:

To get a similar result a PIC 9(1) USAGE COMP field could be defined with a value clause for a decimal value that is the hexadecimal equivalent of X'C0' or whatever hexadecimal is required. For this specific example FIELD-NAME 9(1) USAGE COMP VALUE 192. A PIC 9(1) USAGE COMP field is 2 bytes in length therefore the result will be x'00C0'. To access just the x'C0' byte refine the FIELD-NAME with another field that has two subordinate PIC X fields. Example:

02 FIELD-NAME PIC 9(1) USAGE COMP VALUE 192.     
02 FIELD-NAME-R  REDEFINES FIELD-NAME.           
  04 FIELD-NAME1 PIC X.                          
  02 FIELD-NAME2 PIC X.  

In this example FIELD-NAME2 will have a hexadecimal value of X'C0'.

Additional Information: 

IDD DDDL Reference Guide