View previous topic :: View next topic
|
Author |
Message |
Ermy
New User
Joined: 13 Mar 2010 Posts: 6 Location: ITALY
|
|
|
|
I'm using Cobol Enterprise 3.4.
I wish to convert data (display purpose) from char to their hexadecimal value. I know there's a program, in the forum I have found the code.
I search for a function like HEX DB2 function.(The HEX function returns a hexadecimal representation of a value.)
I ask if there is a way to do this with intrinsic function of Enterprise Cobol (ORD, CHAR, DISPLAY-OF) o Language Environment services (CEE.....)
Thanks
|
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello and welcome to the forum,
Quote: |
I ask if there is a way to do this with intrinsic function of Enterprise Cobol |
Unfortunately no. . . Maybe someday if this is accepted by the language developers.
There are a couple of ways posted in the forum - so you at least have a choice. What i have seen several places is that there is a common callable routine rather than including the code in-line whenever it is wanted. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
For example, if you had a 4-Byte field which equals 'ABCD' you need to convert this to its 8-Byte EBCDIC equivalent of 'C1C2C3C4'?
I'm unaware of a COBOL Intrinsic Function which will do this.
As Dick has said, a canned in-house sub-program is your best option.
The conversion process in COBOL can convert 15-Bytes to 30-Bytes in one fell swoop, using the ARITH(EXTEND) compiler option. Otherwise, the maximum is 8-Bytes to 16-Bytes without this ARITH option.
Bill |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
If you are using DB2 in your module already, it might be an option to let the DB HEX function do it:
Code: |
EXEC SQL.
SET :hex-output = HEX(:binary-input)
END-EXEC.
|
It might be quicker than a home-cooked hex function. |
|
Back to top |
|
|
Ermy
New User
Joined: 13 Mar 2010 Posts: 6 Location: ITALY
|
|
|
|
dick scherrer wrote: |
Hello and welcome to the forum,
Quote: |
I ask if there is a way to do this with intrinsic function of Enterprise Cobol |
Unfortunately no. . . Maybe someday if this is accepted by the language developers.
There are a couple of ways posted in the forum - so you at least have a choice. What i have seen several places is that there is a common callable routine rather than including the code in-line whenever it is wanted. |
Thanks for greetings !
I found a very 'odd' function like REVERSE (!) and might not find a HEX funtion. Sorry for my criticism (I joke) . (I must be polite, othrwhise admin bans me).
thank you
Erasmo |
|
Back to top |
|
|
Kjeld
Active User
Joined: 15 Dec 2009 Posts: 365 Location: Denmark
|
|
|
|
Quote: |
found a very 'odd' function like REVERSE (!) and might not find a HEX funtion. |
Yes, it is odd, as PL/1 has 2(!) functions, HEX and HEXIMAGE that supposedly do what you want. But these functions are probably not implemented using Language Environment routines. |
|
Back to top |
|
|
Bill O'Boyle
CICS Moderator
Joined: 14 Jan 2008 Posts: 2501 Location: Atlanta, Georgia, USA
|
|
|
|
You could use the following as a basis for a callable routine -
www.ibmmainframes.com/viewtopic.php?p=174662&highlight=#174662
If your compiler supports ARITH(EXTEND) then WS-NBR can be defined as PIC 9(30), WS-PACKED can be defines as PIC 9(30)V9 COMP-3 and WS-DISPLAY can be defined as PIC 9(30)V9. Note that regardless of the ARITH option, all three numeric definitions must be defined as unsigned (as illustrated).
Also, in a callable routine scenario, you may want to consider passing the length of the data to be converted as a binary halfword. So, the length of the converted (returned) data will be this halfword value, doubled.
The INSPECT CONVERTING (with literals and/or figurative constants) generates a in-line TR assembler instruction, providing that you're not using reference modification. Otherwise, a BALR is issued to a COBOL run-time routine.
Bill |
|
Back to top |
|
|
|