Re: Setting A Hex Value in COBOL



On 30 May, 19:41, "gary" <garyi...@xxxxxxxxx> wrote:
I have to modify an old COBOL program which probably hasn't been touched
since the mid-90's. And it's probably been almost as long since I've
touched COBOL. Part of what happens in the program is the setting of some
printer control codes which are sent to some downstream printers in CICS.

The following snippet of code shows how some of the control codes are
currently being set. It seems pretty straightforward. For instance, the
redefinition of CH-FF-BIN with its value of +12 causes the CH-FF field to
contain X'0C. Simarly, CH-1D-BIN with its value of +29 causes the CH-1D
filed to contain a X'1D'.

01 CH-NL-BIN PIC S9(4) COMP VALUE +21.
01 FILLER REDEFINES CH-NL-BIN.
02 FILLER PIC X.
02 CH-NL PIC X.
01 CH-FF-BIN PIC S9(4) COMP VALUE +12.
01 FILLER REDEFINES CH-FF-BIN.
02 FILLER PIC X.
02 CH-FF PIC X.
01 CH-1D-BIN PIC S9(4) COMP VALUE +29.
01 FILLER REDEFINES CH-1D-BIN.
02 FILLER PIC X.
02 CH-1D PIC X.
01 CH-56-BIN PIC S9(4) COMP VALUE +86.
01 FILLER REDEFINES CH-56-BIN.
02 FILLER PIC X.
02 CH-56 PIC X.
01 CH-31-BIN PIC S9(4) COMP VALUE +49.
01 FILLER REDEFINES CH-31-BIN.
02 FILLER PIC X.
02 CH-31 PIC X.

My question is this. I need to add a field which would end up containing a
X'E5'. The decimal equivalent is +229. Since the value of the field is
3-digits, will it still "fit" into the PIC X field? Would it look something
like this?

01 CH-E5-BIN PIC S9(4) COMP VALUE +229.
01 FILLER REDEFINES CH-E5-BIN.
02 FILLER PIC X.
02 CH-E5 PIC X.

This is some old MVS COBOL II code. Is there actually a better way to be
performing this function? Is there anything like MOVE X'E5' to CH-E5?

Thank you.
Gary

Why not just edit the fields with PIC X VALUE '.' where the . is the
hex value (eg E5) using HEX ON in an ISPF edit session? Someone else
mentioned that screens can be upset by this but that is something that
I have not encountered. If you are worried about making the code easy
to understand (self documenting) then add a comment field to show what
the value is. However, the field naming standards you use seem to be
self-documenting.

.