Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Read Hex Values in COBOL

Posted on 2008-06-23
1
Medium Priority
?
6,469 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 375 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

916 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