Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to read Hex in Cobol and output to Pic X(2).

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to read Hex in Cobol and output to Pic X(2).
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: 686
Location: Earth

PostPosted: Fri Mar 23, 2007 11:15 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Fri Mar 23, 2007 9:15 pm    Post subject:
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

Site Director


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

PostPosted: Fri Mar 23, 2007 9:40 pm    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Fri Mar 23, 2007 10:13 pm    Post subject:
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    Post subject:
Reply with quote

Thanks everyone! I got it!

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

Site Director


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

PostPosted: Sat Mar 24, 2007 7:47 am    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts it is possible output a SET value fro... Martylin JCL & VSAM 4 Fri Sep 22, 2017 7:08 am
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
No new posts how to see when the last read access ... Mike 1304 DB2 1 Tue Sep 12, 2017 7:52 pm
No new posts BUILD OUTFIL based on condition other... balaji81_k DFSORT/ICETOOL 13 Fri Sep 08, 2017 11:06 pm
No new posts Hardcoded negative sign value in output scdinesh SYNCSORT 8 Fri Sep 08, 2017 5:28 am

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us