Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to convert character to decimal in cobol program.?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to convert character to decimal in cobol program.?
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

Active Member


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

PostPosted: Fri Sep 03, 2010 12:28 pm    Post subject:
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    Post subject:
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    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Fri Sep 03, 2010 12:54 pm    Post subject:
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    Post subject:
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Sep 03, 2010 12:59 pm    Post subject: Reply to: How to convert character to decimal in cobol progr
Reply with quote

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

Global Moderator


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

PostPosted: Fri Sep 03, 2010 1:01 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Sep 03, 2010 1:05 pm    Post subject: Reply to: How to convert character to decimal in cobol progr
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    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10202
Location: italy

PostPosted: Fri Sep 03, 2010 1:20 pm    Post subject: Reply to: How to convert character to decimal in cobol progr
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: 7905
Location: Bellevue, IA

PostPosted: Fri Sep 03, 2010 4:56 pm    Post subject:
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: 2422
Location: Netherlands, Amstelveen

PostPosted: Fri Sep 03, 2010 11:40 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts IMS BMP program causes 878 system abend Artemk IMS DB/DC 7 Tue Nov 22, 2016 8:26 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts Convert +9999999999999.99 to S9(12)V9(3) vnktrrd DFSORT/ICETOOL 8 Thu Nov 17, 2016 8:15 pm
This topic is locked: you cannot edit posts or make replies. Db2 SQL query to convert rows into co... subratarec DB2 5 Thu Nov 17, 2016 4:51 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us