Solved

Read Hex Values in COBOL

Posted on 2008-06-23
1
6,223 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
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 …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

679 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