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

How to identify caller of subroutine in REXX


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

New User


Joined: 20 May 2008
Posts: 3
Location: Leuven - Belgium

PostPosted: Mon Jun 22, 2009 6:23 pm
Reply with quote

Hi,

is it possible to retrieve the name of the calling (main) REXX procedure in a called (subroutine) REXX procedure?

Thanks for the info
Gie

e.g. MyMain exec:

/* REXX main routine*/

V1 = 5
Call MySUB V1
If result > ....

exit
----------------------------------------------------------------
MySub exec:


/* REXX sub routine */
ARG Vx

/* -> I want to know the identity of the caller here */

Return x
----------------------------------------------------------------
Back to top
View user's profile Send private message
genesis786

Active User


Joined: 28 Sep 2005
Posts: 210
Location: St Katherine's Dock London

PostPosted: Mon Jun 22, 2009 9:07 pm
Reply with quote

i think one way is to pass the caller program name (main) to called program (subroutine).

MAIN
Code:


/* rexx */                 
say 'in MAIN'             
call SUBRTN MAIN           
say 'out of SUBRTN, in MAIN'
exit                       



SUBRTN

Code:

 /* rexx */           
 parse arg caller_pgm 
 say 'in SUBRTN'       
 say caller_pgm       
 return               
Back to top
View user's profile Send private message
Gie Indesteege

New User


Joined: 20 May 2008
Posts: 3
Location: Leuven - Belgium

PostPosted: Mon Jun 22, 2009 9:21 pm
Reply with quote

Thank you for that information, but I wanted to know if it is possible to obtain the caller's identity without passing the name as an argument?

In other words: is it possible to get access to the calling stack of the REXX interpreter?

Gie
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Jun 22, 2009 9:39 pm
Reply with quote

if Your rexx subroutine functions needs to behave differently when called from different <caller>
from any point of view , the most appropriate way is to put an additional parm to select the proper subroutine/function behavior
Back to top
View user's profile Send private message
ofer71

Global Moderator


Joined: 27 Dec 2005
Posts: 2358
Location: Israel

PostPosted: Mon Jun 22, 2009 11:51 pm
Reply with quote

Take a look at the PARSE SOURCE instruction.

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

New User


Joined: 20 May 2008
Posts: 3
Location: Leuven - Belgium

PostPosted: Tue Jun 23, 2009 2:03 pm
Reply with quote

PARSE SOURCE only returns information on the way the routine is called (FUNCTION, SUBROUTINE or EXEC). Not the name of the caller.

Passing additional information is a valuable option, but this means that existing programs have to be modified.

I wondered whether it is/was possible to access the calling 'stack' in REXX to get that information, without changing existing 'caller' procs.

Gie
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Tue Jun 23, 2009 2:57 pm
Reply with quote

Quote:
but this means that existing programs have to be modified.


partially true, a good way around it would be to modify only the subroutine
checking the number of parameters, something along the lines

Code:
parse version _version_
say "parse version _version_" _version_
parse source  _source_
say "parse source  _source_ " _source_

call sub1 a, b, c
call sub1 f, a, b, c
call sub1 f


exit

sub1:
say "inside  sub1 "
if arg() = 3 then do
say "called old style"
parse arg arg1, arg2, arg3
end
else  if arg() = 4 then do
say "called new style"
parse arg funccode, arg1, arg2, arg3
end
else ,
say "called with wrong arg count"
return


or using a two stage parsing...
parse as if a function code was provided
if the assumed function code is invalid , reparse onlu for the real args
something like

Code:
a = "a"
b = "b"
c = "c"
f = "f"
f1 = "f1"
f2 = "f2"
f2 = "f2"

call sub1 a, b, c
call sub1 f, a, b, c
call sub1 f


call sub2 a, b, c
call sub2 f1, a, b, c
call sub2 f2, a, b, c

exit

sub1:
say "inside  sub1 "
if arg() = 3 then do
say "called old style"
parse arg arg1, arg2, arg3
end
else  if arg() = 4 then do
say "called new style"
parse arg funccode, arg1, arg2, arg3
end
else ,
say "called with wrong arg count"
return


sub2:
say "inside  sub2 "
parse arg funccode, arg1, arg2, arg3
if wordpos(funccode,"f1 f2 f3 f4") = 0 then do
funccode = "default"
parse arg arg1, arg2, arg3
end
say "sub2 called with funccode" funccode
return
Back to top
View user's profile Send private message
jasorn
Warnings : 1

Active User


Joined: 12 Jul 2006
Posts: 191
Location: USA

PostPosted: Sun Oct 25, 2009 8:03 pm
Reply with quote

While the suggested solutions seem to make sense, I'd like to know the name of the calling routine for the sake of reporting purposes and would rather not rely on a passed argument.

Does the fact no solution to do that was given mean it's not possible or very hard to do?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Mon Oct 26, 2009 1:05 am
Reply with quote

Quote:
Does the fact no solution to do that was given mean it's not possible or very hard to do?

not possible
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 Running REXX through JOB CLIST & REXX 13
No new posts Error to read log with rexx CLIST & REXX 11
No new posts isfline didnt work in rexx at z/OS ve... CLIST & REXX 7
No new posts run rexx code with jcl CLIST & REXX 15
No new posts Execute secondary panel of sdsf with ... CLIST & REXX 1
Search our Forums:

Back to Top