data和type有以下六种语法形式:
1.利用预定义类型(I F N P D T C X):
DATA { {var[(len)] TYPE abap_type [DECIMALS dec]}
| {var TYPE abap_type [LENGTH len] [DECIMALS dec]} }
[VALUE val|{IS INITIAL}]
[READ-ONLY].
TYPES { {dtype[(len)] TYPE abap_type [DECIMALS dec]}
| {dtype TYPE abap_type [LENGTH len] [DECIMALS dec]} }.
2.引用已经存在的类型(包括dataelement 和 程序中定义的类型和数据):
DATA var { {TYPE [LINE OF] type}
| {LIKE [LINE OF] dobj} }
[VALUE val|{IS INITIAL}]
[READ-ONLY].
TYPES dtype { {TYPE [LINE OF] type}
| {LIKE [LINE OF] dobj} }.
3.引用变量或类型:
DATA ref { {TYPE REF TO type}
| {LIKE REF TO dobj} }
[VALUE IS INITIAL]
[READ-ONLY].
TYPES dtype { {TYPE REF TO type}
| {LIKE REF TO dobj} }.
4.定义STRUCTURE
DATA BEGIN OF struc [READ-ONLY].
...
{DATA comp ...} | {INCLUDE {TYPE|STRUCTURE} ...}.
...
DATA END OF struc.
TYPES BEGIN OF struc_type.
...
{TYPES dtype ...} | {INCLUDE {TYPE|STRUCTURE} ...}.
...
TYPES END OF struc_type.
5.定义类表:
DATA itab { {TYPE tabkind OF [REF TO] type}
| {LIKE tabkind OF dobj} }
[WITH key] [INITIAL SIZE n]
[WITH HEADER LINE]
[VALUE IS INITIAL]
[READ-ONLY].
TYPES dtype { {TYPE tabkind OF [REF TO] type}
| {LIKE tabkind OF dobj} }
[WITH key] [INITIAL SIZE n].
6.平行表:
DATA rtab {TYPE RANGE OF type}|{LIKE RANGE OF dobj}
[INITIAL SIZE n]
[WITH HEADER LINE]
[VALUE IS INITIAL]
[READ-ONLY].
TYPES dtype {TYPE RANGE OF type}|{LIKE RANGE OF dobj}
[INITIAL SIZE n].
field-symbols的用法
FIELD-SYMBOLS <fs> { typing | STRUCTURE struc DEFAULT dobj }.
其中typing的语法
... { TYPE generic_type }
| { TYPE {[LINE OF] complete_type}
| {REF TO {data|complete_type|class|intf}} }
| { LIKE {[LINE OF] dobj}
| {REF TO dobj} } ...
其中genric type 为不完全类型,一般包括
any | Any data type (suitable for any type) |
any table | Internal table of any table type |
c | Text field of generic length |
clike | Character-type (c, d, n, t, string and character-type flat structures); in non- Unicode programs also x, xstring and any flat structures |
csequence | Text-type (c, string) |
data | Any data type |
hashed table | Hashed table |
index table | Index table |
n | numeric text of generic length |
numeric | Numeric (b, i, p, f, s) |
object | Any object type (root class of the inheritance hierarchy) |
p | Packed number of generic length and generic number of decimal places |
simple | Elementary data type including structured types with exclusively character-type flat components |
sorted table | Sorted table |
Standard table | Standard table |
table | Standard table |
x | Byte field of generic length |
xsequence | byte-type (x, xstring) |
而complete type指具体明确的类型不具有一般性