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
 

 

Numeric Validation in Rexx

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: Numeric Validation in Rexx
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10231
Location: italy

PostPosted: Mon May 04, 2009 5:51 pm    Post subject: Reply to: Numeric Validation in Rexx
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    Post subject: Reply to: Numeric Validation in Rexx
Reply with quote

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

Active User


Joined: 03 Aug 2008
Posts: 401
Location: Mumbai

PostPosted: Mon May 04, 2009 10:18 pm    Post subject: Reply to: Numeric Validation in Rexx
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

Senior Member


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

PostPosted: Mon May 04, 2009 11:22 pm    Post subject: Reply to: Numeric Validation in Rexx
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    Post subject: Reply to: Numeric Validation in Rexx
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

Moderator Team Head


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

PostPosted: Tue May 05, 2009 5:59 pm    Post subject: Reply to: Numeric Validation in Rexx
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: 1226
Location: Israel

PostPosted: Wed May 06, 2009 3:11 am    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts REXX cdoe to purge a JOB from spool a... Sulabh Agrawal CLIST & REXX 11 Thu Mar 09, 2017 11:36 am
No new posts Overriding PS data in rexx Shaheen Shaik CLIST & REXX 8 Fri Mar 03, 2017 5:08 pm
No new posts REXX compiled via RXTCOMP sergeyken CLIST & REXX 7 Tue Feb 07, 2017 9:41 pm
No new posts Converting decimal to numeric using I... Balaryan DFSORT/ICETOOL 4 Thu Feb 02, 2017 11:27 pm
This topic is locked: you cannot edit posts or make replies. Calling REXX code from ISPF panel sanchita dey TSO/ISPF 4 Mon Jan 02, 2017 5:13 pm


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