View previous topic :: View next topic
|
Author |
Message |
trushant.w
New User
Joined: 22 Sep 2013 Posts: 81 Location: pune india
|
|
|
|
Hi All
I am trying to pass all array elements to calling program from subprograme using retun statement.
My Stem elements are like below
Element.1
Element.2
Element.3
No of array element could be anything varying from 1 to n.
But when is use "Say result" in caling programe i am unable to dispplay the values of stem variable. |
|
Back to top |
|
|
Paul Voyner
New User
Joined: 26 Nov 2012 Posts: 52 Location: UK
|
|
|
|
If your subprogram is a different rexx in a different member, that won't work, can't work. RESULT is a single variable, never a stem.
If the array isn't too big, pass it back in result as a long string and then parse it in the calling program. |
|
Back to top |
|
|
trushant.w
New User
Joined: 22 Sep 2013 Posts: 81 Location: pune india
|
|
|
|
Hi Paul
Thanks for reply!!!
But how can i create a single concatenated string consisting of n elements of array/stem because here i cannot use concate operator (||) as no of elements in array can vary. |
|
Back to top |
|
|
mistah kurtz
Active User
Joined: 28 Jan 2012 Posts: 316 Location: Room: TREE(3). Hilbert's Hotel
|
|
|
|
try this
Code: |
PAS_STRING = ELEMENT.1
DO I=2 TO ELEMENT.0
PAS_STRING = PAS_STRING || '~' || ELEMENT.I
END |
|
|
Back to top |
|
|
trushant.w
New User
Joined: 22 Sep 2013 Posts: 81 Location: pune india
|
|
|
|
Hi mistah,
This is working perfectly.
Thanks Mistah and Paul |
|
Back to top |
|
|
Paul Voyner
New User
Joined: 26 Nov 2012 Posts: 52 Location: UK
|
|
|
|
You're welcome !
Maybe you've done this already, but this will parse the returned string
Code: |
/*rexx*/
trace R
string = "a a a a~bb bb bb~c c ~d"
l = length(string)
i = 1
do while l > 0
p = pos('~',string)
stem.i = left(string,p-1)
string = right(string,l-p)
l = length(string)
i = i + 1
end
exit |
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
and why not ...
Code: |
string = "a a a a~bb bb bb~c c ~d"
do i = 1 while ( string \= "")
parse var string stem.i "~" string
end
stem.0 = i - 1
do i = 1 to stem.0
say i stem.i
end
|
|
|
Back to top |
|
|
Steve Coalbran
New User
Joined: 01 Feb 2007 Posts: 89 Location: Stockholm, Sweden
|
|
|
|
Try this. It was actually written as an educational snippet...
Code: |
/**REXX*(RXCALLER)*/TRACE "O"
RC = BPXWDYN("ALLOC RTDDN(TDD) RTDSN(TDS) NEW REUSE UNIT(VIO)")
IF( RC<>0 )THEN EXIT 69
twister = "Peter Piper picked a peck of pickled peppers.",
"§A peck of pickled peppers Peter Piper picked.",
"§If Peter Piper picked a peck of pickled peppers,",
"§How many pickled peppers did Peter Piper pick?"
yourstem.0 = WORDS(twister)
l = 1
DO w = 1 TO yourstem.0
yourstem.w=WORD(twister,w)
IF( LEFT(yourstem.w,1)="§" )THEN l = l+1
END
SAY w "words in" l "lines."
"EXECIO" yourstem.0 "DISKW" tdd "(STEM yourstem. FINIS "
CALL RXCALLED tdd
EXIT /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/
/**REXX*(RXCALLED)*/ TRACE "O"
ARG tdd
"EXECIO * DISKR" tdd "(STEM yourstem. FINIS "
line = ""
line. = 0
eop = yourstem.0+1
yourstem.eop = "§"
DO w = 1 TO eop
twd = STRIP(yourstem.w)
IF( LEFT(twd,1)="§" )THEN DO
IF( LEFT(line,1)="§" )THEN
line = SUBSTR(line,2)
ELSE NOP
PARSE VALUE line.0+1 line";",
WITH t line.t ";" line 1 line.0 .
END
ELSE NOP
line = line||twd" "
END
"EXECIO" line.0 "DISKW" tdd "(STEM line. FINIS "
ADDRESS ISPEXEC "LMINIT DATAID(V) DDNAME("tdd") "
ADDRESS ISPEXEC "VIEW DATAID(&V) "
ADDRESS ISPEXEC "LMFREE DATAID(&V) "
"FREE DD("tdd") "
EXIT /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
I'm sure you can cut the tonge-twister processing out? |
|
Back to top |
|
|
Steve Coalbran
New User
Joined: 01 Feb 2007 Posts: 89 Location: Stockholm, Sweden
|
|
|
|
Simplified...
Code: |
/**REXX*(RZCALLER)*/TRACE "R"
RC = BPXWDYN("ALLOC RTDDN(TDD) RTDSN(TDS) NEW REUSE UNIT(VIO)")
IF( RC<>0 )THEN EXIT 69
stem.1 = "A"
stem.2 = "B"
stem.3 = "C"
stem.4 = "D"
stem.5 = "E"
stem.6 = "F"
stem.0 = "6"
"EXECIO" stem.0 "DISKW" tdd "(STEM stem. FINIS "
CALL RZCALLED tdd
EXIT /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
Code: |
/**REXX*(RZCALLED)*/ TRACE "O"
ARG tdd
"EXECIO * DISKR" tdd "(STEM stem. FINIS "
DO i = 1 TO stem.0
SAY stem.i
END
EXIT /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
enrico-sorichetti wrote: |
and why not ...
Code: |
string = "a a a a~bb bb bb~c c ~d"
do i = 1 while ( string \= "")
parse var string stem.i "~" string
end
stem.0 = i - 1
do i = 1 to stem.0
say i stem.i
end
|
|
Code: |
st.0 = 0
do while string \= ''
parse value st.0+1 string with ? st.? string 1 st.0 .
end |
|
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
prino wrote: |
Code: |
st.0 = 0
do while string \= ''
parse value st.0+1 string with ? st.? string 1 st.0 .
end |
|
OoOooh! Now that's interesting... |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10888 Location: italy
|
|
|
|
Code: |
#!/usr/bin/rexx
say "original snippet"
string = "a a a a~bb bb bb~c c~d"
do i = 1 while ( string \= "")
parse var string st.i "~" string
end
st.0 = i - 1
do i = 1 to st.0
say i st.i
end
drop st.
say "prino unmodified snippet, it will return words!"
string = "a a a a~bb bb bb~c c~d"
st.0 = 0
do while string \= ''
parse value st.0+1 string with ? st.? string 1 st.0 .
end
do i = 1 to st.0
say i st.i
end
drop st.
say "prino snippet, modified to return THE <strings> separated by ~"
string = "a a a a~bb bb bb~c c~d"
st.0 = 0
do while string \= ''
parse value st.0+1 string with ? st.? "~" string 1 st.0 .
end
do i = 1 to st.0
say i st.i
end
drop st.
|
|
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1315 Location: Vilnius, Lithuania
|
|
|
|
Obviously missed that one. |
|
Back to top |
|
|
Mickeydusaor
Active User
Joined: 24 May 2006 Posts: 258 Location: Salem, Oregon
|
|
|
|
do I = 1 to element.0
queue element.I
end
call sub-routine
sub-routine
element.0 = queued()
do I = 1 to element.0
pull element.I
end |
|
Back to top |
|
|
|