Skip to Content

SAP ABAP how to get the called program name in the calling program (both are standard programs)

Dec 05, 2017 at 01:21 PM


avatar image


There are 2 standard programs.

1. prgm1

2. Prgm2

Prgm2 is being called internally from prgm1. (Inside prgm1 there is a submit statement for prgm2)

Now there is a BADI that needs to be implemented as a part of my requirement.( Inside prgm2 we have the BADI implementation)

The issue is that this BADI should be trigged only when the report prgm1 is executed and should not be triggered when directly prgm2 is executed.

How to get which is the starting program that executed the report in this case?

sy-repid and sy-cprog are giving only the prgm2 name even it is being run from prgm1.

Also call system stack related FM's are giving the details of the prgm2 only and not prgm1.

Please help me with this.

10 |10000 characters needed characters left characters exceeded

Rather an odd requirement... Are you sure there is no other criteria? And why do you need to do this?



No there is no other criteria. :(

Its part of my clients requirement and he specifically mentioned it.



* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Bartosz Siminski Dec 05, 2017 at 09:00 PM

Hi Atmakur,

This is related to the concept of internal sessions. From SAP doc:

When a program is called, the calling program can be exited either temporarily or completely. For a temporary exit from the calling program, the called program is started in a new internal session. The internal session of the calling program is retained. The calling program and the called program represent a call sequence. Within a call sequence, the programs have shared access to the ABAP Memory (statements IMPORT FROM MEMORY and EXPORT TO MEMORY). A call sequence can have a maximum of nine internal sessions. If this maximum is exceeded, the program terminates and the entire call sequence is deleted.

So you can use ABAP Memory to achieve required result in this way:

report z_rep_1. 
export sy-cprog to memory id 'ZCPROG'. 
submit z_rep_2.

And the called one..

report z_rep_2. 
data lv_prog like sy-cprog. 
import sy-cprog to lv_prog from memory id 'ZCPROG'. 
free memory id 'ZCPROG'. 
write / lv_prog.
Show 4 Share
10 |10000 characters needed characters left characters exceeded


The reports that i am referring are not custom reports they are standard SAP reports.

So its very difficult to implement your solution. :(




You may add custom code to standard SAP reports easily using the Enhancement Framework.

If you cannot pass the caller information via the SUBMIT parameters, then the only possible way is to use the ABAP memory, as Bartosz explained.


There is no other solution, I'm afraid. As you can see, the calling program must let the other program know where it came from. This can be done either using memory (as Bartosz explained) or a parameter (as Sandra mentioned).

I'm still not clear, however, what exactly is the purpose of such design. "Client requirement" is not a sufficient explanation, I'm afraid. What exactly are you trying to achieve with this? What's the importance?

When "client" comes up with such "requirement" they need to understand the technical implications, both short and long term. And it's a consultant's duty to guide them to the best solution, not just blindly help them to shot themselves in a foot. (If they keep insisting though - it's their foot, of course.)


Hi All,

Thanks a lot for this. I will communicate the same to my client that this is only possible via enhancement using ABAP memory.

I have posted this to know whether there is any other solution (lets say an FM,system variable or something) before letting the client know about it. Thanks for let me know all the possible ways.



Gerrit Beukema Dec 05, 2017 at 08:43 PM


Show 1 Share
10 |10000 characters needed characters left characters exceeded


System_callstack gives only the details of pgm2 and not the details of PGM1.

So this doesn't work in my case.