Skip to content

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

STATICS

Quick 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 name stat. The syntax of the additions options is the same as for the statement DATA for declaring normal variables. The only additions that are not possible are READ-ONLY and BOXED and it is also not possible to declare LOB handle structures.

As with normal local variables, variables declared using STATICS are only visible within the procedure. The life span of a variable declared using 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 life span 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 method meth returns the same result for the variable local for each call, since this subroutine is instantiated again in every call. The static variable static already exists, on the other hand, and its value is raised by 1 in each call.

CLASS cls DEFINITION. 
  PUBLIC SECTION. 
    CLASS-METHODS meth. 
ENDCLASS. 

CLASS cls IMPLEMENTATION. 
  METHOD meth. 
    DATA    local  TYPE i VALUE 10. 
    STATICS static TYPE i VALUE 10. 
    local  += 1. 
    static += 1. 
    cl_demo_output=>write( |Local: { local }, | && 
                           |Static: { static }| ). 
  ENDMETHOD. 
ENDCLASS. 

START-OF-SELECTION. 
  DO 10 TIMES. 
    cls=>meth( ). 
  ENDDO. 
  cl_demo_output=>display( ).