IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to read Hex in Cobol and output to Pic X(2).


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Fri Mar 23, 2007 9:14 am
Reply with quote

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
View user's profile Send private message
agkshirsagar

Active Member


Joined: 27 Feb 2007
Posts: 691
Location: Earth

PostPosted: Fri Mar 23, 2007 11:15 am
Reply with quote

See the link below
http://www.ibmmainframes.com/viewtopic.php?t=18366&highlight=displaying+hex+value
Back to top
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Fri Mar 23, 2007 7:44 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 9:15 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Mar 23, 2007 9:40 pm
Reply with quote

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
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Mar 23, 2007 10:13 pm
Reply with quote

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
View user's profile Send private message
atanwc

New User


Joined: 26 Jul 2006
Posts: 24

PostPosted: Sat Mar 24, 2007 7:44 am
Reply with quote

Thanks everyone! I got it!

Thanks you very much!
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Mar 24, 2007 7:47 am
Reply with quote

You're welcome icon_smile.gif
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Error to read log with rexx CLIST & REXX 11
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top