Application Development 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: 

How can I Improve performance of Below code.

AadivaramAbbulu
Explorer
0 Kudos
519

Hi, 

As per my requirement i fetched multiple Queries, but while preparing final Internal table. 
Taking lot of time. One Scenario having 10 Days having 19k Records. Any possible way I Can improve the performance.

* SORT lt_cdpos BY changenr.
* SORT lt_user_addr BY bname.
* SORT lt_usr21 BY bname.
* SORT lt_adr6 BY persnumber.
LOOP AT lt_cdhdr ASSIGNING FIELD-SYMBOL(<ls_cdhdr>).
READ TABLE lt_cdpos WITH KEY changenr = <ls_cdhdr>-changenr ASSIGNING FIELD-SYMBOL(<ls_cdpos>).
IF sy-subrc = 0.
READ TABLE lt_user_addr WITH KEY bname = <ls_cdhdr>-username ASSIGNING FIELD-SYMBOL(<ls_user_addr>).
IF sy-subrc = 0.
READ TABLE lt_usr21 WITH KEY bname = <ls_user_addr>-bname ASSIGNING FIELD-SYMBOL(<ls_usr21>).
IF sy-subrc = 0.
READ TABLE lt_adr6 WITH KEY persnumber = <ls_usr21>-persnumber ASSIGNING FIELD-SYMBOL(<ls_adr6>).
ENDIF.
ENDIF.
ENDIF.
APPEND VALUE #( uname = <ls_cdhdr>-username
udate = <ls_cdhdr>-udate
utime = <ls_cdhdr>-utime
tcode = <ls_cdhdr>-tcode
Objvale = <ls_cdhdr>-objectid
tabname = <ls_cdpos>-tabname
fname = <ls_cdpos>-fname
valueold = <ls_cdpos>-value_old
valuenew = <ls_cdpos>-value_new
fstname = <ls_user_addr>-name_first
lstname = <ls_user_addr>-name_last
email = <ls_adr6>-smtp_addr ) TO rt_output.
ENDLOOP.

4 REPLIES 4

Ryan-Crosby
Active Contributor
496

Make sure you are using sorted/hashed tables with appropriate keys or BINARY SEARCH.

DominikTylczyn
Active Contributor
442

Hello @AadivaramAbbulu 

You really should have shared the entire code especially the declarations of the internal tables and have the source code correctly formatted. Without internal tables declarations it's all but impossible to tell how READs are executed.

As the first try add BINARY SEARCH to READs as @Ryan-Crosby advised.

Best regards

Dominik Tylczynski

raymond_giuseppi
Active Contributor
398
  • As already written, use a sorted or hashed table.
  • Check your exact requirements. Wouldn't you need to loop at cdpos, in which case use cdpos in the outer loop?

priya527
Explorer
0 Kudos
280

Hi @AadivaramAbbulu ,  I suggest write a CDS for the tables and fields required -  CDHDR , CDPOS , USR21 , ADR6 . use appropriate joins to fetch all fields required and then use it in your report. It will improve the performance of the report rather than using loops and read statement and appending.