CLASS-DATA 静态属性-理解

来源:互联网 发布:崇州行知中学 编辑:程序博客网 时间:2024/05/22 14:28

CLASS-DATA  

Syntax

语法

CLASS-DATA attr [options].

ClASS-DATA attr(属性)[可选]

Effect

The statement CLASS-DATA can only be used in the declaration part of a class or an interface. The statement declares a static attribute attr whose validity is not associated with instances of a class but with the class itself. All instances of the class and its subclasses access the same static attribute.

作用

语句CLASS-DATA只允许被声明在接口或者类中,这个语句定义一个静态属性attr的有效性是和类的实例无关的,只对类的本身有效。所有的类的实例和子类都可以访问这个静态属性。

 

The naming conventions apply to the name attr. The syntax of the additions options is identical to the statementDATA for instance attributes (only the addition WITH HEADER LINE must not be used).

SAP命名规则都适用attr的命名。除了WITH HEADER LINE 不可以用。

 

Notes

  • Like all static components in the inheritance, the static attributes of a superclass exist in all subclasses. A static attribute that is visible externally can be addressed using the class component selector along with all the names of the classes in which it exists. This means that the class in which it is declared is always addresssed, which, for example, has an impact on how thestatic constructor is executed. A change made to the static attribute applies to all classes in which it exists, independently of the addressing.
  • You can access static attributes declared with CLASS-DATA by using the class component selector only with class names, and not with interface names.
  • The static attributes of a Shared Memory-enabled class are handled in the same way as a normal class, that is they are created in internal mode of a program when the class is loaded. If a number of programs access the same shared objects, the static attributes of the corresponding classes exist more than once and independently of one another in the programs.
  • Structured static attributes can be declared as a static box using the addition BOXED.

注意

1.        像所有的在继承中的静态组件,静态属性存在于所有继承父类的子类中。静态的属性,该属性是可见的外部使用类组件选择器可以解决随着它存在的类中的所有的名字。这意味着类在声明的时候已经被定义,举例来说,如何执行构造函数有影响。如果静态属性改变,那么所有的类都会影响,会独立的寻找地址。

2.        你可以访问CLSS-DATA定义的静态属性只用类的名字,而不是接口的名字。

3.        作为一个普通的类,这是他们内部的程序模式是建立在加载类时,共享内存功能的类的静态属性以同样的方式处理,如果不同的程序访问类中静态属性,那么这些动态属性是相互独立的。

4.        动态属性接口可以声明成一个static box,用语句 BOXED.

Example

In this example, the static attribute text of class c1 is accessed using the class component selector without having created an instance of the class.

这个例子,在一个类中静态文本属性,没用实例化就可以访问。

 

 

 

以下就测试。

1. SAP官方提供的例子测试。

report  yhk1.*----------------------------------------------------------------------**       CLASS c1 DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*class c1 definition.  public section.    class-data text type string value `Static data`.endclass.                    "c1 DEFINITIONstart-of-selection.  write c1=>text.


 

2. 稍微更改程序,定义另外一个不是静态属性的TEXT,然后直接访问,会有什么错误。

*----------------------------------------------------------------------**       CLASS c1 DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*class c1 definition.  public section.    class-data text type string value 'Static data'.    data text1 type string.endclass.                    "c1 DEFINITIONstart-of-selection.  write: / c1=>text.  write: / cl1->text1.


3.实例化CLASS.

report  yhk1.class c1 definition deferred.*----------------------------------------------------------------------**       CLASS c1 DEFINITION*----------------------------------------------------------------------***----------------------------------------------------------------------*class c1 definition.  public section.    class-data text type string value 'Static data'.    data text1 type string.endclass.                    "c1 DEFINITIONstart-of-selection.  data: cl1 type ref to c1.  create object cl1.  cl1->text1 = 'TEST'.  write: / c1=>text.  write: / cl1->text1.