Portal | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref

Author Message
SayantaniKundu

New User

Joined: 24 Nov 2008
Posts: 6
Location: Kolkata

 Posted: Fri Sep 03, 2010 12:16 pm    Post subject: How to convert character to decimal in cobol program.? How to convert character to decimal in cobol program.? In the source code char say 'A' is accepted. But the decimal value of 'A' is validated against some logic. Please suggest how to achieve this situation in cobol program?

Phrzby Phil

Senior Member

Joined: 31 Oct 2006
Posts: 1012
Location: Richmond, Virginia

 Posted: Fri Sep 03, 2010 12:28 pm    Post subject: It is hard to decipher just what you are asking. Ask a colleague to read your post and tell you what s/he thinks the question is.
Bharath Bhat

Active User

Joined: 20 Mar 2008
Posts: 283
Location: chennai

 Posted: Fri Sep 03, 2010 12:30 pm    Post subject: Why do you think 'A' has a decimal value? It would be better to post the actual requirement to get realistic solutions.
SayantaniKundu

New User

Joined: 24 Nov 2008
Posts: 6
Location: Kolkata

 Posted: Fri Sep 03, 2010 12:44 pm    Post subject: The code accepts data like 'A' , 'B' etc.. Now the HEX value of 'A' is C1... If C1 is converted to decimal (i.e. HEX to Decimal) , u get 193. I would like to know if we can do this conversion in cobol code.
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2476
Location: Netherlands, Amstelveen

 Posted: Fri Sep 03, 2010 12:54 pm    Post subject: Function ORD (inp-char)
Bharath Bhat

Active User

Joined: 20 Mar 2008
Posts: 283
Location: chennai

 Posted: Fri Sep 03, 2010 12:57 pm    Post subject: Declare a working storage array having two columns and 26 occurances. Col1 contains character and col2 contains decimal value. You've got yourself a conversion table.
Bharath Bhat

Active User

Joined: 20 Mar 2008
Posts: 283
Location: chennai

Posted: Fri Sep 03, 2010 12:59 pm    Post subject:

 PeterHolland wrote: Function ORD (inp-char)

That simple?
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10701
Location: italy

 Posted: Fri Sep 03, 2010 12:59 pm    Post subject: Reply to: How to convert character to decimal in cobol progr to all of You .... it would be wise to review the different number representations see for hints http://ibmmainframes.com/viewtopic.php?t=40254&highlight= the question is badly posed the common sense tells that a CHAR represents a number itself what You are probably asking for is how to convert a generic byte to the decimal equivalent, in other words an HEX to DECIMAL NOT a CHAR to DECIMAL
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2476
Location: Netherlands, Amstelveen

Posted: Fri Sep 03, 2010 1:01 pm    Post subject:

Bharath Bhat wrote:
 PeterHolland wrote: Function ORD (inp-char)

That simple?

Yes.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10701
Location: italy

 Posted: Fri Sep 03, 2010 1:05 pm    Post subject: Reply to: How to convert character to decimal in cobol progr c /to all of You .... /to some of You .... /
Bharath Bhat

Active User

Joined: 20 Mar 2008
Posts: 283
Location: chennai

Posted: Fri Sep 03, 2010 1:10 pm    Post subject:

 SayantaniKundu wrote: The code accepts data like 'A' , 'B' etc.. Now the HEX value of 'A' is C1... If C1 is converted to decimal(i.e. HEX to Decimal) , u get 193. I would like to know if we can do this conversion in cobol code.
enrico-sorichetti

Senior Member

Joined: 14 Mar 2007
Posts: 10701
Location: italy

 Posted: Fri Sep 03, 2010 1:20 pm    Post subject: Reply to: How to convert character to decimal in cobol progr it would be wiser in these cases to post the full requirement common sense tells that ... c'A' ==> positive 1 ( zoned decimal ) or as an alternative c'A' ==> printable for hex "A" c''0123456789ABCDEF' ==> x'000102030405060708090a0b0c0d0e'
Robert Sample

Global Moderator

Joined: 06 Jun 2008
Posts: 8567
Location: Dubuque, Iowa, USA

 Posted: Fri Sep 03, 2010 4:56 pm    Post subject: To be accurate, you need to subtract 1 from the FUNCTION output. FUNCTION ORD returns a value in the range of 1 to 256, whereas the collating sequence values are 0 to 255. The function returns 194 for an upper case A, not 193.
PeterHolland

Global Moderator

Joined: 27 Oct 2009
Posts: 2476
Location: Netherlands, Amstelveen

Posted: Fri Sep 03, 2010 11:40 pm    Post subject:

 Robert Sample wrote: To be accurate, you need to subtract 1 from the FUNCTION output. FUNCTION ORD returns a value in the range of 1 to 256, whereas the collating sequence values are 0 to 255. The function returns 194 for an upper case A, not 193.

Yes Robert, and i left that to the TS to find out.
 All times are GMT + 6 Hours
 Page 1 of 1

Search our Forum:

 Topic Author Forum Replies Posted Similar Topics Calling Rexx program from Cobol Srinivas B CLIST & REXX 7 Thu Oct 29, 2020 6:00 pm How to define transaction that trigge... cnop042 CICS 2 Thu Oct 22, 2020 7:12 am COnvert a column with mix of hex ,cha... shub2204 DB2 5 Fri Oct 02, 2020 2:20 pm Missing Negative sign in COBOL jzhardy COBOL Programming 6 Sat Sep 26, 2020 11:32 am COBOL reading from SYSIN jzhardy COBOL Programming 1 Mon Sep 21, 2020 2:37 pm

 © 2003-2020 IBM MAINFRAME Software Support Division
 Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us