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 issue in report

Former Member
0 Likes
923

Dear experts,

is there any alternative solution for following code

     IF wa_final-vat_cst IS INITIAL .

       READ TABLE it_mseg INTO wa_mseg WITH KEY  mblnr = wa_j_1iexcdtl-rdoc2 mjahr = p_docyr matnr = wa_j_1iexcdtl-matnr..

       READ TABLE it_rseg INTO wa_rseg WITH KEY lfbnr = wa_mseg-lfbnr .

       LOOP AT it_temp INTO wa_temp WHERE lfbnr = wa_rseg-lfbnr.

         READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey = wa_temp-awkey . " belnr = wa_temp-belnr.

         READ TABLE it_bset INTO wa_bset WITH KEY belnr = wa_bkpf-belnr kschl = 'JVRD'.

         wa_final-belnr = wa_bkpf-belnr.

         lv_kbetr = wa_bset-kbetr / 10.

*        wa_final-vat_cst = wa_bset-hwste.

*      modify it_final FROM wa_final.

       ENDLOOP.

     ENDIF.



Regards,

Danny

1 ACCEPTED SOLUTION
Read only

RaymondGiuseppi
Active Contributor
0 Likes
886

First read (again) documentation of READ TABLE and LOOP AT WHERE statement, look for ‘performance’.

  • Insure that tables read with READ TABLE are sorted either by SORT (then add a BINARY SEARCH) or (better) by their type.
  • For ‘it_temp’, to optimize the LOOP AT WHERE, you cannot use SORT but must use a TYPE SORTED or equivalent (HASHED, secondary index) definition.

Regards,

Raymond

First read (again) documentation of READ TABLE and LOOP AT WHERE statement, look for ‘performance’.

  • Insure that tables read with READ TABLE are sorted either by SORT (then add a BINARY SEARCH) or (better) by their type.
  • For ‘it_temp’, to optimize the LOOP AT WHERE, you cannot use SORT but must use a TYPE SORTED or equivalent (HASHED, secondary index) definition.

Regards,

Raymond

6 REPLIES 6
Read only

former_member196331
Active Contributor
0 Likes
886

HI,

One Small suggestions I would like to suggest.

After read statement immediately  You have to check .

Read statement.

if sy-subrc eq 0.

read statement

if sy-subrc eq 0.

endif.

endif.

If the record is existing  or not we can know.

Read only

Former Member
0 Likes
886

Include Sort by and read with binary search.

Read only

Former Member
0 Likes
886

Thank u guys

Read only

0 Likes
886

Hi,

modify your code like this::

SORT  it_mseg BY MLBNR MJAHR MATNR.

SORT IT_RSEG BY LFBNR.

SORT IT_BKPF BY AWKEY .

SORT IT_BSET BY BELNR.

IF wa_final-vat_cst IS INITIAL .

       READ TABLE it_mseg INTO wa_mseg WITH KEY  mblnr = wa_j_1iexcdtl-rdoc2 mjahr = p_docyr matnr = wa_j_1iexcdtl-matnr BINARY SEARCH.

       READ TABLE it_rseg INTO wa_rseg WITH KEY lfbnr = wa_mseg-lfbnr   BINARY SEARCH.

       LOOP AT it_temp INTO wa_temp WHERE lfbnr = wa_rseg-lfbnr.

         READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey = wa_temp-awkey BINARY SEARCH " belnr = wa_temp-belnr  BINARY SEARCH.

         READ TABLE it_bset INTO wa_bset WITH KEY belnr = wa_bkpf-belnr kschl = 'JVRD'.

         wa_final-belnr = wa_bkpf-belnr  BINARY SEARCH.

         lv_kbetr = wa_bset-kbetr / 10.

*        wa_final-vat_cst = wa_bset-hwste.

*      modify it_final FROM wa_final.

       ENDLOOP.

     ENDIF.

thanks!!

Read only

RaymondGiuseppi
Active Contributor
0 Likes
887

First read (again) documentation of READ TABLE and LOOP AT WHERE statement, look for ‘performance’.

  • Insure that tables read with READ TABLE are sorted either by SORT (then add a BINARY SEARCH) or (better) by their type.
  • For ‘it_temp’, to optimize the LOOP AT WHERE, you cannot use SORT but must use a TYPE SORTED or equivalent (HASHED, secondary index) definition.

Regards,

Raymond

Read only

Former Member
0 Likes
886

hi,

there is a concept of parallel cursor in SAP ABAP to avoid performance issues with nested loops with where condition.

data: lv_tabix type sy-tabix.

sort it_temp by lfbnr.

read table it_temp into wa_temp with key lfbnr = wa_resg-lfbnr.

if sy-subrc is initial.

  lv_tabix  = sy-tabix.

LOOP AT it_temp INTO wa_temp FROM lv_tabix.

  if wa_resg-lfbnr <> wa_temp-lfbnr.

  exit.

  endif.

READ TABLE it_bkpf INTO wa_bkpf WITH KEY awkey = wa_temp-awkey BINARY SEARCH " belnr = wa_temp-belnr  BINARY SEARCH.

   READ TABLE it_bset INTO wa_bset WITH KEY belnr = wa_bkpf-belnr kschl = 'JVRD'.

         wa_final-belnr = wa_bkpf-belnr  BINARY SEARCH.

         lv_kbetr = wa_bset-kbetr / 10.

ENDLOOP.

thanks!!