STATICS stat [options].
Declaration of static variables stat. The statementSTATICS for declaring static variables can only be used insubroutines, function modules, and static methods.
The naming conventions apply to the stat name. The syntax for the additionsoptions is used for declaring normal variables as with the statementDATA. Only the additionREAD-ONLY is not possible.
As with normal local variables, one with STATICS declared variables can only be viewed in itsprocedure. The life of a variable with STATICS declared variables corresponds to the same one of a global data object. The variable is generated once when loading theframework program in the internal mode, and the contents set to thestart value of the VALUE addition. Calling and ending the procedure have no effect on the life and content.
In instance methods, the statement STATICS is not allowed. Instead, you can usestatic attributes of the class, declared withCLASS-DATA.
The subroutine add_1 gets the same result for the variablelocal for each call as this is instanced again each time. The static variablestatic is already available and its value increased by 1 during each call.
DO 10 TIMES.
PERFORM add_one.
ENDDO.
FORM add_one.
DATA local TYPE i VALUE 10.
STATICS static TYPE i VALUE 10.
local = local + 1.
static = static + 1.
WRITE: / local, static.
ENDFORM.
Test
11 11
11 12
11 13
11 14
11 15
11 16
11 17
11 18
11 19
11 20