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 tuning

0 Likes
727


Hi Experts

Please help me out to optimize the below loop.

I am aware of parallel cursor, but don't know how exactly to fit in this scenario.

LOOP AT itab1 INTO watab1.

  LOOP AT itab2 TRANSPORTING NO FIELDS
    WHERE     objnr EQ watab1-object_id
      AND (   stat = '01'
           OR stat = '02'
           OR stat = '03'
           OR stat = '04' )

<<Actual  logic >>

  ENDLOOP.

ENDLOOP.

Thank you in advance for reply.

Point will be awarded.

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
699


Hi Mudit,

try below logic.

data : l_index type SYTABIX.

Sort itab1 by object_id.

sort itab2 by objnr.

LOOP AT itab1 INTO watab1.

Read table itab2 where objnr =  watab1-objct_id .

if sy-subrc = 0.

l_index = sy-tabix.

  LOOP AT itab2 into watab2
  from l_index.

if watab2-objnr = watab1-object_id and

      AND (   stat = '01'
           OR stat = '02'
           OR stat = '03'
           OR stat = '04' ).

<<Actual  logic >>

else.

exit.

endif.

  ENDLOOP.

endif.

ENDLOOP.

Hope this helps

Regards,

Shanmukh

3 REPLIES 3
Read only

Former Member
0 Likes
699

Hi Mudit,

Please check the below code.

SORT I_CDHDR BY OBJECTCLAS OBJECTID CHANGENR.

SORT I_CDPOS BY OBJECTCLAS OBJECTID CHANGENR.


DATA : LV_IDX TYPE SY-TABIX.

LOOP AT I_CDPOS INTO WA_CDPOS.

       MOVE-CORRESPONDING WA_CDPOS TO WA_OUT.

       READ TABLE I_CDHDR INTO WA_CDHDR

                          WITH KEY OBJECTCLAS = WA_CDPOS-OBJECTCLAS

                                                 OBJECTID = WA_CDPOS-OBJECTID

                                              CHANGENR = WA_CDPOS-CHANGENR BINARY SEARCH.

       IF SY-SUBRC EQ 0.

         LV_IDX = SY-TABIX.

         LOOP AT I_CDHDR INTO WA_CDHDR FROM LV_IDX .

           IF WA_CDHDR-OBJECTCLAS = WA_CDPOS-OBJECTCLAS AND

                    WA_CDHDR-OBJECTID = WA_CDPOS-OBJECTID AND

                 WA_CDHDR-CHANGENR = WA_CDPOS-CHANGENR  .

             MOVE-CORRESPONDING WA_CDHDR TO WA_OUT.

             APPEND WA_OUT TO I_OUT.

             CLEAR WA_OUT.

           ELSE.

             CLEAR WA_OUT.

             EXIT.

           ENDIF.

         ENDLOOP.

       ELSE.

         CONTINUE.

       ENDIF.

     ENDLOOP.


Regards,

Jitendra

Read only

Former Member
0 Likes
700


Hi Mudit,

try below logic.

data : l_index type SYTABIX.

Sort itab1 by object_id.

sort itab2 by objnr.

LOOP AT itab1 INTO watab1.

Read table itab2 where objnr =  watab1-objct_id .

if sy-subrc = 0.

l_index = sy-tabix.

  LOOP AT itab2 into watab2
  from l_index.

if watab2-objnr = watab1-object_id and

      AND (   stat = '01'
           OR stat = '02'
           OR stat = '03'
           OR stat = '04' ).

<<Actual  logic >>

else.

exit.

endif.

  ENDLOOP.

endif.

ENDLOOP.

Hope this helps

Regards,

Shanmukh

Read only

Former Member
0 Likes
699

Where are you facing confusion ?

You can use the normal Parallel Cursor , the only thing is that you have got some Constants to be used in WHERE condition of READ Statement and Inner Loop's conditions also


AND (   stat = '01'

           OR stat = '02'

           OR stat = '03'

           OR stat = '04' )

.

I would also like to highlight one more thing , in many discussions I have noticed that few Experienced ABAP Programmers objecting the use of Parallel Cursors. Saying that Parallel cursor technique is not necessary in newer releases as things are internally optimized you just need to link both the loops with proper and maximum number of keys.

But personally I find Parallel cursors are very efficient especially for avoiding "The Unwanted Inner loop iterations" .