Performance of ITAB Copy

By | June 13, 2011 | Performance | 10,162 | 3

Today, we’ll see another performance drainage – Internal Table Copy. If we don’t use the data properly, we’ll run into the situation where we’ll use lot of resoruces to perform the ITAB copy and end up reducing the performance of our application.

Sometimes, we pass the ITAB from one application to diffrent FM / Method, do some processing like modify certain fields or add some records in it and we get it back from the called module. If this FMs are called so many times it will affect the application performace at large.

We’ll first try to copy the data traditionally – using []. In the main program we have an internal table, which we pass to the FM ZTEST_NP_DATA_SET. Here we save the data to global memory of the Function Group into IT_EDIDD. We’ll call another FM ZTEST_NP_DATA_GET to get the data.

The second way, we’ll use the REF TO DATA. from our main program, we’ll get the reference of the data into O_DATA and pass it to FM ZTEST_NP_DATA_SET_1. We’ll get the data from the object reference. We’ll aslo save the data reference to the Function group Global data. We’ll call the FM ZTEST_NP_DATA_SET_2 to get the data from the FM to main program.

Code Snippet to show performance of ITAB Copy


*& Performance of ITAB Copy
*& Author: Naimesh Patel

REPORT  ztest_np_itab_copy.

DATAlwa_edidd LIKE LINE OF lt_edidd.

DATAlv_sta_time TYPE timestampl,
      lv_end_time TYPE timestampl,
      lv_diff_w   TYPE DECIMALS 5,
      lv_diff_f   LIKE lv_diff_w,
      lv_save     LIKE lv_diff_w.

DATAl_times TYPE i.


  l_times 10000.

* Table copy with []
  GET TIME STAMP FIELD lv_sta_time.
  DO l_times TIMES.
    lwa_edidd-sdata '1'.
    APPEND lwa_edidd TO lt_edidd.

        it_edidd lt_edidd.

        et_edidd lt_edidd.
  GET TIME STAMP FIELD lv_end_time.
  lv_diff_w lv_end_time lv_sta_time.
  WRITE/(30'Itab Copy'lv_diff_w.

* table passed with reference
  CLEAR lt_edidd.
  DATAlo_data TYPE REF TO data.
  GET TIME STAMP FIELD lv_sta_time.
  DO l_times TIMES.
    lwa_edidd-sdata '1'.
    APPEND lwa_edidd TO lt_edidd.

    GET REFERENCE OF lt_edidd INTO lo_data.

        io_edidd lo_data.

        eo_edidd lo_data.

  GET TIME STAMP FIELD lv_end_time.
  lv_diff_f lv_end_time lv_sta_time.
  WRITE/(30'Itab Copy with Reference'lv_diff_f.

Code FM ZTEST_NP_DATA_SET Data Copy using [ ]


*"*"Local Interface:

  t_edidd[] = it_edidd[].

  data: lwa_edidd like line of t_edidd.
  if lines( t_edidd ) = 500.
    append lwa_edidd to t_edidd.


Code FM ZTEST_NP_DATA_GET to data from FG


*"*"Local Interface:

  et_edidd = t_edidd.


Code FM ZTEST_NP_DATA_SET_1 – Data copy using REF TO DATA

FUNCTION ztest_np_data_set_1.
*"*"Local Interface:

  o_edidd = io_edidd.

  FIELD-SYMBOLS: <lt_edidd> TYPE tab_edidd.

  ASSIGN o_edidd->* TO <lt_edidd>.
  DATA: lwa_edidd LIKE LINE OF <lt_edidd>.

  IF LINES( <lt_edidd> ) = 500.
    APPEND lwa_edidd TO <lt_edidd>.


Code ZTEST_NP_DATA_GET_1 – Get Data reference back


*"*"Local Interface:

  eo_edidd = o_edidd.


Some stats on running the program with different number of records:

On graph when considering traditional ITAB copy as 100%:

So, if we use the traditional ITAB Copy, it will decrease the performance with increasing number of records.

Like It? Share!!

Don't miss an Update

Get notified of the new post, right into your inbox

Naimesh Patel{273 articles}

I'm SAP ABAP Consultant for more than a decade. I like to experiment with ABAP especially OO. I have been SDN Top Contributor.
Follow :

Explore all of his 273 articles.

Load comments


  • Thank you for the interesting view on data and references of data.
    Just to clarify: There is no real difference between ZTEST_NP_DATA_SET ztest_np_data_set_1 except that you pass the table parameter by value using VALUE(IT_EDIDD) in the first case. This will do one more copy of the table implicitly.
    The default is passing by reference.

    Note that all references work only in the same work process on the same server. This means all RFC, UPDATE TASK or BACHGROUND calls need the value parameter.

    Most advanced programming languages (as C or JAVA) use the reference concept for decades of years.

    It's a bit complicated and up to the user to do it in ABAP: No way without field-symbols and you must always be aware that any change to the referenced data means a change of the original data.

    Any change of t_edidd in the function group of ZTEST_NP_DATA_SET will not affect lt_edidd in the calling program; all changes of o_edidd->* or any field-symbol assigned to it are changes of lt_edidd in the calling program – although IO_EDIDD is IMPORT parameter of function ZTEST_NP_DATA_SET_1.

    In consequence, the clear concept of IMPORT, EXPORT and CHANGING parameters and the difference between CALL BY VALUE and CALL BY REFERENCE is undercut by passing references of data.

    You are given lots of ways to make your programs a lot faster but you must use much more time, concentration and experience to get it right or so find an error.

    Thanks for the chance to think about it!


  • Thanks Clemens your detailed reply.

    Yes we need to keep in mind that by using the REF TO DATA, we'll start using the reference of the actual data. So, any change in the reference will directly affect the original data.

    When we use the data copy by LT_TAB2 = LT_TAB1, system doesn't copy the data right away. It will only record what changes are being made to LT_TAB2. By growing number of records, it will take more time and resources to record all the changes made to LT_TAB2. We would loose data encapsulation.

    In recent times at a client's place, we had an issue where APPEND ITAB which was taking about 70% of time of the entire processing with about 25K records. At a close look we come to a fact that the root cause behind this was the ITAB2 = ITAB1 in our User-exit FM. By using the data with reference we were able to save lot of processing time thus resources.

    Naimesh Patel

  • Shariq

    One more big thanks for your demonstration and Presentation……

Comments on this Post are now closed. If you have something important to share, you can always contact me.

You seem to be new here. Subscribe to stay connected.