Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Performance enhancement for parallel loops

Former Member
0 Likes
1,180

Hi,

I have performance problem for the following parallel loops.Please help me solve this to improve performance of report,urgently.

LOOP AT xt_git_ekpo INTO lv_wa_ekpo.

lv_wa_final-afnam = lv_wa_ekpo-afnam.

LOOP at xt_git_ekkn into lv_wa_ekkn where ebeln = lv_wa_ekpo-ebeln

and ebelp = lv_wa_ekpo-ebelp.

lv_wa_final-meins = lv_wa_ekpo-meins.

READ TABLE xt_git_ekko INTO lv_wa_ekko

WITH KEY ebeln = lv_wa_ekpo-ebeln

BINARY SEARCH.

IF sy-subrc IS INITIAL.

lv_wa_final-ebeln = lv_wa_ekko-ebeln.

lv_wa_final-ebelp = lv_wa_ekpo-ebelp.

lv_wa_final-txz01 = lv_wa_ekpo-txz01.

lv_wa_final-aedat = lv_wa_ekko-aedat.

READ TABLE xt_git_lfa1 INTO lv_wa_lfa1

WITH KEY lifnr = lv_wa_ekko-lifnr

BINARY SEARCH.

IF sy-subrc IS INITIAL.

lv_wa_final-lifnr = lv_wa_lfa1-lifnr.

lv_wa_final-name1 = lv_wa_lfa1-name1.

ENDIF.

LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE ebeln = lv_wa_ekpo-ebeln

AND ebelp = lv_wa_ekpo-ebelp.

waiting for quick reply.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
672

Hi,

if u have Nested loops then its better to use PARALLEL CURSOR Method.

Nested Loops – This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.

Program using Normal Nested Loop:

REPORT  ZNORMAL_NESTEDLOOP.

TABLES:
  likp,
  lips.

Data:
  t_likp  type table of likp,
  t_lips  type TABLE OF lips.

data:
  W_RUNTIME1 TYPE I,
  W_RUNTIME2 TYPE I.

START-OF-SELECTION.
select *
  from likp
  into table t_likp.

select *
  from lips
  into table t_lips.

get RUN TIME FIELD w_runtime1.

loop at t_likp into likp.
  loop at t_lips into lips where vbeln eq likp-vbeln.
  endloop.
endloop.

get RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

write w_runtime2.

Nested Loop using Parallel Cursor:

REPORT  zparallel_cursor2.

TABLES:
  likp,
  lips.

DATA:
  t_likp  TYPE TABLE OF likp,
  t_lips  TYPE TABLE OF lips.

DATA:
  w_runtime1 TYPE i,
  w_runtime2 TYPE i,
  w_index LIKE sy-index.

START-OF-SELECTION.
  SELECT *
    FROM likp
    INTO TABLE t_likp.

  SELECT *
    FROM lips
    INTO TABLE t_lips.

  GET RUN TIME FIELD w_runtime1.
  SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.

    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE w_runtime2.

Analysis report: Runtime in microseconds:

Iteration No.... Normal Nested Loop..._Using Parallel Cursor_

1 ......................34,796,147................. 63,829

2 .......................38,534,583 ................. 56,894

3 ......................34,103,426 .................. 50,510

please check this link

http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm

reward if helpful

raam

Hi,

if u have Nested loops then its better to use PARALLEL CURSOR Method.

Nested Loops – This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.

Program using Normal Nested Loop:

REPORT  ZNORMAL_NESTEDLOOP.

TABLES:
  likp,
  lips.

Data:
  t_likp  type table of likp,
  t_lips  type TABLE OF lips.

data:
  W_RUNTIME1 TYPE I,
  W_RUNTIME2 TYPE I.

START-OF-SELECTION.
select *
  from likp
  into table t_likp.

select *
  from lips
  into table t_lips.

get RUN TIME FIELD w_runtime1.

loop at t_likp into likp.
  loop at t_lips into lips where vbeln eq likp-vbeln.
  endloop.
endloop.

get RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

write w_runtime2.

Nested Loop using Parallel Cursor:

REPORT  zparallel_cursor2.

TABLES:
  likp,
  lips.

DATA:
  t_likp  TYPE TABLE OF likp,
  t_lips  TYPE TABLE OF lips.

DATA:
  w_runtime1 TYPE i,
  w_runtime2 TYPE i,
  w_index LIKE sy-index.

START-OF-SELECTION.
  SELECT *
    FROM likp
    INTO TABLE t_likp.

  SELECT *
    FROM lips
    INTO TABLE t_lips.

  GET RUN TIME FIELD w_runtime1.
  SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.

    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE w_runtime2.

Analysis report: Runtime in microseconds:

