LOCAL dobj.
The statement LOCAL (not allowed in classes) saves the current content of a data object dobj in an internal temporary storage area. It can be used only in sub-programs or funtion modules. At the end of the procedure, the data object dobj is reassigned to the value in temporary storage. If LOCAL is executed in a procedure for a data object several times, only the first execution is taken into account.
For dobj all data objects possible in write positions can be specified. If dobj is an internal table, the procedure should not be called within a LOOP-Loop that processes the table.
After LOCAL, changeable formal parameters of the procedure,
field symbols or dereferenced data references are also possible. When formal parameters are specified,
at the end of the procedure the assigned actual parameter is set to the value in temporary storage. With field symbols, the field reference and the content of the referenced fields are stored.
The statement LOCAL serves, 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.
When executing the following program section, the value of the global variable text is stored temporarily twice, in separate places: once by specifying the name in subr1 and and a second time in subr2 by specifying the formal parameter para, to which text will be transferred by reference. After coming back from subr2, text once again has the value that is set in subr1, and after return 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.