Monday, 15 July 2019

LOOP AT performance Work area Vs Inline Work Area Vs Field Symbol Vs Inline Field Symbol

We are all using field symbol and work area for loop. But, we didn't measure, which is good performance.

Most of the time, We use work area to process the internal table. We can increase program performance sing the field-symbols.

Demo program

REPORT zloop_performance_test.

DATA v_start_time TYPE timestampl,
       v_end_time   TYPE timestampl,
       v_diff_w     TYPE DECIMALS 5.

TYPES BEGIN OF ty_vbrp,
          vbeln TYPE vbrp-vbeln,
        END OF ty_vbrp.

DATA lt_vbrp TYPE STANDARD TABLE OF ty_vbrp,
       ls_vbrp TYPE ty_vbrp.

FIELD-SYMBOLS <fs_vbrp> TYPE ty_vbrp.

PARAMETERS p_count TYPE n LENGTH 6.

* Start of selection

START-OF-SELECTION.

* Get billing item data
  SELECT vbeln
      FROM vbap
      INTO TABLE lt_vbrp
      UP TO p_count ROWS.

END-OF-SELECTION.

* 1 . Loop with work area

  GET TIME STAMP FIELD v_start_time.

  LOOP AT lt_vbrp INTO ls_vbrp.
  ENDLOOP.

  GET TIME STAMP FIELD v_end_time.
  v_diff_w v_end_time v_start_time.

  WRITE :/(30'Loop with Work area'v_diff_w.
  CLEAR v_start_timev_end_timev_end_time.
* 2 . Loop with work area inline declaration
  GET TIME STAMP FIELD v_start_time.

  LOOP AT lt_vbrp INTO DATA(ls_vbrp_inline).
  ENDLOOP.

  GET TIME STAMP FIELD v_end_time.

  v_diff_w v_end_time v_start_time.

  WRITE:/(30'Loop with Inline Work area'v_diff_w.
  CLEAR v_start_timev_end_timev_end_time.
*   3 . Loop with Field symbol
  GET TIME STAMP FIELD v_start_time.

  LOOP AT lt_vbrp ASSIGNING <fs_vbrp>.
  ENDLOOP.

  GET TIME STAMP FIELD v_end_time.

  v_diff_w v_end_time v_start_time.

  WRITE:/(30'Loop with Field Symbol'v_diff_w.
  CLEAR v_start_timev_end_timev_end_time.
* 4 . Loop with Field symbol inline declaration

  GET TIME STAMP FIELD v_start_time.

  LOOP AT lt_vbrp ASSIGNING FIELD-SYMBOL(<fs_vbrp_inline>).
  ENDLOOP.

  GET TIME STAMP FIELD v_end_time.

  v_diff_w v_end_time v_start_time.

  WRITE:/(30'Loop with Inline Field Symbol'v_diff_w.
  CLEAR v_start_timev_end_timev_end_time.

Results statistics



No comments:

Post a Comment