Supply Chain Management Blogs by SAP
Expand your SAP SCM knowledge and stay informed about supply chain management technology and solutions with blog posts by SAP. Follow and stay connected.
cancel
Showing results for 
Search instead for 
Did you mean: 
bernd_dittrich
Active Participant

As we always have to think of mass processing in the TM context you often loop over data or retrieve data.

ABAP has basically 3 options:

  • LOOP AT itab into wa
  • LOOP AT itab assigning <fs>
  • LOOP AT itab reference into lr_data

Basically you should always use option 2 or 3. It´s in most cases faster compared to option one and never slower.

Here is a test report (thanks to Marcus Zahn who wrote the report) which quantifies this:

******************************************************************************************************

   DATA: lv_time_before       TYPE i,
      lv_time_after        TYPE i,
      lv_time_runtime_wa   TYPE i,
      lv_time_runtime_fs   TYPE i,
      lv_time_runtime_rf   TYPE i.
PARAMETERS: pa_count       TYPE i DEFAULT 10000.

DATA: lt_buf      TYPE /bobf/t_buf_simple_buffer,
      lt_buf_ref  TYPE /bobf/t_buf_simple_buffer,
      ls_buf      TYPE /bobf/s_buf_simple_buffer,
      lr_buf      TYPE REF TO /bobf/s_buf_simple_buffer,
      lv_key      TYPE /bobf/conf_key.

FIELD-SYMBOLS: <fs_buf> TYPE /bobf/s_buf_simple_buffer.

ls_buf-node = '123'.
ls_buf-key = '123'.
ls_buf-root_key = '123'.
ls_buf-parent_key = '123'.
ls_buf-node_cat_key = '123'.

DO pa_count TIMES.
  CREATE DATA ls_buf-data TYPE /scmtms/s_tor_item_tr_k.
  ls_buf-key = ls_buf-parent_key = ls_buf-key + 1.
  INSERT ls_buf INTO TABLE lt_buf_ref.

ENDDO.
SET RUN TIME CLOCK RESOLUTION HIGH.

**********************************************************************
* Field Symbols
lt_buf = lt_buf_ref.
GET RUN TIME FIELD lv_time_before.
LOOP AT lt_buf ASSIGNING <fs_buf>.
  lv_key = <fs_buf>-key.
ENDLOOP.
GET RUN TIME FIELD lv_time_after.
lv_time_runtime_fs lv_time_after - lv_time_before.
**********************************************************************

**********************************************************************
**** Reference reference into
lt_buf = lt_buf_ref.
GET RUN TIME FIELD lv_time_before.
LOOP AT lt_buf REFERENCE INTO lr_buf.
  lv_key = lr_buf->key.
ENDLOOP.
GET RUN TIME FIELD lv_time_after.
lv_time_runtime_rf = lv_time_after - lv_time_before.
**********************************************************************


**********************************************************************
* Workarea
lt_buf = lt_buf_ref.
GET RUN TIME FIELD lv_time_before.
LOOP AT lt_buf INTO ls_buf.
  lv_key = ls_buf-key.
ENDLOOP.
GET RUN TIME FIELD lv_time_after.
lv_time_runtime_wa = lv_time_after - lv_time_before.
**********************************************************************


WRITE
:/ 'Workarea:', lv_time_runtime_wa, 'ms'.
WRITE:/ 'Field symbol:', lv_time_runtime_fs, 'ms'.
WRITE:/ 'Reference into', lv_time_runtime_rf, 'ms'.

******************************************************************************************************

A result from our development systems shows the difference:

Report Performance wa/fs/ref

Workarea:      2.459  ms
Field symbol:      1.153  ms
Reference into      1.399  ms

The difference depends on the structure of the table line, but even for small structures (like key tables) the field-symbol / ref to data is as fast as the work area, the bigger the structure, the bigger the difference.

1 Comment