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

Check whether a field is NUMERIC or ALPHABETIC


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

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Sat Jun 12, 2010 1:08 pm
Reply with quote

Hi,
I have a requirement to check whether a field is NUMERIC or ALPHABETIC.

i have a fields of say

Code:

     
                               01 FORIEGN  X(30)
                               01 IS-FOREIGN X(05)

                         When i move numeric bytes such as

                         MOVE 009125478987  TO FOREIGN
                         
                            IF FOREIGN IS NUMERIC
                               MOVE 'TRUE'   TO IS-FOREIGN
                            ELSE
                               MOVE 'FALSE' TO IS-FORIEGN
                            END-IF.
   

                             


Always the value of IS-FOREIGN is a FALSE.

Please can i get any solution on it to know wheteher a field is a perfect NUMERIC OR perfect ALPHABETIC.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Jun 12, 2010 2:29 pm
Reply with quote

try moving 30 numeric characters!!!!!!
Back to top
View user's profile Send private message
PeterHolland

Global Moderator


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

PostPosted: Sat Jun 12, 2010 2:36 pm
Reply with quote

01 FORIEGN X(30)
IF FOREIGN

01 IS-FOREIGN X(05)
MOVE 'FALSE' TO IS-FORIEGN


As far as i see it the compiler will not even let you go that far
too test it.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Sat Jun 12, 2010 7:09 pm
Reply with quote

Quote:
Please can i get any solution on it to know wheteher a field is a perfect NUMERIC OR perfect ALPHABETIC.
Yes, if an alphanumeric variable contains numeric data the IF NUMERIC test will return true while if it contains just letters the IF ALPHABETIC test will return true. However, you must remember that if the variable is PIC X(30), you must have 30 digits for it to pass -- since you did not provide all 30 digits, the variable is filled with spaces which are NOT numeric. Hence the FALSE display.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sat Jun 12, 2010 8:32 pm
Reply with quote

in case you are trying to proof for a NUMVALable values (char) in a char field (PIC X),
I always setup a user class/condition (in special names paragraph) that defines
what characters are allowed (will not cause an abend) for the NUMVAL or NUMVAL-C instructions.
Back to top
View user's profile Send private message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Sun Jun 13, 2010 12:21 pm
Reply with quote

Thanks for the reply.

so for my logic to work can i check till the field is having spaces and then go ahead with the check of numeric or alphabetic.does that work.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Jun 13, 2010 12:41 pm
Reply with quote

tecnokrat wrote:
Please can i get any solution on it to know wheteher a field is a perfect NUMERIC OR perfect ALPHABETIC.
This is a very vague question, what exactly are you looking for?
Quote:
so for my logic to work can i check till the field is having spaces and then go ahead with the check of numeric or alphabetic.does that work.
Yes, sort of, again, less generalization and more specifics. There are a lot of answers here and a lot of expertise here, let us know just what you are trying to do.
Back to top
View user's profile Send private message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Sun Jun 13, 2010 2:50 pm
Reply with quote

as said to move the complete X(30) with NUM values to check it as IF NUMERIC then the exact result would be TRUE.

instead if only a partial NUM is present in X(30) say only 20 bytes and if only these 20 bytes can be checked with rest as spaces.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Jun 13, 2010 3:06 pm
Reply with quote

tecnokrat wrote:
as said to move the complete X(30) with NUM values to check it as IF NUMERIC then the exact result would be TRUE.

instead if only a partial NUM is present in X(30) say only 20 bytes and if only these 20 bytes can be checked with rest as spaces.
I'm not sure where the question is, but NUMVAL or EXAMINE replacing the blanks with zeros might help....
Back to top
View user's profile Send private message
tecnokrat
Warnings : 1

Active User


Joined: 22 May 2009
Posts: 160
Location: Bangalore

PostPosted: Sun Jun 13, 2010 3:35 pm
Reply with quote

if the exact value in the field X(30) has 00901213147600 and if the remaining is replaced with zeroes the exact value would have missed out.

The value intact cant be checked without replacing the spaces with zeroes.

and if the field has zeroes in the trailing then it would become tedious to know which one is real value,if added with zeroes with remaining spaces.
Back to top
View user's profile Send private message
CICS Guy

Senior Member


Joined: 18 Jul 2007
Posts: 2146
Location: At my coffee table

PostPosted: Sun Jun 13, 2010 3:55 pm
Reply with quote

tecnokrat wrote:
if the exact value in the field X(30) has 00901213147600 and if the remaining is replaced with zeroes the exact value would have missed out.

The value intact cant be checked without replacing the spaces with zeroes.

and if the field has zeroes in the trailing then it would become tedious to know which one is real value,if added with zeroes with remaining spaces.
Have you looked at NUMVAL?
That intrinsic function will convert you 30 byte character field down to a valid numeric field.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Sun Jun 13, 2010 3:56 pm
Reply with quote

tecnokrat,

you never bother to read the links provided,
thus your threads go on forever.

since no one could be that dense,
i figure that you are doing it on purpose in attempt to irritate posters to your thread.
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 Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Using Multiple IFTHEN and WHEN condit... SYNCSORT 12
No new posts Check if CICS is online in JCL CICS 10
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
Search our Forums:

Back to Top