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 

How to convert a decimal value to hex in COBOL ?

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


Joined: 24 Mar 2006
Posts: 25
Topics: 10

PostPosted: Tue Aug 08, 2006 11:52 pm    Post subject: How to convert a decimal value to hex in COBOL ? Reply with quote

Is there any in-built function in COBOL to convert a decimal value into a hexadecimal value ? Also how to unpack a COMP-5 value and display it on the console ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Wed Aug 09, 2006 7:12 am    Post subject: Reply with quote

Quote:

Is there any in-built function in COBOL to convert a decimal value into a hexadecimal value ?


SSD,

No. There is no in-built function for the conversion. Check this link which shows you an example of converting to hex

http://www.mvsforums.com/helpboards/viewtopic.php?t=2592&highlight=hex

Quote:

Also how to unpack a COMP-5 value and display it on the console ?


You can use DISPLAY the comp-5 field and it will displayed in the sysout.

Hope this helps...

Cheers

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


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Wed Aug 09, 2006 12:44 pm    Post subject: Reply with quote

SSD,

Check this link for Intrinsic Functions available in COBOL:

http://publibz.boulder.ibm.com/cgi-bin/bookmgr_OS390/BOOKS/IGY3LR10/7.1?SHELF=&DT=20020920180651&CASE=
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
ssd
Beginner


Joined: 24 Mar 2006
Posts: 25
Topics: 10

PostPosted: Wed Aug 09, 2006 11:45 pm    Post subject: Reply with quote

Kolusu,

What if the number to be converted to hex is a negative interger ?

Regarding the display of COMP-5 the display shows some unreadable characters but once the COMP-5 is move to Zoned-decimal variable I could view the original value.

Thanks for your Replies


SSD
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Thu Aug 10, 2006 6:41 am    Post subject: Reply with quote

SSD,

Try this code for a sample negative input:
Code:

//STEP0100 EXEC PGM=SORT                                               
//SYSOUT   DD SYSOUT=*                                                 
//SYSPRINT DD SYSOUT=*                                                 
//SORTIN   DD *                                                         
-0065781053                                                             
/*                                                                     
//SORTOUT  DD SYSOUT=*                                                 
//SYSIN    DD *                                                         
  SORT FIELDS=COPY                                                     
  OUTREC FIELDS=(1,11,HEX)                                             
/*                                                                     
//       

OUTPUT
60F0F0F6F5F7F8F1F0F5F3

_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
ssd
Beginner


Joined: 24 Mar 2006
Posts: 25
Topics: 10

PostPosted: Mon Aug 14, 2006 11:42 pm    Post subject: Reply with quote

Shekar and Kolusu ,
Thanks for your replies..
They are extremely helpful

SSD
Back to top
View user's profile Send private message
anit.mohanty
Beginner


Joined: 20 Jun 2015
Posts: 1
Topics: 0

PostPosted: Mon Jun 22, 2015 6:48 am    Post subject: Conversion of Decimal to HEX Reply with quote

Hi All,

I wrote a progarm to get the BASE 16 Hex equivalent of a Decimal Number.
So if the input is 978, the program gives 03D2.

Now I want to write 03D2 into a X(2) field in COBOL.

When I move hardcoded X'03D2' into X(02) , it works
but when I declare the same in Working storage and move the variable into
the X(2) , it does not work.

Can anybody please help ?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


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

PostPosted: Mon Jun 22, 2015 11:59 am    Post subject: Re: Conversion of Decimal to HEX Reply with quote

anit.mohanty wrote:
Hi All,

I wrote a progarm to get the BASE 16 Hex equivalent of a Decimal Number.
So if the input is 978, the program gives 03D2.

Now I want to write 03D2 into a X(2) field in COBOL.

When I move hardcoded X'03D2' into X(02) , it works
but when I declare the same in Working storage and move the variable into
the X(2) , it does not work.

Can anybody please help ?


What do you mean it is not working? can you show us the code? Here is a sample.

Code:

WORKING-STORAGE SECTION.                     
01 WS-A        PIC X(02) VALUE X'03D2'.       
01 WS-B        PIC X(02) VALUE SPACES.       
01 WS-C        PIC X(02) VALUE SPACES.       
PROCEDURE DIVISION.                           
                                             
     MOVE WS-A         TO WS-B               
     MOVE X'03D2'      TO WS-C               
                                             
     DISPLAY 'WS-B IS : ' WS-B               
     DISPLAY 'WS-C IS : ' WS-C               
                                             

_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
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