LOCAL

Basic form

LOCAL f.



This statement is not allowed in an ABAP Objects context.

See Cannot Use the LOCAL statement.

Effect

The LOCAL statement can only be used after FORM and FUNCTION.
Saves the current value of the specified field f when you enter the routine and restores it when you leave the routine.
You should not regard the LOCAL statement as a declaration. It only saves the value of f at the point where the form was called.
You can also use LOCAL for field symbols and formal parameters. With field symbols, it not only saves and restores the field reference created using ASSIGN, but also the contents of the field referenced when you enter the routine.
With formal parameters, please note that although changing the value of the formal parameter does not affect the actual parameter after you leave the routine (if you specified the formal parameter after LOCAL), the values of the formal and actual parameter within the routine are always identical.
This contrasts with the VALUE specification (see FORM) where changing the passed field within the routine does not affect the value of the formal parameter.

Example

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.

When the example is executed, the system temporarily (and seperately) stores the value of the global variant text twice. Once by specifying the name in subr1 and the second time by specifying the formal parameter para, which text is transferred to by reference. After its return from subr2, text has the value set in subr1 and after its return from subr1, text has the value set in the main program.






Note

You cannot use the LOCAL statement with internal tables if the code before and after the statement has been called within a LOOP performed on an internal table.
Within a loop performed on an internal table, the MOVE statement is carried out by the LOCAL statement and the table is then copied back. This destroys the LOOP administration for the table.

Additional help

Global Data from the Main Program