IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to convert character to decimal in cobol program.?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
SayantaniKundu

New User


Joined: 24 Nov 2008
Posts: 6
Location: Kolkata

PostPosted: Fri Sep 03, 2010 12:16 pm
Reply with quote

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?
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


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

PostPosted: Fri Sep 03, 2010 12:28 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Sep 03, 2010 12:30 pm
Reply with quote

Why do you think 'A' has a decimal value? It would be better to post the actual requirement to get realistic solutions.
Back to top
View user's profile Send private message
SayantaniKundu

New User


Joined: 24 Nov 2008
Posts: 6
Location: Kolkata

PostPosted: Fri Sep 03, 2010 12:44 pm
Reply with quote

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.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Fri Sep 03, 2010 12:54 pm
Reply with quote

Function ORD (inp-char)
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Sep 03, 2010 12:57 pm
Reply with quote

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.
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Sep 03, 2010 12:59 pm
Reply with quote

PeterHolland wrote:
Function ORD (inp-char)


That simple? icon_redface.gif
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Sep 03, 2010 12:59 pm
Reply with quote

to all of You ....
it would be wise to review the different number representations

see for hints
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
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Fri Sep 03, 2010 1:01 pm
Reply with quote

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


That simple? icon_redface.gif


Yes.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Sep 03, 2010 1:05 pm
Reply with quote

c /to all of You .... /to some of You .... / icon_biggrin.gif
Back to top
View user's profile Send private message
Bharath Bhat

Active User


Joined: 20 Mar 2008
Posts: 283
Location: chennai

PostPosted: Fri Sep 03, 2010 1:10 pm
Reply with quote

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.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Fri Sep 03, 2010 1:20 pm
Reply with quote

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'
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Fri Sep 03, 2010 4:56 pm
Reply with quote

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.
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Fri Sep 03, 2010 11:40 pm
Reply with quote

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.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Using API Gateway from CICS program CICS 0
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
Search our Forums:

Back to Top