STATICS

Simple Static Field Definitions

- STATICS f.
- STATICS f(len).

Structured Static Data Object Definitions
- STATICS: BEGIN OF struc,
              ...
               END   OF struc
.




Structured Static Internal Table Definition
- STATICS itab TYPE tabtype [WITH HEADER LINE].
- STATICS itab TYPE tabkind OF linetype
             [WITH [UNIQUE|NON-UNIQUE] keydef]
             [INITIAL SIZE n] [WITH HEADER LINE].
- STATICS itab LIKE tabkind OF lineobj
            [WITH [UNIQUE|NON-UNIQUE] keydef]
            [INITIAL SIZE n] [WITH HEADER LINE].
- STATICS itab TYPE linetype OCCURS n [WITH HEADER LINE].
- STATICS itab LIKE lineobj  OCCURS n [WITH HEADER LINE].
- STATICS: BEGIN OF itab OCCURS n,
           ...
         END   OF itab [VALID BETWEEN f1 AND f2].
STATICS itab TYPE RANGE OF type.
STATICS itab LIKE RANGE OF f

Effect

The STATICS statement is a variation of the DATA statement. It allows you to define variables in a procedure (CLASS-METHODS, FORM, or FUNCTION) with local visibility, but static validity.

This statement is not allowed in methods. See STATICS not allowed in instance methods.

Local visibility means that static variables, like normal local variables created with DATA, can be accessed by their name only within the defining procedure.

Static validity means that, unlike normal local variables, the life of static variables does not depend on the defining procedure, but on the program at runtime. Static variables are thus not redefined on the stack each time the defining procedure is called, but exist independently of this in the program and keep their value, regardless of calls to the defining procedure.

Like all other data objects, static variables always have a particular data type. Data types and data objects are important components of the ABAP type concept.

Example

DATA RESULT TYPE I.

PERFORM RANDOM CHANGING RESULT.

FORM RANDOM CHANGING P_RESULT TYPE I.
  STATICS L_STATE TYPE I.
  L_STATE = ( L_STATE * 113 + 34 )  MOD 256.
  P_RESULT = L_STATE.
ENDFORM.

Additional help

Local Data in a Subroutine