SAP
ABAP
参考英文原版教程请移步 Tutorialspoint
一、声明语句
Each variable in ABAP has a specific type, which determines
- Size and layout of the variable’s memory
- Range of values that can be stored within that memory
- Set of operations that can be applied to the variable
Tag | Description |
---|---|
f | Name (MAX 30) |
type | Data Type |
val | Initial value |
Example
|
|
ABAP共包含以下三种变量类型
- Static 静态变量
- Reference 引用变量
- System 系统变量
二、Static Variables 静态变量
Delared in subroutines, function modules, and static methods
Statement | Discription |
---|---|
CLASS-DATA | Declare variables within the classes |
PARAMETERS | Declare the elementary data objects that are linked to input fields on a selection screen |
SELECT-OPTIONS | Declare the internal tables that are linked to input fields on a selection screen |
- 不可使用特殊字符如
t
,
- 预定义的对象名称不可更改
- 变量名称不可与ABAP关键字相同
- 变量名称须表达真实含义
- 避免使用连字符
-
- 可使用下划线
_
分隔连词
|
|
三、Reference Variables 引用变量
|
|
Statement | Description |
---|---|
REF TO | Declares a reference |
Type | Specifies the static type of the reference variable |
The static type | Restricts the set of objects to which can refer |
The dynamic type | Data type or class to which it currently refers |
- The static type is always more general or the same as the dynamic type.
- The TYPE addition is used to create a bound reference type and as a start value, and only IS INITIAL can be specified after the VALUE addition.
|
|
- In the above code snippet, an object reference Oref and two data reference variables Dref1 and Dref2 are declared.
- Both data reference variables are fully typed and can be dereferenced using the dereferencing operator
→*
at operand positions.
四、System Variables 系统变量
- 所有ABAP程序均可访问 ABAP system variables are accessible from all ABAP programs.
- 由运行时环境赋值 These fields are actually filled by the run-time environment.
- 系统变量可在任何时间获取,并指示系统状态 The values in these fields indicate the state of the system at any given point of time.
- SAP的SYST表中记录所有系统变量 You can find the complete list of system variables in the SYST table in SAP.
- 使用前缀访问独立字段 Individual fields of the SYST structure can be accessed by using either “SYST-” or “SY-”.
|
|
以上程序输出如下
|
|