COBOL

kwolbert_IT
kwolbert_IT used Ask the Experts™
on
Does anyone know how to convert the ASCII letter 'A' to the Ascii value 65?

I would like to perform a calculation on the value of the letters entered without using evaluate of nested if statements.  I used to do this in Microfocus cobol using some sort of valueof statement.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
I don't see any support in Fujitsu Power Cobol for these types of conversions.  Have you tried the simplistic approach of just using a redefines, like:

01 conversion-area.
     02 ca-char picture x.
     02 ca-int redefines ca-char picture s9(2) binary.

Then just move the character to "convert" into the ca-char area, and get it's ascii value from ca-int.

~bp

Author

Commented:
No I didn't try a redefine but I have now.  It returns a value of 40 no matter what.  

I attempted the same moving from pic x to pic 99 before and that didn't work.  Also 99 binary, s99, etc, etc, etc.  This shouldn't be complicated but for some reason I can't do it.  I remember doing this in Microfocus years ago and the coding escapes me.  It's a different language but why would Fujitisu incorporate that into it's abilities.  

Someday someone will look at my evaluate and post my code on thedailywtf.com.  
IT / Software Engineering Consultant
Top Expert 2016
Commented:
Okay, sorry that wasn't useful.

Only other thought would be to try BINARY-CHAR UNSIGNED instead of BINARY in my example above.

Reading the docs it looks like my earlier test will allocate 2 bytes of storage for ca-int, which isn't going to work.  The docs seem to indicate that BINARY-CHAR UNSIGNED only allocates 1 byte, which is what we want.

~bp

Author

Commented:
01 conversion-area.
     02 ca-char                  pic x.
     02 ca-int redefines ca-char BINARY-CHAR UNSIGNED.

Worked like a charm!!!
Bill PrewIT / Software Engineering Consultant
Top Expert 2016

Commented:
Excellent, glad I tossed that out there.  Thanks for the grade.

~bp

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial