Skip to Content

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


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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    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.
    Add comment
    10|10000 characters needed characters exceeded

    • 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.



  • Dec 05, 2017 at 08:43 PM


    Add comment
    10|10000 characters needed characters exceeded