释疑の语法LOCAL

来源:互联网 发布:淘宝怎样找妹子服务 编辑:程序博客网 时间:2024/06/06 12:44

作用就是把当前对象保存在一个临时存储空间,它只能用到子程序或者FUNTION MODULE里,在程序结束的时候数据对象重新分配在临时空间的值。

如果用LOCAL对同一个对象执行了好几遍,那么只有第一次执行起作用。

语法:LOCAL dobj.

The statement LOCAL (not allowed in classes) saves the current content of a data objectdobj in an internal buffer. It can be used only in subroutines or function modules. At the end of the procedure, the data objectdobj is reassigned to the value in the buffer. If LOCAL is executed in a procedure for a data object more than once, only the first execution is taken into account.

All data objects possible in write positions can be specified fordobj. If dobj is an internal table, the procedure should not be called within aLOOP loop that processes the table.

Modifiable formal parameters of the procedure, field symbols, or dereferenced data references are also possible afterLOCAL. If formal parameters are specified, the assigned actual parameter is set to the value in the buffer at the end of the procedure. For field symbols, the field reference and the content of the referenced fields are saved. 

例子:

DATA TEXT TYPE STRING VALUE 'Global text'.

CL_DEMO_OUTPUT=>WRITE_TEXTTEXT ).

PERFORM SUBR1.

CL_DEMO_OUTPUT=>DISPLAY_TEXTTEXT ).

FORM SUBR1.
  LOCAL TEXT.
  TEXT 'Text in subr1'.
  CL_DEMO_OUTPUT=>WRITE_TEXTTEXT ).
  PERFORM SUBR2 USING TEXT.
  CL_DEMO_OUTPUT=>WRITE_TEXTTEXT ).
ENDFORM.

FORM SUBR2 USING PARA TYPE STRING.
  LOCAL PARA.
  PARA 'Text in subr2'.
  CL_DEMO_OUTPUT=>WRITE_TEXTTEXT ).
ENDFORM.

输出:



1 0