Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

abap

I have one doubt. May I know what the difference between LIKE and LIKE LINE OF in ABAP is? I have seen somewhere that while declaring the work area they are declaring.

wa LIKE it_one
wa LIKE LINE OF it_one
like image 854
Srinivas Rachumallu Avatar asked Jul 24 '14 04:07

Srinivas Rachumallu


People also ask

Is like line of is obsolete in SAP ABAP?

LIKE - obsolete - ABAP Keyword Documentation. Outside of classes, the addition LIKE can also be used to refer to flat structures, database tables, or classic views in ABAP Dictionary, as well as to their components. A LIKE reference to the flat components of a deep dictionary structure is not possible.

What is difference between like and type in ABAP?

Type is a keyword used to refer to a data type whereas Like is a keyword used to copy the existing properties of already existing data object. The ABAP type concept distinguishes between data types and data objects. or globally in the ABAP Dictionary.

What is like table of in SAP ABAP?

If a reference is made to a data type in ABAP Dictionary, its primary components are transformed to predefined ABAP types in accordance with the tables of predefined types in ABAP Dictionary. LIKE can be used to refer to data objects, and also to the public attributes of global classes.

What is difference between data and types in SAP ABAP?

In TYPE STATEMENT you can define structure which have no physical memory on the other hand in DATA STATEMENT you can define structure with physical memory.


2 Answers

LIKE LINE OF means that the variable will be of the table line type.

LIKE means that the variable will be exactly of the same type as the one sitting after this key word.

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.
like image 194
Jagger Avatar answered Nov 15 '22 10:11

Jagger


Well, the difference is when you pass table into subroutine with USING or TABLES.

In 1st case you will get a table without headerline, thus WA_LIKE will be a table too.

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. Particulary, DATA ... LIKE IT_DATA will refer to headerline, and not entire internal table.

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.
like image 24
Nikolai Kim Avatar answered Nov 15 '22 11:11

Nikolai Kim