SAP ABAP

参考英文原版教程请移步 Tutorialspoint

一、基本数据类型

Type keyword
Byte field X
Text field C
Integer I
Floating point F
Packed number(压缩号) P
Text String STRING

Some of the fields and numbers can be modified using one or more names as the following

  1. byte
  2. numeric
  3. character-like

二、ABAP数据类型概览

Type Typical Length Typical Range
X 1 byte Any byte values (00 to FF)
C 1 char 1 to 65535
N 1 char 1 to 65535
D (date) 8 chars 8 characters
T (time) 6 chars 6 characters
I 4 bytes -2147483648 to 2147483647
F 8 bytes 2.2250738585072014E-308 to 1.7976931348623157E+308 positive or negative
P 8 bytes [-10^(2len -1) +1] to [+10^(2len -1) 1] (where len = fixed length)
STRING Variable Any alphanumeric characters
XSTRING Variable Any byte values (00 to FF)

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
REPORT ZHELLO1.
DATA text_line TYPE C LENGTH 40.
text_line = 'A Chapter on Data Types'.
Write text_line.
DATA text_string TYPE STRING.
text_string = 'A Program in ABAP'.
Write / text_string.
DATA d_date TYPE D.
d_date = SY-DATUM.
Write / d_date.

Output

1
2
3
A Chapter on Data Types
A Program in ABAP
12092015

注:WRITE / ... 可用于换行,相当于\n


三、Complex and Reference Types 复杂类型与引用类型

The complex types are classified into Structure types and Table types. In the structure types, elementary types and structures (i.e. structure embedded in a structure) are grouped together. You may consider only the grouping of elementary types. But you must be aware of the availability of nesting of structures.

When the elementary types are grouped together, the data item can be accessed as a grouped data item or the individual elementary type data items (structure fields) can be accessed. The table types are better known as arrays in other programming languages. Arrays can be simple or structure arrays. In ABAP, arrays are called internal tables and they can be declared and operated upon in many ways when compared to other programming languages. The following table shows the parameters according to which internal tables are characterized.

Parameter Description
Line or row type Row of an internal table can be of elementary, complex or reference type.
Key Specifies a field or a group of fields as a key of an internal table that identifies the table rows. A key contains the fields of elementary types.
Access method Describes how ABAP programs access individual table entries.

Reference types are used to refer to instances of classes, interfaces, and run-time data items. The ABAP OOP run-time type services (RTTS) enables declaration of data items at run-time.