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

RExx code to accept input from user


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

Active User


Joined: 14 Jul 2005
Posts: 105

PostPosted: Sat Dec 20, 2008 12:13 am
Reply with quote

Dear Experts,

I do not have much knowledge of REXX.If someone can give me a piece of code for following will be great.
a)Say 123456789 is a ninie digit number.I want this number to be taken from the user and then
Getting the second last digit like in this case its 8.
Next step is adding 1 to it which maked 9 in this case
Display the outout 9 in this case

But there is an exception of output and that is for
when the second digit from last is 9.IN this case 9+1 will make 10.But in this case the output should be 0.

I know that its easy task for someone who knows REXX.I have to get this done urgently and my current REXX skill are not helping me out to get this.
Hope I am not bugging any of the experts here,thanks
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 20, 2008 12:20 am
Reply with quote

homework ??

what did You try, up to now,,,

post something ( even errors ) and somebody will be glad to advice
Back to top
View user's profile Send private message
raghavmcs

Active User


Joined: 14 Jul 2005
Posts: 105

PostPosted: Sat Dec 20, 2008 12:55 am
Reply with quote

I tried Stem concept.Bust stuck next,anyway I feel like you want me to learn REXX and be the expert :-)
Back to top
View user's profile Send private message
raghavmcs

Active User


Joined: 14 Jul 2005
Posts: 105

PostPosted: Sat Dec 20, 2008 12:57 am
Reply with quote

I was trying like this.Please do not see the digits and the number of digits.

Not sure am on right track to achieve this
VAR1=RIGHT( '102301123',2)
VAR2=RIGHT('VAR1',1)
VAR3=VAR2+1
SAY VAR1
SAY VAR2
SAY VAR3
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Sat Dec 20, 2008 1:00 am
Reply with quote

first of all, where did the assignment come from ??
( it does not make too much sense )
Back to top
View user's profile Send private message
Douglas Wilder

Active User


Joined: 28 Nov 2006
Posts: 305
Location: Deerfield IL

PostPosted: Sat Dec 20, 2008 3:53 am
Reply with quote

It look like you are coming along fine on coding this.
To be on the safe side it is good for the first line of a REXX to contain /* REXX */.
If you need to get the input from the keyboard try using "Parse Upper Arg".
For your exception processing use an "IF THEN ELSE".
There is no batter way to learn any programming language than to try it, and when needed get pointers (not the answers) from someone else who knows the language.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8797
Location: Welsh Wales

PostPosted: Sat Dec 20, 2008 3:54 pm
Reply with quote

raghavmcs wrote:
I was trying like this.Please do not see the digits and the number of digits.

Not sure am on right track to achieve this
VAR1=RIGHT( '102301123',2)
VAR2=RIGHT('VAR1',1)
VAR3=VAR2+1
SAY VAR1
SAY VAR2
SAY VAR3

Unfortunately, the syntax is almost correct but the logic is not. The logic will return the LAST digit from the string.

Syntax - Where you have VAR2=RIGHT('VAR1',1) by enclosing the word VAR1 in quotes you are using a literal rather than the value stored in the VAR1 variable.

Logic - Try this
Code:

VAR2 = LEFT(VAR1,1)
VAR3 = VAR2 + 1
IF VAR3 > 9 THEN VAR3 = 0
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Sun Dec 21, 2008 12:54 pm
Reply with quote

Another version:
Code:

/* REXX */                                                             
                                                                       
A = '123456789'                                                         
B = RIGHT(SUBSTR(REVERSE(STRIP(A)),2,1)+1,1)                           
                                                                       
SAY A                                                                   
SAY B                                                                   
                                                                       
EXIT                                                                   
                                                                       


O.
Back to top
View user's profile Send private message
Pedro

Global Moderator


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

PostPosted: Mon Dec 22, 2008 9:16 pm
Reply with quote

O.'s example works. But in instances like this, I prefer using the PARSE instruction:

Code:
/* REXX */                                                             
                                                                       
A = '123456789'                                                         
PARSE VAR a 8 b 9 .                         
                                                                       
SAY A                                                                   
SAY B                                                                   
                                                                       
EXIT 
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 TRIM everything from input, output co... DFSORT/ICETOOL 1
No new posts Compile Several JCL JOB Through one r... CLIST & REXX 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 Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top