View previous topic :: View next topic
|
Author |
Message |
atanwc
New User
Joined: 26 Jul 2006 Posts: 24
|
|
|
|
I received file which have 1000 records. When I use 'hex on' to read the record on TSO, it displays like this.
xxxxxxxxx xxxxx
xxxxxxxxx6xxxxx
xxxxxxxxx7xxxxx
At column 10, I have a X'67'. (In the file, column 10 can be any number between 00 to 99).
In COBOL, I can check HEX by using code IF WS-Byte-10 = X'67'
But how can I read from a file and then move to an output PIC X(2) field?
I tried define as WS-Byte-10 PIC COMP-3, COMP but all these would not work. Please help!
Thanks! |
|
Back to top |
|
|
agkshirsagar
Active Member
Joined: 27 Feb 2007 Posts: 691 Location: Earth
|
|
Back to top |
|
|
atanwc
New User
Joined: 26 Jul 2006 Posts: 24
|
|
|
|
Thanks Abhijit!
But my problem is input. How do I define input. Because PIC 99 comp and pic 9 comp. Both means 2 bytes. My input is only in one byte
xxx6x
xxx7x |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
You can move your 1-byte input field to the low-order byte in a COMP field in working storage (make sure the high order byte is set to x'00' - if you declare the initial value as zeros you'll be good to go).
You can then use the comp field as the displacement into an array that is set up as:
Code: |
01 HEX-TABLE.
05 filler pic x(32 ) value '000102030405060708090A0B0C0D0E0F'.
.
05 filler pic x(32 ) value 'F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF'.
01 HEX-TABLE-R redefines HEX-TABLE.
05 HEX-ITM occurs 256 times.
10 HEX-OVER PIC X.
10 HEX-UNDER PIC X.
|
If you ever need to "dump" all or part of a record, this is also handy for that use. With the "input" character and the over/under values, you can produce your own "HEX ON" or DITTO dump.
Please let me know if there are any questions. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello again,
If anyone wants/needs to convert the nibbles of a byte into the hex equivalent, i'd suggest putting the hex-translation code into a called module. The callable module that i've installed at many sites includes:
Code: |
LINKAGE SECTION.
*
01 THE-LENGTH PIC 9(5) COMP.
*
01 ORIGINAL-LINE.
05 ORIG-CHAR PIC X OCCURS 2000 TIMES
INDEXED BY ORG-INX.
*
01 HEX-OVER-LINE.
05 HEX-OVER-CHAR PIC X OCCURS 2000 TIMES
INDEXED BY HO-INX.
*
01 HEX-UNDER-LINE.
05 HEX-UNDER-CHAR PIC X OCCURS 2000 TIMES
INDEXED BY HU-INX.
*
.
.
PROCEDURE DIVISION USING THE-LENGTH,
ORIGINAL-LINE,
HEX-OVER-LINE,
HEX-UNDER-LINE.
*
|
This definition will handle from 1 to 2000 bytes.
In addition to "dumping" data from files, it can be handy to take a "hex snapshot" of part of a program's variables for debugging. |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
atanwc wrote: |
But my problem is input. How do I define input. Because PIC 99 comp and pic 9 comp. Both means 2 bytes. My input is only in one byte |
Move the one byte (pic x) to the low-order byte of a two byte comp field and convert as suggested.
Code: |
num pic s9(2) comp.
filler redefined num.
filler pic x.
hex pic x. |
|
|
Back to top |
|
|
atanwc
New User
Joined: 26 Jul 2006 Posts: 24
|
|
|
|
Thanks everyone! I got it!
Thanks you very much! |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
You're welcome |
|
Back to top |
|
|
|