Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with one byte binary or hex field 2

Status
Not open for further replies.

liguana

Programmer
Aug 26, 2003
2
CA
I have a one byte field where in one record the value is “04” and in the next record it is “0f” (for decimal 15).
According to this thread
thread209-542604
seems a comp field will be a minimum 2 bytes long but my records only have one byte for the field. I’ve included the display for 2 records for clarity, the field in question is in column 36 only.
----+----1----+----2----+----3----+----4
:: :::::::: :: ::: ::: ::
1100324002100000000000EF0000000000000000
00010833381014000342041C0000000000140000
:: ::k::::: :: : ::: ::# ::
110029100210000000000027000000000000000
00049283381044060342042B00000000004F000

I’ve tried various redefines and moves and I cannot get it to define the field correctly so as to interpret x’0f’ as decimal 15. I even tried a modified version of code from thread
thread209-508632 am running IBM VS COBOL II Release 4.0 09/15/92. What pictures/redefines/conversions should I be doing?

PS. I will be away Wed. but any reply would be appreciated.
 
liguana -

This is a fairly unusual construct for many/most architectures (i.e. 1 byte comp field). I'd deal with it as PIC X and translate it via an intermediate field:
Code:
     05  IN-MY-FIELD      PIC X.
...
 01  WS-MY-FIELD.
     05  WS-MY-FIELD-NUM  PIC S9(4) COMP.
...
     MOVE LOW-VALUES       TO WS-MY-FIELD(1:1)
     MOVE IN-MY-FIELD      TO WS-MY-FIELD(2:1)
     ADD WS-MY-FIELD-NUM   TO ...
(Obviously you could assign WS-MY-FIELD the value LOW-VALUES in WORKING-STORAGE, but you might be better off initializing it when you use it as I've shown in case someone wants to do arithmetic with the elementary item and the value goes negative or grows over +255.)

Regards.

Glenn
 
Hi liguana,

If you're looking to display the field, just continue Glenn's solution with:

In WS -> 01 ws-displ-field pic 9.

In PD -> move WS-MY-FIELD-NUM to ws-displ-field
display ws-displ-field

The move converts the comp field to display format (decimal) and provides the appropriate character representation for displaying or printing.

Regards, Jack.
 
WS-DISPL-FIELD should have a PIC of 999 as one byte binary can have a value as high as 255.
 
I can't test it now, but I think when WS-MY-FIELD is S9(4) COMP, my compiler cannot do WS-MY-FIELD(n:n).

I have had to redefine the field as PIC XX. WS-MY-FIELD is initialized with LOW-VALUES. The one byte value (0F) goes into the left (or right) -most field. The MOVE constructs the final S9(4) COMP thru the REDEFINES.

This also will give you values up to 255 when warranted.

Dimandja
 
That worked! Thank you all very much.
This is a great forum. I'm going to tell my colleages.
 
liguana -

You might consider "Mark this post as helpful ..." to recognize those forum members who were helpful/provided a good answer.

Glenn
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top