Page 1 of 1

getting the function name

Posted: August 31st, 2021, 3:01 pm
by AriSilva
Is there a way to have access to the function´s name that is being executed, similar to getsymbol to acces the proc´s name?
Such as "getfunction()"?
Best
Ari

Re: getting the function name

Posted: August 31st, 2021, 5:22 pm
by sherrell
Hi Ari,

No, sorry, we don't offer that. Is there a reason you need it?

Thanks,
Sherrell

Re: getting the function name

Posted: September 1st, 2021, 10:40 am
by AriSilva
The reason is not that crucial, I can always use a text field to have it.
I use this kind of information mainly to display messages to myself (in the trace function).
Sometimes I use it also to keep track of the program flow and, for a specific reason, I call a function from different other functions and I need to know who called this common function.
In either case I can survive, no problem, the fact is that using something like getfunctionname() produces a neater coding.
Best
Ari

Re: getting the function name

Posted: September 1st, 2021, 2:30 pm
by Gregory Martin
Can you just put this at the top of PROC GLOBAL?
set trace;
In your trace output, you'll be able to see the logic that was executed to get to the point that you're interested in tracking.

Re: getting the function name

Posted: September 2nd, 2021, 1:04 pm
by AriSilva
sure, I´m using it.
I´m tracking the program using that, but sometimes the routines are similar and by using the trace with the routine name helps me debugging.
Also, when cspro issues an error, like invalid subscript, it points to a proc, not to a function that was called inside the proc, and when you have a proc with several functions, and functions calling another functions it is a little difficult to get the error. Can you pinpoint the function that caused the error instead of the procedure that called it?
Best
Ari

Re: getting the function name

Posted: September 2nd, 2021, 8:11 pm
by Gregory Martin
Makes sense. The issue you raise with subscript errors is often brought up by a colleague. You can use "%p" in message text to get the procedure you're in, but as you note, there's no way to get the function name. We'll keep this on our list of feature requests. We would have to fully think it through, because you might also want the entire stack of code you're executing: PROC, function 1, function 2, etc.