ABAP Keyword Documentation → ABAP - Reference → Obsolete Language Elements → Obsolete modularization → Temporary Storage of Data
LOCAL
Other versions: 7.31 | 7.40 | 7.54
Obsolete Syntax
LOCAL dobj.
Effect
The statement LOCAL
(not allowed in classes) saves the current content of a data object dobj
in an internal buffer. It can be used only in
subroutines or
funtion modules. At
the end of the procedure, the data object dobj
is reassigned to the value
in the buffer. If LOCAL
is executed in a procedure for a data object more than once, only the first execution is taken into account.
All data objects possible in write positions
can be specified for dobj
. If dobj
is an internal
table, the procedure should not be called within a LOOP
loop that processes the table.
Modifiable formal parameters of the procedure, field symbols, or dereferenced data references are also
possible after LOCAL
. If formal parameters are specified, the assigned actual
parameter is set to the value in the buffer at the end of the procedure. For field symbols, the field reference and the content of the referenced fields are saved.
Note
The statement LOCAL
is used, in particular, to protect global variables of the
framework program declared
with DATA
from unwanted changes during
a procedure. Instead of using LOCAL
, you should avoid accessing the global data of the framework program in procedures.
Example
When executing the following program section, the value of the global variable text
is buffered twice, in separate locations: once by specifying the name in subr1
and and a second time in subr2
by specifying the formal parameter para
,
to which text
is passed by reference. After returning from subr2
,
text
once again has the value that is set in subr1
,
and after returning from subr1
, text
assumes the value set in the framework program.
DATA text TYPE string VALUE 'Global text'.
WRITE / text.
PERFORM subr1.
WRITE / text.
FORM subr1.
LOCAL text.
text = 'Text in subr1'.
WRITE / text.
PERFORM subr2 USING text.
WRITE / text.
ENDFORM.
FORM subr2 USING para TYPE string.
LOCAL para.
para = 'Text in subr2'.
WRITE / text.
ENDFORM.