STATICS ( SAP ABAP Keyword)

STATICS is a keyword used in SAP ABAP programming.This tutorial covers its introduction & syntax details.

STATICS

Variants

1. STATICS f.
2. STATICS f(len).
3. STATICS: BEGIN OF rec,

END OF rec.
4. STATICS: BEGIN OF itab OCCURS n,

END OF itab.

 

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

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/4 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.

More References