ABAP - Keyword Documentation →  ABAP - Reference →  Obsolete Language Elements →  Obsolete modularization →  Temporary Storage of Data → 

LOCAL

Quick Reference

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 function 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, all executions are ignored except the first one.

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 master program declared with DATA from unwanted changes during a procedure. Instead of using LOCAL, the global data of the master program should not be accessed 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 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 master program.

DATA text TYPE string VALUE 'Global text'.

cl_demo_output=>write_text( text ).

PERFORM subr1.

cl_demo_output=>display_text( text ).

FORM subr1.
  LOCAL text.
  text = 'Text in subr1'.
  cl_demo_output=>write_text( text ).
  PERFORM subr2 USING text.
  cl_demo_output=>write_text( text ).
ENDFORM.

FORM subr2 USING para TYPE string.
  LOCAL para.
  para = 'Text in subr2'.
  cl_demo_output=>write_text( text ).
ENDFORM.