Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to identify caller of subroutine in REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
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    Post subject: How to identify caller of subroutine in REXX
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    Post subject:
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    Post subject: Reply to: How to identify caller of subroutine in REXX
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Mon Jun 22, 2009 9:39 pm    Post subject: Reply to: How to identify caller of subroutine in REXX
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: 2360
Location: Israel

PostPosted: Mon Jun 22, 2009 11:51 pm    Post subject:
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    Post subject: Reply to: How to identify caller of subroutine in REXX
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Tue Jun 23, 2009 2:57 pm    Post subject: Reply to: How to identify caller of subroutine in REXX
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

Active User


Joined: 12 Jul 2006
Posts: 153
Location: USA

PostPosted: Sun Oct 25, 2009 8:03 pm    Post subject:
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10210
Location: italy

PostPosted: Mon Oct 26, 2009 1:05 am    Post subject: Reply to: How to identify caller of subroutine in REXX
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    IBMMAINFRAMES.com Support Forums -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. Calling REXX code from ISPF panel sanchita dey TSO/ISPF 4 Mon Jan 02, 2017 5:13 pm
No new posts REXX DB2: Dynamic allocation of DB2.D... BHAS CLIST & REXX 3 Mon Dec 19, 2016 8:26 pm
No new posts find particular member name in PDS us... ravi243 CLIST & REXX 10 Mon Dec 19, 2016 6:44 pm
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 7 Fri Nov 18, 2016 1:48 pm
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us