Iteration No.... Normal Nested Loop..._Using Parallel Cursor_

1 ......................34,796,147................. 63,829

2 .......................38,534,583 ................. 56,894

3 ......................34,103,426 .................. 50,510

please check this link

http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm

reward if helpful

raam

5 REPLIES 5
Read only

Former Member
0 Likes
672

LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
   lv_wa_final-afnam = lv_wa_ekpo-afnam.

LOOP at xt_git_ekkn 
          into lv_wa_ekkn 
          where ebeln = lv_wa_ekpo-ebeln
             and ebelp = lv_wa_ekpo-ebelp.

       lv_wa_final-meins = lv_wa_ekpo-meins.

       READ TABLE xt_git_ekko INTO lv_wa_ekko
                 WITH KEY ebeln = lv_wa_ekpo-ebeln
                 BINARY SEARCH.

You must use a sorted table for xt_git_ekkn or use trick with standard tables,

see

Measurements on internal tables: Reads and Loops:

/people/siegfried.boes/blog/2007/09/12/runtimes-of-reads-and-loops-on-internal-tables

Last section (read binary search / Loop from index and EXIT !!!)

Siegfried

Read only

Former Member
0 Likes
673

Hi,

if u have Nested loops then its better to use PARALLEL CURSOR Method.

Nested Loops – This is one of the fear factors for all the ABAP developers as this consumes lot of program execution time. If the number of entries in the internal tables is huge, then the situation would be too worse. The solution for this is to use parallel cursor method whenever there is a need for Nested Loop.

Program using Normal Nested Loop:

REPORT  ZNORMAL_NESTEDLOOP.

TABLES:
  likp,
  lips.

Data:
  t_likp  type table of likp,
  t_lips  type TABLE OF lips.

data:
  W_RUNTIME1 TYPE I,
  W_RUNTIME2 TYPE I.

START-OF-SELECTION.
select *
  from likp
  into table t_likp.

select *
  from lips
  into table t_lips.

get RUN TIME FIELD w_runtime1.

loop at t_likp into likp.
  loop at t_lips into lips where vbeln eq likp-vbeln.
  endloop.
endloop.

get RUN TIME FIELD w_runtime2.

w_runtime2 = w_runtime2 - w_runtime1.

write w_runtime2.

Nested Loop using Parallel Cursor:

REPORT  zparallel_cursor2.

TABLES:
  likp,
  lips.

DATA:
  t_likp  TYPE TABLE OF likp,
  t_lips  TYPE TABLE OF lips.

DATA:
  w_runtime1 TYPE i,
  w_runtime2 TYPE i,
  w_index LIKE sy-index.

START-OF-SELECTION.
  SELECT *
    FROM likp
    INTO TABLE t_likp.

  SELECT *
    FROM lips
    INTO TABLE t_lips.

  GET RUN TIME FIELD w_runtime1.
  SORT t_likp BY vbeln.
  SORT t_lips BY vbeln.

  LOOP AT t_likp INTO likp.

    LOOP AT t_lips INTO lips FROM w_index.
      IF likp-vbeln NE lips-vbeln.
        w_index = sy-tabix.
        EXIT.
      ENDIF.
    ENDLOOP.
  ENDLOOP.

  GET RUN TIME FIELD w_runtime2.

  w_runtime2 = w_runtime2 - w_runtime1.

  WRITE w_runtime2.

Analysis report: Runtime in microseconds:

Iteration No.... Normal Nested Loop..._Using Parallel Cursor_

1 ......................34,796,147................. 63,829

2 .......................38,534,583 ................. 56,894

3 ......................34,103,426 .................. 50,510

please check this link

http://www.saptechnical.com/Tutorials/ABAP/ParallelCursor.htm

reward if helpful

raam

Read only

Former Member
0 Likes
672

LOOP AT

xt_git_ekpo INTO lv_wa_ekpo.

lv_wa_final-afnam = lv_wa_ekpo-afnam.

LOOP at

xt_git_ekkn into lv_wa_ekkn where ebeln = lv_wa_ekpo-ebeln

and ebelp = lv_wa_ekpo-ebelp.

lv_wa_final-meins = lv_wa_ekpo-meins.

READ TABLE xt_git_ekko INTO lv_wa_ekko

WITH KEY ebeln = lv_wa_ekpo-ebeln

BINARY SEARCH.

IF

sy-subrc IS INITIAL.

lv_wa_final-ebeln = lv_wa_ekko-ebeln.

lv_wa_final-ebelp = lv_wa_ekpo-ebelp.

lv_wa_final-txz01 = lv_wa_ekpo-txz01.

lv_wa_final-aedat = lv_wa_ekko-aedat.

