IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Enterprise Cobol function working like HEX DB2 function


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Ermy

New User


Joined: 13 Mar 2010
Posts: 6
Location: ITALY

PostPosted: Mon Mar 15, 2010 4:19 am
Reply with quote

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
icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Mon Mar 15, 2010 5:37 am
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Mar 15, 2010 7:06 am
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Mar 15, 2010 2:46 pm
Reply with quote

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
View user's profile Send private message
Ermy

New User


Joined: 13 Mar 2010
Posts: 6
Location: ITALY

PostPosted: Mon Mar 15, 2010 5:17 pm
Reply with quote

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
View user's profile Send private message
Kjeld

Active User


Joined: 15 Dec 2009
Posts: 365
Location: Denmark

PostPosted: Mon Mar 15, 2010 6:04 pm
Reply with quote

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
View user's profile Send private message
Bill O'Boyle

CICS Moderator


Joined: 14 Jan 2008
Posts: 2501
Location: Atlanta, Georgia, USA

PostPosted: Mon Mar 15, 2010 7:47 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top