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

Numeric Validation in Rexx


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Mon May 04, 2009 5:49 pm
Reply with quote

Hi,

I am getting the input from user to run a rexx program.

I need to validate that input if numeric or non-numeric.

Could you please help me on this.

Also please provide me the link if this topic is already available in the forum.

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

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Mon May 04, 2009 5:51 pm
Reply with quote

the topic is available in the REXX manuals
see the datatype function
or google for rexx datatype
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Mon May 04, 2009 5:52 pm
Reply with quote

OK thanks
Back to top
View user's profile Send private message
MBabu

Active User


Joined: 03 Aug 2008
Posts: 400
Location: Mumbai

PostPosted: Mon May 04, 2009 10:18 pm
Reply with quote

Be aware that datatype marks more than just numerics as numbers. Scientifc notation is also considered a number
Code:
say datatype('1E12')
NUM
Back to top
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Mon May 04, 2009 11:22 pm
Reply with quote

Perhaps use translate:
Code:
/* rexx */                                         
mynum = '1E12'                                     
If translate(mynum,' ','1234567890') ¬= ' ' Then   
  /* add error message */                           


If there are any non-numeric characters, the result is non-blank.
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Tue May 05, 2009 5:37 pm
Reply with quote

Thanks for letting me know about these things as I am new to RExx.

Actually, I referred the manual and used,

Code:

          if datatype(L1,W) /== '1' then do
          /* error message  */


Where L1 is a variable having input data.

'W' refers to whole number.

Hence if L1 is whole number, rexx returns 1 otherwise 0 which is an error.

Please correct me if my understaning is incorrect.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Tue May 05, 2009 5:59 pm
Reply with quote

Your understanding of this function sounds right.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 06, 2009 3:11 am
Reply with quote

As REXX always returns a number, you can do a numeric comparison:
Code:
if datatype(L1,W) <> 1 then do
          /* error message  */

In my programs, when dealing with functions that return 0 or 1, I use the following trick:
In my Init paragraph (at the beginning of execution):
Code:
True = (1=1)
False = /True
Then I can ask:
Code:
if datatype(L1,W) = False then do
          /* error message  */
Back to top
View user's profile Send private message
Mathiv Anan

Active User


Joined: 23 Jul 2008
Posts: 106
Location: USA

PostPosted: Thu May 07, 2009 11:19 pm
Reply with quote

oh great.

everything i hear from this forum is new!

Thanks for your information/guidance. icon_smile.gif
Back to top
View user's profile Send private message
arun.masilamani

New User


Joined: 26 Jun 2008
Posts: 4
Location: Chennai

PostPosted: Fri May 08, 2009 11:02 am
Reply with quote

You could also us this form of "DATATYPE" Validation too :

Code:
PULL INPUT                               
       IF DATATYPE(INPUT) = "NUM" THEN   
           SAY "NUMBER IS NUMERIC"       
       ELSE                               
           SAY "NUMBER IS NOT NUMERIC"   
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 -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 4
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
Search our Forums:

Back to Top