何时在 ABAP 中使用 TYPE 和 LIKE

when to use TYPE and LIKE in ABAP

为什么会出现这个错误

NAME must a flat structure you can not use internal table,string referenceses or structure as component

当我在第 2 行中使用 type 代替 like 时引发,没有显示任何错误,当我使用 like 时显示错误。

LIKETYPE有什么区别?

代码:

TYPES name(20) type c.    
data student_name like name.   "<=============== like or type
student_name = 'satya'.   
write student_name.

您已将 name 创建为 type。因此,如果你声明一个类型name的变量,你需要把语句写成data student_name type name.

现在,如果您想创建另一个变量 ,例如 变量 student_name,您可以在声明中使用 like 关键字作为 data student_name2 like student_name.

更详细的解释请参考documentation