Portal | Manuals | 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

Active Member

Joined: 31 Oct 2006
Posts: 996
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: 2472
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: 10649
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: 2472
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: 10649
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: 10649
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: 8519
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: 2472
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 Cobol redefines for Signed pictured c... gvvjags COBOL Programming 4 Thu Feb 27, 2020 4:33 pm convert SUPERC compare report to side... jzhardy CLIST & REXX 5 Fri Feb 21, 2020 8:55 am COBOL - Array result in single variab... vinu78 COBOL Programming 3 Thu Feb 20, 2020 5:29 pm Dynamic cursor name in Cobol program Jlevine COBOL Programming 1 Fri Feb 14, 2020 2:55 am Indent cobol code Renato Zangerolami COBOL Programming 6 Thu Feb 13, 2020 12:53 am

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