Solved

Read Hex Values in COBOL

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
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.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump 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.

760 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

20 Experts available now in Live!

Get 1:1 Help Now