STATICS
Short Reference
ABAP Syntax STATICS stat [ options ].
What does it do? Declaration of static variables stat . The
statement STATICS for declaring static variables can only be used
in static methods ,
function modules , and
subroutines .
The naming conventions apply to the
stat name. The syntax for the options additions is the
same as for the DATA statement for declaring
normal variables. Only the additions READ-ONLY
, BOXED , and the declaration of
LOB handle structures are not
possible.
As with normal local variables, variables declared with STATICS
are only visible within the procedure . The
lifespan of a variable declared with STATICS is the same as that
of a global data object. The variable is generated once when the
framework program is loaded to the
internal session, and its contents are assigned the
start value of the VALUE addition.
Calling and ending the procedure have no effect on the lifespan and
content.
Latest notes: In instance methods, the statement STATICS is not
allowed. Instead, static attributes
of the class declared using CLASS-DATA can
be used.
Example ABAP Coding The subroutine add_one returns the same result
for the variable local for each call as this is instantiated
again each time. The static variable static is already available
and its value increased by 1 during each call.
DO 10 TIMES.
PERFORM add_one.
ENDDO.
cl_demo_output=>display( ).
FORM add_one.
DATA local TYPE i VALUE 10.
STATICS static TYPE i VALUE 10.
local = local + 1.
static = static + 1.
cl_demo_output=>write( |Local: { local }, | <(> <)><(> <)>
|Static: { static }| ).
ENDFORM.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved