STATICS data type

The STATICS keyword is used to describe statically valid data within procedures. DATA-defined variables exist throughout the lifetime of the context in which they are defined. If they are defined in the global, they do not exist as long as the lifetime of the program, if they are defined in subroutines, when exiting the subroutine. STATICS data type are global variables specific to subroutines, unlike global, they cannot be used in another subroutine. They gain globality within the subroutine they are defined. Like DATA variables, the value in the subrout is not reset every time the subroutine is called, it continues to keep the last value they kept in the previous call when the same subroutine is called again.

Example:

REPORT ztest.

FORM test.
  DATA: lv_value TYPE i.
  STATICS: st_value TYPE i.

  lv_value = lv_value + 1.
  st_value = st_value + 1.
ENDFORM.

INITIALIZATION.

  PERFORM test.

  PERFORM test.

As you know everything in my first call, both variables are initialized from initial values +1 added.

The st_value variable defined with STATICS at the beginning of the second call continues to keep the value it received in the first call.

When +1’s are added at the end of the second call, lv_value becomes 1 because it is reset at every entry and becomes 2 because st_value holds the value.

When we left the subroutine, both variables were no longer available. To use it again, it is necessary to call the subroutine “test” again.

Leave a Reply

Your email address will not be published. Required fields are marked *