View previous topic :: View next topic |
Author |
Message |
bidpar Beginner
Joined: 08 Jan 2003 Posts: 28 Topics: 4 Location: india
|
Posted: Fri Jun 06, 2003 7:58 am Post subject: Passing variable no of arguments |
|
|
Hi all
Learning REXX.
How can I pass different no of arguments to a REXX program ?
I have written a small program to read the argument list and print it. I used the following method
numarg = ARG()
say numarg
Do i = 1 to numarg
say 'arg(' || i || ') =' || ARG(i)
end
I am running this program as TSO EX 'PDS.NAME(MEMBER)' '1 2 3'
All my variables 1 2 &3 are getting associated to arg(1). It is showing arg(1) = '1 2 3' and numarg = 1
I want
arg(1) = 1
arg(2) = 2
arg(3) = 3.
Also I should be able to run this program with different set of variables like TSO EX 'PDS.NAME(MEMBER)' '1 2 3 4 5' without changing the program and the output should look like following
arg(1) = 1
arg(2) = 2
arg(3) = 3
arg(4) = 4
arg(5) = 5
Is this possible in REXX?
I tried exploring the PARSE ARG option without any success.
Regards
Bidpar |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Jun 06, 2003 8:30 am Post subject: |
|
|
Instead of parse option, you can use WORDS() function. This will give you no of variables in the input argument (separated by spaces).
Try this:
Code: |
numarg = WORDS(arg_variable)
ARG(1) = WORD(arg_variable, 1)
ARG(2) = WORD(arg_variable, 2)
|
and so on
Hope this helps, |
|
Back to top |
|
 |
Phantom Data Mgmt Moderator

Joined: 07 Jan 2003 Posts: 1056 Topics: 91 Location: The Blue Planet
|
Posted: Fri Jun 06, 2003 8:33 am Post subject: |
|
|
Sorry, the code was incomplete, Use this.
Code: |
numarg = WORDS(arg_variable)
do I = 1 TO numarg
say 'arg(' || i || ') =' || WORD(arg_variable, I)
end
|
WORD(variable, n) will return the n'th word in the input variable.
Thanks |
|
Back to top |
|
 |
bidpar Beginner
Joined: 08 Jan 2003 Posts: 28 Topics: 4 Location: india
|
Posted: Wed Jun 11, 2003 1:42 am Post subject: |
|
|
Working fine.
Thank you Phantom. |
|
Back to top |
|
 |
|
|