Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarations →  Declaration Statements →  Data Types and Data Objects →  Declaring Data Objects 

STATICS

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


STATICS stat [options]. 

Effect

Declares 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 of the additions options is the same as for the statement DATA 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 created once when the master program is loaded to the internal session, and its content is assigned the start value of the VALUE addition. Calling and ending the procedure have no effect on the lifespan and content.


Note

In instance methods, the statement STATICS is not allowed. Instead, static attributes of the class declared using CLASS-DATA can be used.


Example

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.