当前位置: 首页 > 工具软件 > node-static > 使用案例 >

STATICS

冯星阑
2023-12-01

STATICS

Syntax

STATICS stat [options].

Effect

Declaration of static variables stat. The statementSTATICS for declaring static variables can only be used insubroutines, function modules, and static methods.

The naming conventions apply to the stat name. The syntax for the additionsoptions is used for declaring normal variables as with the statementDATA. Only the additionREAD-ONLY is not possible.

As with normal local variables, one with STATICS declared variables can only be viewed in itsprocedure. The life of a variable with STATICS declared variables corresponds to the same one of a global data object. The variable is generated once when loading theframework program in the internal mode, and the contents set to thestart value of the VALUE addition. Calling and ending the procedure have no effect on the life and content.

Note

In instance methods, the statement STATICS is not allowed. Instead, you can usestatic attributes of the class, declared withCLASS-DATA.

Example

The subroutine add_1 gets the same result for the variablelocal for each call as this is instanced again each time. The static variablestatic is already available and its value increased by 1 during each call.

DO 10 TIMES.
  PERFORM add_one.
ENDDO.

FORM add_one.
  DATA    local  TYPE i VALUE 10.
  STATICS static TYPE i VALUE 10.
  local  = local  + 1.
  static = static + 1.
  WRITE: / local, static.
ENDFORM.


Test

        11          11
        11          12
        11          13
        11          14
        11          15
        11          16
        11          17
        11          18
        11          19
        11          20

效果
统计静态变量声明。声明静态变量的声明静力学只能用于子程序,功能模块和静态方法。

命名约定适用于的STAT名称。为增加选项的语法是用于报表数据的正常变量声明。只有另外只读是不可能的。

与正常的本地变量,一个与静力学声明的变量只能在其程序中查看。生活的一个静态的变量声明变量对应一个全局数据对象的同一个。变量生成一次装载在内部模式的框架方案时,内容设置起始值附加值。调用和结束程序的生命和内容没有影响。



注意
在实例方法中,声明静力学是不允许的。相反,你可以使用类的静态属性,声明类数据。



例子
子程序add_1得到相同的结果,因为这是每次实例再次为每个调用的局部变量。静态静态变量是已经提供,并在每次调用它的值增加1。

 类似资料:

相关阅读

相关文章

相关问答