static variable,

最近做Exit module是,遇到static variable,从SAP help的解释中发现其和印象中的概念有出入,因此对其作如下的小结,主要是个人理解和翻译,如有出入,欢迎大家指正。

       首先是 static variable的使用范围: SAP help

1. subroutines

2. function module

3. static methods

static variable和Data变量一样,只能在有效范围内使用,超出其使用范围就不可视了。但static variable的特殊性是,子程序中static variable的最终值能在其范围外的main program的过程中保持不变,下次再进入该子程序(以上的static variable的使用范围)时,就在原有的值上进行相应操作了。

对于例子,SAP help也给出了相应的例子,我作出相应的改动,示例如下:

DO 10 TIMES.
  PERFORM add_one.
ENDDO.

FORM add_one.
  DATA local TYPE i VALUE 10.
  STATICS static TYPE i VALUE 10.
  STATICS text TYPE i.

  local = local + 1.
  static = static + 1.
  text  = text + 1.
  WRITE: / 'local ', local.
  WRITE: / 'static',static.
  WRITE: / 'text  ', text.

ENDFORM.

运行结果如下:

local          11
static         11
text            1
local          11
static         12
text            2
local          11
static         13
text            3
local          11
static         14
text            4
local          11
static         15
text            5
local          11
static         16
text            6
local          11
static         17
text            7
local          11
static         18
text            8
local          11
static         19
text            9
local          11
static         20
text           10

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值