简体   繁体   English

ABAP中的like和like行有什么区别?

[英]What is the difference between like and like line of in ABAP?

I have one doubt. 我有一个疑问。 May I know what the difference between LIKE and LIKE LINE OF in ABAP is? 我可以知道ABAP中LIKELIKE LINE OF的区别是什么? I have seen somewhere that while declaring the work area they are declaring. 我在某个地方看到了宣布工作区域的声明。

wa LIKE it_one
wa LIKE LINE OF it_one

LIKE LINE OF means that the variable will be of the table line type. LIKE LINE OF表示变量将是表格行类型。

LIKE means that the variable will be exactly of the same type as the one sitting after this key word. LIKE表示该变量与该关键字后面的变量完全相同。

Example

TYPES: BEGIN OF t_my_example_structure,
    my_example_field1 TYPE i,
    my_example_field2 TYPE n,
  END OF t_my_example_structure.

TYPES tt_my_example_structure TYPE STANDARD TABLE OF t_my_example_structure.

DATA: l_tab_my_example TYPE tt_my_example_structure.

* has structure of row of l_tab_my_example so in this case t_my_example_structure.
DATA: l_str_my_example LIKE LINE OF l_tab_my_example.

* is exactly the same table type as l_tab_my_example so in this case tt_my_example_structure.
DATA: l_tab_like_my_example LIKE l_tab_my_example.

* I use it often for LOOP AT <tab> ASSIGNING <fs>.
FIELD-SYMBOLS: <fs_str_my_example> LIKE LINE OF l_tab_my_example.

Well, the difference is when you pass table into subroutine with USING or TABLES. 好吧,区别在于您使用USING或TABLES将表传递到子例程。

In 1st case you will get a table without headerline, thus WA_LIKE will be a table too. 在第一种情况下,您将得到一个没有标题的表,因此WA_LIKE也将是一个表。

In 2nd case IT_DATA will be a table with headerline: this causes IT_DATA actually means IT_DATA as structure or IT_DATA[] as table, depending on context. IT_DATA情况下, IT_DATA将是一个带有标题的表:这导致IT_DATA实际上意味着IT_DATA为结构, IT_DATA[]为表,具体取决于上下文。 Particulary, DATA ... LIKE IT_DATA will refer to headerline, and not entire internal table. 特别是, DATA ... LIKE IT_DATA将引用标题,而不是整个内部表。

You may check this using a debugger: 您可以使用调试器来检查:

DATA T_DATA TYPE STRING_TABLE.

PERFORM TEST_01 USING  T_DATA.
PERFORM TEST_02 TABLES T_DATA.

FORM TEST_01 USING IT_DATA TYPE STRING_TABLE.
  DATA : WA_LIKE LIKE         IT_DATA  "This is a Table
       , WA_LINE LIKE LINE OF IT_DATA.
  BREAK-POINT.
ENDFORM.

FORM TEST_02 TABLES IT_DATA TYPE STRING_TABLE.
  DATA : WA_LIKE LIKE         IT_DATA  "This is a String
       , WA_LINE LIKE LINE OF IT_DATA.
  BREAK-POINT.
ENDFORM.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM