You are on page 1of 1

Getting the current call stack

Sometimes, especially inside user-exits that are called in several different places, we need to know where it was
called to decide what to do.

Some fields in the "sy" structure can be useful for this: sy-tcode (transaction), sy-repid (current main program), sy-
cprog, sy-xprog, sy-xform, etc.

This info might not be enough, however: we might need to know if we are inside a given form, for example, even if
we might be several levels below (the form called another form, which in turn called another form, that then called a
function, that called our exit..).

To know this, we need to get the current call stack. In debug mode, we can see it by clicking the button "Calls".
Getting that info in our programs is just as easy: just use function SYSTEM_CALLSTACK, and you'll get an
internal table with that same information.

MOD de func SYSTEM_CALLSTACK

Ej

* consultar la pila de llamadas que conducen a la exit y habilitar la


* generación de lote sólo en uno de las dos ejecuciones
DATA: lit_callstack TYPE SYS_CALLST,
lwa_callstack TYPE LINE OF SYS_CALLST.
CALL FUNCTION 'SYSTEM_CALLSTACK'
IMPORTING
ET_CALLSTACK = lit_callstack.
READ TABLE lit_callstack
INTO lwa_callstack
WITH KEY PROGNAME = 'SAPLV01Z' " Programa
EVENTTYPE = 'FUNC' " Clase de evento
EVENTNAME = 'VB_CREATE_BATCH'. " Nombre de un subrutina
CHECK sy-subrc = 0.

You might also like