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

Passing Stem(array) to calling program


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

New User


Joined: 22 Sep 2013
Posts: 81
Location: pune india

PostPosted: Thu Aug 07, 2014 9:56 am
Reply with quote

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
View user's profile Send private message
Paul Voyner

New User


Joined: 26 Nov 2012
Posts: 52
Location: UK

PostPosted: Thu Aug 07, 2014 11:49 am
Reply with quote

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
View user's profile Send private message
trushant.w

New User


Joined: 22 Sep 2013
Posts: 81
Location: pune india

PostPosted: Thu Aug 07, 2014 12:03 pm
Reply with quote

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
View user's profile Send private message
mistah kurtz

Active User


Joined: 28 Jan 2012
Posts: 316
Location: Room: TREE(3). Hilbert's Hotel

PostPosted: Thu Aug 07, 2014 12:17 pm
Reply with quote

try this
Code:
PAS_STRING = ELEMENT.1

DO I=2 TO ELEMENT.0
    PAS_STRING = PAS_STRING || '~' || ELEMENT.I
END
Back to top
View user's profile Send private message
trushant.w

New User


Joined: 22 Sep 2013
Posts: 81
Location: pune india

PostPosted: Thu Aug 07, 2014 1:02 pm
Reply with quote

Hi mistah,

This is working perfectly.

Thanks Mistah and Paul
Back to top
View user's profile Send private message
Paul Voyner

New User


Joined: 26 Nov 2012
Posts: 52
Location: UK

PostPosted: Thu Aug 07, 2014 1:06 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Thu Aug 07, 2014 6:11 pm
Reply with quote

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
View user's profile Send private message
Steve Coalbran

New User


Joined: 01 Feb 2007
Posts: 89
Location: Stockholm, Sweden

PostPosted: Mon Aug 25, 2014 7:36 pm
Reply with quote

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? icon_wink.gif
Back to top
View user's profile Send private message
Steve Coalbran

New User


Joined: 01 Feb 2007
Posts: 89
Location: Stockholm, Sweden

PostPosted: Tue Aug 26, 2014 10:11 am
Reply with quote

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 /*>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/

icon_smile.gif
Back to top
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1314
Location: Vilnius, Lithuania

PostPosted: Wed Aug 27, 2014 4:09 am
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed Aug 27, 2014 2:13 pm
Reply with quote

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
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10886
Location: italy

PostPosted: Wed Aug 27, 2014 10:34 pm
Reply with quote

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
View user's profile Send private message
prino

Senior Member


Joined: 07 Feb 2009
Posts: 1314
Location: Vilnius, Lithuania

PostPosted: Wed Aug 27, 2014 10:43 pm
Reply with quote

Obviously missed that one. icon_redface.gif icon_redface.gif icon_redface.gif
Back to top
View user's profile Send private message
Mickeydusaor

Active User


Joined: 24 May 2006
Posts: 258
Location: Salem, Oregon

PostPosted: Thu Aug 28, 2014 1:56 am
Reply with quote

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
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 Passing containers on START command CICS 4
No new posts Error to invoke MPP program through B... IMS DB/DC 3
No new posts Using API Gateway from CICS program CICS 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
Search our Forums:

Back to Top