LOCAL (not allowed in classes) saves the current content of a data object
dobj in an internal buffer. It can be used only in
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.
Modifiable formal parameters of the procedure, field symbols, or dereferenced data references are also
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.
LOCAL is used, in particular, to protect global variables of the
master program declared
DATA from unwanted changes during
a procedure. Instead of using
LOCAL, the global data of the master program should not be accessed in procedures.
When the following program section is executed, the value of the global variable
is buffered twice, once by specifying the name in
subr1 and a second time
subr2 by specifying the formal parameter
text is passed by reference. After returning from
text once again has the value that is set in
and after returning from
text assumes the value set in the framework 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.