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

how to improve performance for following code?

Former Member
0 Likes
951

LOOP AT record.

    SELECT * FROM drad WHERE doknr = h_fco_doknr.

      SELECT * FROM viqmel INTO it_viqmel

                 WHERE qmnum EQ drad-objky

                   AND bequi EQ record-equnr.

        APPEND it_viqmel.

      ENDSELECT.

    ENDSELECT.

  ENDLOOP.

here viqmel is a view constructed on 4 tables. here it takes much time while executing the program.

Anyone can post, how to avoid this code.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
905

There is a better way arround, Have a look. No new structures introduced

SELECT * FROM drad into it_drad WHERE doknr = h_fco_doknr.

SELECT * FROM viqmel INTO it_viqmel

                for all entries in it_drad

                 WHERE qmnum EQ it_drad-objky.

loop at it_vigmel.

     read table record with key equnr eq it_vigmel-begui.

     if sy-subrc ne 0.

           DELETE TABLE it_vigmel.

     endif.

endloop

The total iteration of loops is reduced. expeced less number of times it will go inside if sy-subrc ne 0.

Do a runtime analysis see which is better.

There is a better way arround, Have a look. No new structures introduced

SELECT * FROM drad into it_drad WHERE doknr = h_fco_doknr.

SELECT * FROM viqmel INTO it_viqmel

                for all entries in it_drad

                 WHERE qmnum EQ it_drad-objky.

loop at it_vigmel.

     read table record with key equnr eq it_vigmel-begui.

     if sy-subrc ne 0.

           DELETE TABLE it_vigmel.

     endif.

endloop

The total iteration of loops is reduced. expeced less number of times it will go inside if sy-subrc ne 0.

Do a runtime analysis see which is better.

6 REPLIES 6
Read only

Former Member
0 Likes
905

Hi,

     I have also introduced another itab here it_vigmel_temp and a work area wa_it_vigmel.

     This will hit the database 2 times where as earlier it would have been hitting too many times.

     Its better to avoid writing selects inside select.

                   to avoid writing selects inside loop.

     Time for loop(count) is same.

SELECT * FROM drad into it_drad WHERE doknr = h_fco_doknr.

SELECT * FROM viqmel INTO it_viqmel_temp

                for all entries in it_drad

                 WHERE qmnum EQ it_drad-objky.

refresh it_vigmel.

loop at record.

     read table it_vigmel_temp into wa_vigmel with key begui eq record-equnr.

     if sy-subrc = 0.

          append wa_vigmel to it_vigmel.

     endif.

endloop.

Do a runtime analysis figure out what happens.

I hope this helps.

HAPPY ABAPing!!

Read only

Former Member
0 Likes
906

There is a better way arround, Have a look. No new structures introduced

SELECT * FROM drad into it_drad WHERE doknr = h_fco_doknr.

SELECT * FROM viqmel INTO it_viqmel

                for all entries in it_drad

                 WHERE qmnum EQ it_drad-objky.

loop at it_vigmel.

     read table record with key equnr eq it_vigmel-begui.

     if sy-subrc ne 0.

           DELETE TABLE it_vigmel.

     endif.

endloop

The total iteration of loops is reduced. expeced less number of times it will go inside if sy-subrc ne 0.

Do a runtime analysis see which is better.

Read only

ravi_lanjewar
Contributor
0 Likes
905

Hi, It can be improve further using the following tips

1) VIQMEL is database view on 3 table, if it is possible and your data is in single table then used single table for fetch the data instead of using the view.

2) Check the driver table should not be empty.

3) Used the fields symbol for processing the data instead of internal table with header line or work area.

4) Use the appropriate internal table type for data processing.

Read only

former_member491621
Contributor
0 Likes
905

You could get all the required values using FOR ALL ENTRIES IN and then use parallel cursor. That can improve performance.

Read only

Former Member
0 Likes
905

SELECT  * FROM drad into table it_drad WHERE doknr = h_fco_doknr.

SELECT * FROM viqmel INTO it_viqmel

FOR ALL ENTRIES IN it_drad

WHERE qmnum EQ drad-objky.

LOOP AT record.

     LOOP AT it_drad.

          LOOP AT it_viqmel WHERE bequi EQ record-equnr.

   

             clear: it_output.

             it_output = it_viqmel.

             APPEND it_output.

           ENDLOOP.

    ENDLOOP.

ENDLOOP.

Regards,

Vijay Pimputkar

Read only

0 Likes
905

SELECT  * FROM drad into table it_drad

              WHERE doknr = h_fco_doknr.

IF it_drad[] is not initial.

SELECT * FROM viqmel INTO it_viqmel

                      FOR ALL ENTRIES IN it_drad

                WHERE qmnum EQ drad-objky.

LOOP AT record.

read table it_viqmel with key bequi = record-equnr.

if sy-subrc ne  0.

delete  it_viqmel.

endif.

endloop.

endif.