I write a lot of REXX code using mainframe REXX.
I don't use other REXXs.
In my routines, I always start my subroutines with the name of the
routine left justified and, therefore, no comments between the start of the
line and the routine's name.
I have a routine that I copy into my REXXs that has a single purpose of
getting the name of the caller from within another routine.
I do this by passing the routine, GetCallersName(), the value of SIGL on
entry to the GetCallersName() routine.
I also pass an optional argument that controls how far the GetCallersName()
will search.
GetCallersName() looks backwards from the line indicated by SIGL for the
name of the routine by searching for the line that contains a colon (:") at
the end of the first word.
It uses the built-in function, SOURCELINE(), to retrieve the, you guessed
it, source statement at a specific line number, starting at the line
indicated by SIGL.
I set up a default search limit and then override it if the calling routine
passed a different value.
I usually code GetCallersName() right after the entry of a routine and save
the value in a variable.
For example:
MainRoutine:
Some statements....
call Routine1
Some statements...
exit
Routine1:
Routine1CalledFrom = sigl
statement making up routine 1....
Routine1CalledBy = GetCallersName(Routine1CalledFrom)
return
GetCallersName() will then start at the passed line number, arg(1), and
look for a line whose first word ends with a colon.
One that is found, or not, the first word is returned to the caller as the
name of the routine that called it.
Basically, the code in GetCallersName() is something like this:
ReturnName = "***"
do stmt# = arg(1) to arg(1) - searchlimit
stmt = sourceline(stmt#)
if right(word(stmt, 1), 1) = ":" then
ReturnName = left(word(stmt, 1), length(word(stmt, 1)) - 1)
end
return ReturnName
My routine is a bit more complex as it takes into account comments between
where the call to the routine was coded and the start of the calling
routine.
Hopefully this makes some sense.
Chuck
On Thu, Feb 6, 2025 at 3:39 PM Bob Bridges <
[email protected]> wrote:
> I don't know of a way that's built in to TSO-REXX. But if the need is
> important enough, you can always include the name of the caller as an arg
> in the call.
>
> In my own REXX execs I always start with the following:
>
> parse source . calltype self .
>
> SELF is the name of the routine, so if it has to abend because of some
> error it can say (eg)
>
> MYROUTIN abending with RC 8.
>
> Loss often I use CALLTYPE, but I can look at that and decide whether to
> return a value to the calling program or SAY it. The rest of the PARSE
> SOURCE data I never use.
>
> ---
> Bob Bridges, [email protected], cell 336 382-7313
>
> /* "I will tell you what I say", answered Ransom, jumping to his feet.
> "Of course good came of it. Is Maleldil a beast that we can stop His path,
> or a leaf that we can twist His shape? Whatever you do, He will make good
> of it. But not the good He had prepared for you if you had obeyed Him.
> That is lost forever. The first King and first Mother of our world did the
> forbidden thing; and He brought good of it in the end. But what they did
> was not good; and what they lost we have not seen." -from Pelelandra by C
> S Lewis */
>
> -----Original Message-----
> From: IBM Mainframe Discussion List <[email protected]> On Behalf
> Of Weizman arbel
> Sent: Thursday, February 6, 2025 02:27
>
> is it possible to retrieve the name of the calling (main) REXX procedure
> in a called (subroutine) REXX procedure?
>
> ----------------------------------------------------------------------
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to [email protected] with the message: INFO IBM-MAIN
>
----------------------------------------------------------------------
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to [email protected] with the message: INFO IBM-MAIN