MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Hexadecimal format for an alphanumeric field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
deepeshk79
Beginner


Joined: 20 Jun 2003
Posts: 112
Topics: 48
Location: Bangalore

PostPosted: Wed Jul 21, 2004 11:04 am    Post subject: Hexadecimal format for an alphanumeric field Reply with quote

Hi All,

I was trying to get the hexadecimal format of an alphanumeric field.

For eg, the hexadecimal format of

XCPTWD05

is
=========
ECDEECFF
73736405
========

as seen from a file (with hex as TSO command).

Now i need to get the hex value of XCPTWD05 in a variable X(16)..ie as
'E7C3D7E3E6C4F0F5'.

Any suggestion how this can be achieved in Cobol.

Thanks,
Deepesh
Back to top
View user's profile Send private message AIM Address
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jul 21, 2004 12:05 pm    Post subject: Reply with quote

Hi

Found the following code in Google Groups:
Code:
 PROGRAM-ID. CHAR-TO-HEX.
 DATA DIVISION.
 WORKING-STORAGE SECTION.
 01  NUM           PIC 999      COMP.
 01  HIGH          PIC 99       COMP.
 01  LOW           PIC 99       COMP.
 01  HEX-DIGITS    PIC X(16)    VALUE "0123456789ABCDEF".
 LINKAGE SECTION.
 01  CHAR    PIC X.
 01  HEX     PIC XX.
 PROCEDURE DIVISION USING CHAR, HEX.
 BEGIN.
     COMPUTE NUM = FUNCTION ORD (CHAR), SUBTRACT 1 FROM NUM
     DIVIDE NUM BY 16 GIVING HIGH REMAINDER LOW
     ADD 1 TO HIGH, LOW
     MOVE HEX-DIGITS (HIGH:1) TO HEX (1:1)
     MOVE HEX-DIGITS (LOW:1) TO HEX (2:1)
     EXIT PROGRAM.
 END PROGRAM CHAR-TO-HEX.


By the way - the HEX command is an ISPF editor command.

O.
________
ultimate fighters


Last edited by ofer71 on Sat Feb 05, 2011 11:18 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed Jul 21, 2004 12:31 pm    Post subject: Reply with quote

Deepesh,

Apart from Cobol example shown by ofer, there are many ways to do get the hex representation of character data.You can use utilities like IDCAMS, SORT to print the data in hex.
Code:

//STEP0100 EXEC PGM=SORT   
//SORTIN   DD *             
XCPTWD05                   
//SYSOUT   DD SYSOUT=*     
//SORTOUT  DD SYSOUT=*     
//SYSIN    DD *             
  SORT FIELDS=COPY           
  OUTREC FIELDS=(1,8,HEX)   
/*                         


Code:

//STEP0200 EXEC PGM=IDCAMS   
//SYSPRINT DD SYSOUT=*       
//FILE1    DD *               
XCPTWD05                     
//SYSIN    DD *               
    PRINT INFILE(FILE1) HEX     
/*                           


Ofer : Is there any special reason that you choose the conversion to be done in a subroutine?

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ofer71
Intermediate


Joined: 12 Feb 2003
Posts: 358
Topics: 4
Location: Israel

PostPosted: Wed Jul 21, 2004 12:34 pm    Post subject: Reply with quote

Kolusu -

No, there is no special reason. I just copied the code from Google.

And what about REXX ?
Code:

HEX = C2X(CHAR)


O.
________
Fetish Video


Last edited by ofer71 on Thu Mar 17, 2011 10:39 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Wed Jul 21, 2004 12:38 pm    Post subject: Reply with quote

Here is a simple revision of the code without calling a subroutine

Code:

WORKING-STORAGE SECTION.                                   
01  NUM           PIC 999      COMP.                       
01  HIGH          PIC 99       COMP.                       
01  LOW           PIC 99       COMP.                       
01  HEX-DIGITS    PIC X(16)    VALUE '0123456789ABCDEF'.   
                                                           
01  CHAR    PIC X.                                         
01  HEX     PIC XX.                                         
01  W-INP-STRING  PIC X(08) VALUE 'XCPTWD05'.               
01  W-HEX-STRING  PIC X(16).                               
01  W-SUB1        PIC S9(04) COMP.                         
01  W-SUB2        PIC S9(04) COMP VALUE 1.                 
                                                           
PROCEDURE DIVISION.                                         
                                                           
      PERFORM VARYING W-SUB1 FROM 1 BY 1 UNTIL W-SUB1 > 8   
              COMPUTE NUM = FUNCTION ORD                   
                            (W-INP-STRING(W-SUB1: 1))       
              SUBTRACT 1 FROM NUM                           
              DIVIDE NUM BY 16 GIVING HIGH REMAINDER LOW   
              ADD 1 TO HIGH, LOW                           
              MOVE HEX-DIGITS (HIGH:1) TO HEX (1:1)         
              MOVE HEX-DIGITS (LOW:1)  TO HEX (2:1)         
              MOVE HEX   TO W-HEX-STRING(W-SUB2 : 2)       
              ADD +2 TO W-SUB2                             
      END-PERFORM                                           
      DISPLAY W-HEX-STRING                                 
      GOBACK.                                               


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
slade
Intermediate


Joined: 07 Feb 2003
Posts: 266
Topics: 1
Location: Edison, NJ USA

PostPosted: Wed Jul 21, 2004 3:46 pm    Post subject: Reply with quote

Hi Kolusu,

I'm surprised, no, **AMAZED**, that you didn't reply:

"Please search before posting. This topic has been discussed earlier. check this link"

http://www.mvsforums.com/helpboards/viewtopic.php?t=2564

Couldn't resist. Very Happy

Regards, Jack.
Back to top
View user's profile Send private message
deepeshk79
Beginner


Joined: 20 Jun 2003
Posts: 112
Topics: 48
Location: Bangalore

PostPosted: Thu Jul 22, 2004 7:54 am    Post subject: Reply with quote

Hi All,

Thanks for your replies. All the codes worked fine.

Deepesh
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group