Solved

Read Hex Values in COBOL

Posted on 2008-06-23
1
6,130 Views
Last Modified: 2013-11-25
Hi,

I have a requirement in which, i need to find out the ASCII equivalent of a given character. To explain this with an example, if a character "L" is passed to my program, i need to return back 76 (Decimal equivalent of L in ASCII). I was able to convert the EBCDIC character "L" to the ASCII hex value of "L" i.e. "4C". Now, i need to read the hex value of "4C' in my COBOL program and then convert that to 76 using the hexadecimal to decimal conversion.

Can anyone please advise how i can read each character of the hex value and convert it to a decimal equivalent. I need to do a (4 *16^1) + (C * 16^0)?
0
Comment
Question by:bhagatali
1 Comment
 
LVL 27

Accepted Solution

by:
tliotta earned 125 total points
ID: 21851491
bhagatali:

There are three general answers depending on circumstances.

First simple answer is to code two tables/arrays. Look up the EBCDIC character in one array and use the corresponding character from the other array. The 'lookup' could be coded with a SEARCH statement or might be implemented with an INSPECT statement and a CONVERTING clause; other possibilities exist, even a PERFORM loop with an IF-test. A number of tables are available on the internet for the EBCDIC/ASCII characters.

Second simple answer is to call the QDCXLATE API. This is a fairly simple API to use for code-page/character-set conversions. IBM supplies a number of table objects (*TBL) that can be used. Select the appropriate EBCDIC and ASCII tables for whatever the environment is.

AFAIK, the _best_ answer is to use the iconv() APIs for true CCSID conversions. This allows for programming that can more easily adapt to different languages, different system and job CCSIDs, various flavors of Unicode, etc. It's not a "simple" answer because it gets into the whole subject of 'Internationalization.' This really calls for some general understanding of programming for mixed language/mixed CCSID systems.

Please describe the overall business requirement for needing to do the conversion in COBOL rather than simply having it happen automatically. There are a number of ways to cause it to happen without needing any programming, so the 'right' way to do it can depend on why it needs to be done at all.

Tom
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
countHi2 challenge 7 52
oracle query help 18 99
Help to convert powershell script into a gui 9 136
Not needed 13 93
A short article about a problem I had getting the GPS LocationListener working.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now