Comparing INTO DATA VS FIELD-SYMBOL To Update Internal Table

When you want to update records of an internal table using LOOP ENDLOOP. The most common practice would be copying each row into a working are (INTO DATA) and modify the internal table afterwards.

Many developers still unaware of the performance issues caused by this technique. In this tutorial, we’ll do a comparation between INTO DATA and FIELD-SYMBOLS, the two common ways for updating internal table records.

Tutorial Objectives
1. Understand the different usage of INTO DATA and FIELD-SYMBOL.
2. Performance test between INTO DATA and FIELD-SYMBOL to see which one is better
Prerequisites
1. SAP System: SAP GUI, ECC
2. Authorization: Developer role, SE38.

The Basic Declaration of INTO DATA and FIELD-SYMBOL in a LOOP

The INTO DATA and FIELD-SYMBOL syntaxes are used for dynamic data handling, allowing you to declare a working area at runtime. With INTO DATA( ), the data object is created dynamically during runtime, similar to how a FIELD-SYMBOL can reference dynamic data objects.

"INTO DATA
LOOP ITAB INTO DATA( your_variable ).
ENDLOOP.

"OR

"FIELD-SYMBOL
LOOP ITAB ASSIGNING FIELD-SYMBOL(<fs_name>).
ENDLOOP.

While both methods achieve the same result (updating records in a loop), their underlying mechanisms differ significantly, especially when it comes to performance.

Using INTO DATA

When using INTO DATA to modify an internal table from inside a loop, you’re basically copying the table row into a working area. And after you’ve updated some values, the old table row will be replaced by the new one using the MODIFY statement as shown below.

The Process of copying and updating the row will eventually effecting the performance for a large datasets.

So what’s the solution? The solution is by start using FIELD-SYMBOL for modifying your internal tables.

Using FIELD-SYMBOL For Faster Performance

Unlike using INTO DATA and followed by MODIFY statement, FIELD-SYMBOL act as pointers to memory locations of your records, allowing you to work directly with the data without creating any copies.

By using FIELD-SYMBOL the steps are simpler and faster. It’s more efficient for large tables since no deep copy is involved.

Performance Test Between INTO DATA and FIELD-SYMBOL

Here’s a quick performance test I did earlier by comparing the two methods for processing internal table with 20,000 records. You can copy the code below.

*& ABAPGeeks.com
*& MODIFY VS FIELD-SYMBOL Performance testing
*& Declare variable for timestamp
data: l_start  type timestampl,
      l_end    type timestampl,
      l_result type timestampl.
data: l_perct type p DECIMALS 2.
*& Declare sorted table for performance sake
data: it_mara type sorted table of mara with unique key matnr.
*& Get 20000 records from Mara table
select * from mara into table it_mara up to 20000 rows.
*& Start testing for MODIFY table
get time stamp field l_start.
loop at it_mara into data(wa_mara).
  wa_mara-laeda = sy-datum.
  modify it_mara from wa_mara transporting laeda.
endloop.
get time stamp field l_end.
l_result = l_end - l_start.

write: / 'Modify Result in:', l_result, 'seconds'.
*& Start testing using FieldSymbol To Update
get time stamp field l_start.
loop at it_mara ASSIGNING FIELD-SYMBOL(<fs>).
  <fs>-laeda = sy-datum.
endloop.
get time stamp field l_end.
l_result = l_end - l_start.

write: / 'FieldS Result in:', l_result, 'seconds'.

Now let’s check out the result.

As you can see, the FIELD-SYMBOL is like two times faster than using MODIFY table.

Conclusion

  1. Use INTO DATA for simplicity and readability when working with small datasets or performing occasional updates.
  2. Use FIELD-SYMBOL if you want to have faster performance or dealing with large datasets. Its ability to directly reference memory makes it significantly faster and more efficient.
Share this tutorial with Fellow Geeks!

Other ABAP Tutorials

Leave a Reply

Your email address will not be published. Required fields are marked *