[英]What is the difference between "Data" and "Types" creating a structure?
I found 2 examples for creating a structure.我找到了 2 个创建结构的示例。
This one with TYPES
:这个带有TYPES
:
TYPES : BEGIN OF employee_information,
name TYPE c LENGTH 20,
surname TYPE c LENGTH 20,
tel_no TYPE n LENGTH 12,
END OF employee_information.
and this other one with DATA
:而另一个带有DATA
:
DATA : BEGIN OF employee_information,
name TYPE c LENGTH 20,
surname TYPE c LENGTH 20,
tel_no TYPE n LENGTH 12,
END OF employee_information.
I read the documentation topic " The Statements TYPES and DATA " in the SAP Library, but I don't understand why we use these distinct terms TYPES
and DATA
for creating a structured data type.我阅读了 SAP 库中的文档主题“ 语句类型和数据”,但我不明白为什么我们使用这些不同的术语TYPES
和DATA
来创建结构化数据类型。
Can you explain the difference?你能解释一下区别吗?
First of all, creating a TYPE is the newer and recommended method to use.首先,创建 TYPE 是较新且推荐使用的方法。
When you create a DATA, lets say for an internal table;创建 DATA 时,可以说是内部表;
DATA: BEGIN OF employee_information OCCURS 0, "itab with header line
name TYPE c LENGTH 20,
surname TYPE c LENGTH 20,
tel_no TYPE n LENGTH 12,
END OF employee_information.
You can have the internal table with header line.您可以拥有带有标题行的内部表格。 But this is the old method.但这是旧方法。
When you use TYPE in order to declare an internal table you can use its headerline and its content simultaneously;当你使用 TYPE 来声明一个内部表时,你可以同时使用它的标题和它的内容;
TYPES: BEGIN OF t_employee_information,
name TYPE c LENGTH 20,
surname TYPE c LENGTH 20,
tel_no TYPE n LENGTH 12,
END OF t_employee_information.
DATA: employee_information TYPE STANDARD TABLE OF t_employee_information INITIAL SIZE 0, "itab
employee_information TYPE t_employee_information. "work area (header line)
For example: You can use this TYPE in order to create as many internal tables as you want such as:例如:您可以使用此 TYPE 来创建任意数量的内部表,例如:
DATA: employee_information_1 TYPE TABLE OF t_employee_information, "itab1
employee_information_1 TYPE t_employee_information. "work area1 (header line)
DATA: employee_information_2 TYPE TABLE OF t_employee_information, "itab2
employee_information_2 TYPE t_employee_information. "work area2 (header line)
DATA: employee_information_3 TYPE TABLE OF t_employee_information, "itab3
employee_information_3 TYPE t_employee_information. "work area3 (header line)
The TYPES
statement creates a data type which are templates for creating data objects. TYPES
语句创建一个数据类型,它是用于创建数据对象的模板。
The DATA
statement creates a data object which is an instance of a data type and occupies as much memory space as its type specifies. DATA
语句创建一个数据对象,它是数据类型的一个实例,占用的内存空间与其类型指定的一样多。
The first thing is that this code you posted is surely wrong, you started the type as employee_information
and ended it as personel_bilgileri
.第一件事是,您发布的这段代码肯定是错误的,您将类型开头为employee_information
并以personel_bilgileri
结尾。
The thing is that the second declaration defines employee_information
variable which has the structure of name, surname and tel_no
.问题是第二个声明定义了employee_information
变量,该变量具有name, surname and tel_no
的结构。 In the second case you define a type employee_information
.在第二种情况下,您定义了一个类型employee_information
。 Then you can define a variable of this structured type for example as DATA: l_str_employee_information TYPE
employee_information`.然后你可以定义一个这种结构化类型的变量,例如DATA: l_str_employee_information TYPE
employee_information`。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.