Solved

Read Hex Values in COBOL

Posted on 2008-06-23
1
6,349 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Independent Software Vendors: 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

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
Introduction to Processes
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

624 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