READ TABLE xt_git_lfa1 INTO lv_wa_lfa1

WITH KEY lifnr = lv_wa_ekko-lifnr

BINARY SEARCH.

IF

sy-subrc IS INITIAL.

lv_wa_final-lifnr = lv_wa_lfa1-lifnr.

lv_wa_final-name1 = lv_wa_lfa1-name1.

ENDIF.

Read only

Former Member
0 Likes
672

Forget the parallel cursor stuff it is much to complicated in your case, for loop and read. And it is not better the a solution with binary searches.

Read my answer again if you don't understand it.

A loop if really necessary can not be replaced by a read so the third solution is also not applicable.

Read the last section of the blog, then you will get the solution.

Siegfried

Read only

Former Member
0 Likes
672

Hi

U can use SORTED TABLE instead of STANDARD TABLE:

DATA: xt_git_ekkn TYPE SORTED TABLE OF EKKN WITH NON-UNIQUE KEY EBELN EBELP,
          xt_git_ekbe  TYPE SORTED TABLE OF EKBE WITH NON-UNIQUE KEY EBELN EBELP.


LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
    lv_wa_final-afnam = lv_wa_ekpo-afnam.
    LOOP at xt_git_ekkn into lv_wa_ekkn where ebeln = lv_wa_ekpo-ebeln
                                                              and ebelp = lv_wa_ekpo-ebelp.
        lv_wa_final-meins = lv_wa_ekpo-meins.
        READ TABLE xt_git_ekko INTO lv_wa_ekko WITH KEY ebeln = lv_wa_ekpo-ebeln
                                                                                BINARY SEARCH.
        IF sy-subrc IS INITIAL.
          lv_wa_final-ebeln = lv_wa_ekko-ebeln.
          lv_wa_final-ebelp = lv_wa_ekpo-ebelp.
          lv_wa_final-txz01 = lv_wa_ekpo-txz01.
          lv_wa_final-aedat = lv_wa_ekko-aedat.
          READ TABLE xt_git_lfa1 INTO lv_wa_lfa1 WITH KEY lifnr = lv_wa_ekko-lifnr
                                                                                BINARY SEARCH.
          IF sy-subrc IS INITIAL.
             lv_wa_final-lifnr = lv_wa_lfa1-lifnr.
             lv_wa_final-name1 = lv_wa_lfa1-name1.
         ENDIF.

         LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE ebeln = lv_wa_ekpo-ebeln
                                                                         AND ebelp = lv_wa_ekpo-ebelp.

Anyway u should considere to upload in the internal table only the record of the current document, in this case u need to insert the SELECT into the loop:

SORT  xt_git_ekpo by EBELN EBELP.

LOOP AT xt_git_ekpo INTO lv_wa_ekpo.
    lv_wa_final-afnam = lv_wa_ekpo-afnam.

   IF lv_wa_ekkn-EBELN <>  lv_wa_ekpo-EBELN.
     SELECT * FROM EKKN INTO TABLE xt_git_ekkn WHERE EBELN = lv_wa_ekpo-EBELN.
     SELECT * FROM EKBE INTO TABLE xt_git_ekbe WHERE EBELN = lv_wa_ekpo-EBELN.
   ENDIF.

    LOOP at xt_git_ekkn into lv_wa_ekkn where ebelp = lv_wa_ekpo-ebelp.
        lv_wa_final-meins = lv_wa_ekpo-meins.
        READ TABLE xt_git_ekko INTO lv_wa_ekko WITH KEY ebeln = lv_wa_ekpo-ebeln
                                                                                BINARY SEARCH.
        IF sy-subrc IS INITIAL.
          lv_wa_final-ebeln = lv_wa_ekko-ebeln.
          lv_wa_final-ebelp = lv_wa_ekpo-ebelp.
          lv_wa_final-txz01 = lv_wa_ekpo-txz01.
          lv_wa_final-aedat = lv_wa_ekko-aedat.
          READ TABLE xt_git_lfa1 INTO lv_wa_lfa1 WITH KEY lifnr = lv_wa_ekko-lifnr
                                                                                BINARY SEARCH.
          IF sy-subrc IS INITIAL.
             lv_wa_final-lifnr = lv_wa_lfa1-lifnr.
             lv_wa_final-name1 = lv_wa_lfa1-name1.
         ENDIF.

         LOOP AT xt_git_ekbe INTO lv_wa_ekbe WHERE ebelp = lv_wa_ekpo-ebelp.

In my experience (for a very large number of records) this second solution was faster than the first one:

- Using the first solution (upload all data in internal table and use sorted table): my job takes 2/3 days

- Using the second solution: my job takes 1 hour.

Max