Portal | IBM Manuals | Downloads | Products | Refer | Info | Programs | JCLs | Forum Rules*| Site Map | Mainframe CD 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index
 
Register
 
IBMMAINFRAMES.com - IBM Mainframe Support Forums Index FAQ Search Memberlist Usergroups Profile Log in to check your private messages Log in
 
Entering and Reading Hex Data in Input to COBOL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL
Author Message
cakask

New User


Joined: 20 Jan 2010
Posts: 10
Location: OH

PostPosted: Wed Feb 03, 2010 10:56 am    Post subject: Entering and Reading Hex Data in Input to COBOL
Reply with quote

I have an 8 character Hex field (which happens to be an IDMS dbkey) - for example: 3B823417 - and I need to be able to process an input file contains a number of records with this data.

Such as
//INFILE DD *
3B823417
3B82340C
/*

I know that I can turn HEX on in tso but to enter the values I will have to manually type them into the two rows.

so it would look like

000001 b b 17 3899960 23 0998389783
3831444444444383144FF4FFFFFFF4FF44FFFFFFFFFF4444
B247000000000B2470017038999600230009983897830000

or more simply
3831
B247

But I need to know how I can enter 8 characters of hex data 3B823417 and get the COBOL program to "understand" or read it as though it were a COMP with the 4 bytes = '3B823417'. (which converts to 0998389783 in decimal - which I will then be able to use as the DBKEY in an IDMS command "FIND DB-KEY w-dbkey"


The have DFSORT, so if there were convesion option I could try that as well.

Thank you for any ideas.
Back to top
View user's profile Send private message
References
dick scherrer

Global Moderator


Joined: 23 Nov 2006
Posts: 13611
Location: 221 B Baker St

PostPosted: Wed Feb 03, 2010 11:13 am    Post subject:
Reply with quote

Hello and welcome to the forum,

One way to do what you want is to create an array that contains all of the 2-char values from 00 to FF and the one-byte hex equivelent.

For example the array entry for 3B would have a 1-byte result value of x'3B'. This entry might be:
05 char3B pic xx value '3B'
05 hex3B pic x value x'3B'

The array would have 256 entries - from 00 thru FF.
Back to top
View user's profile Send private message
Bill O'Boyle

Active Member


Joined: 14 Jan 2008
Posts: 991
Location: South Carolina, USA

PostPosted: Wed Feb 03, 2010 5:03 pm    Post subject: Reply to: Entering and Reading Hex Data in Input to COBOL
Reply with quote

Give this a try -

Code:

03  WS-DISPLAY PIC 9(08)V9.
03  WS-DISPLAY-X REDEFINES WS-DISPLAY PIC X(09).
03  WS-PACKED PIC 9(08)V9 COMP-3.
03  WS-PACKED-X REDEFINES WS-PACKED PIC X(05).
03  WS-SYSIN-VALUE PIC X(08) VALUE '3B823417'.
03  WS-HEX-VALUE PIC X(04).

MOVE WS-SYSIN-VALUE TO WS-DISPLAY-X.
MOVE ZERO TO WS-DISPLAY-X (9:).

INSPECT WS-DISPLAY-X CONVERTING 'ABCDEF' TO X'FAFBFCFDFEFF'.

MOVE WS-DISPLAY TO WS-PACKED.
MOVE WS-PACKED-X TO WS-HEX-VALUE.

At this point WS-HEX-VALUE equals X'3B823417'.

Note: WS-DISPLAY and WS-PACKED must be UNSIGNED, as illustrated.

Bill
Back to top
View user's profile Send private message
Bill O'Boyle

Active Member


Joined: 14 Jan 2008
Posts: 991
Location: South Carolina, USA

PostPosted: Wed Feb 03, 2010 6:07 pm    Post subject: Reply to: Entering and Reading Hex Data in Input to COBOL
Reply with quote

After further review -

Code:

03  WS-FWORD PIC 9(09) COMP.
03  WS-FWORD-X REDEFINES WS-FWORD PIC X(04).
03  WS-DBKEY PIC 9(10).

MOVE WS-HEX-VALUE TO WS-FWORD-X.
MOVE WS-FWORD TO WS-DBKEY.

You can probably get rid of a couple of fields and redefine them over others, resulting in less MOVE statements.

Bill
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe COBOL All times are GMT + 6 Hours
Page 1 of 1