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

infinite loop

Former Member
0 Likes
1,643

Hello ABAPers

while debugging t_vbrk[ ]  contains 98 rows and t_vbrp contains 33 rows still this loop is going infinite.any idea?


*==============================================

loop at t_vbrk.
  if t_vbrk-fkart = 'ZRE'.
      loop at t_vbrp .
              if t_vbrk-vbeln eq t_vbrp-vbeln .

                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).
                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .

                    APPEND T_VBRP.
           endif.

      endloop.       "  LOOP AT T_VBRP.
    endif.

endloop.

*==============================================


thanks

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,309

Hi

As the guys have written above you're APPENDing a new record in T_VBRP, I suppone you want to change a value, so you should use MODIFY:


loop at t_vbrk.

  if t_vbrk-fkart = 'ZRE'.

      loop at t_vbrp .

              if t_vbrk-vbeln eq t_vbrp-vbeln .

                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).

                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .

                    APPEND T_VBRP.

                    MODIFY T_VBRP.

           endif.

      endloop.       "  LOOP AT T_VBRP.

    endif.

endloop.

For the performance, you should use WHERE condition instead of IF into the LOOP:


loop at t_vbrk WHERE FKART = 'ZRE'.

  if t_vbrk-fkart = 'ZRE'.

      loop at t_vbrp  WHERE VBELN = T_VBRK-VBELN.

              if t_vbrk-vbeln eq t_vbrp-vbeln .

                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).

                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .

                    APPEND T_VBRP.

                    MODIFY T_VBRP.

           endif.

      endloop.       "  LOOP AT T_VBRP.

    endif.

endloop.

Max

4 REPLIES 4
Read only

Former Member
0 Likes
1,309


Hi Faizur,

Add where condition  to loop it will reduce some iteration.

YOu can also append the records into some temp internanal table.If you want to modify the T_VBRP use modify statement.

The belwo code will resolve your issue.

*==============================================

loop at t_vbrk.
  if t_vbrk-fkart = 'ZRE'.
      loop at t_vbrp where vbeln = t_vbrp-vbeln .           
                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).
                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .
                MODIFY T_VBRP
INDEX SY-TABIX TRANSPORTING ntgew netwr.

       endloop.       "  LOOP AT T_VBRP.
    endif.

endloop.

*==============================================

Regards,

Pravin

Read only

former_member188724
Contributor
0 Likes
1,309

Hi,

I guess you are appending t_vbrp again inside t_vbrp Loop which can be the issue.

Rgeards,

K.S.

Read only

Former Member
0 Likes
1,309

Hi,

     AS KS pointed you are appending T_vbrp again and again which is causing loop to be end less, as each pass a new record is appended in same table.

Read only

Former Member
0 Likes
1,310

Hi

As the guys have written above you're APPENDing a new record in T_VBRP, I suppone you want to change a value, so you should use MODIFY:


loop at t_vbrk.

  if t_vbrk-fkart = 'ZRE'.

      loop at t_vbrp .

              if t_vbrk-vbeln eq t_vbrp-vbeln .

                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).

                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .

                    APPEND T_VBRP.

                    MODIFY T_VBRP.

           endif.

      endloop.       "  LOOP AT T_VBRP.

    endif.

endloop.

For the performance, you should use WHERE condition instead of IF into the LOOP:


loop at t_vbrk WHERE FKART = 'ZRE'.

  if t_vbrk-fkart = 'ZRE'.

      loop at t_vbrp  WHERE VBELN = T_VBRK-VBELN.

              if t_vbrk-vbeln eq t_vbrp-vbeln .

                     t_vbrp-ntgew =  t_vbrp-ntgew * ( -1 ).

                     t_vbrp-netwr =  t_vbrp-netwr * ( -1 ) .

                    APPEND T_VBRP.

                    MODIFY T_VBRP.

           endif.

      endloop.       "  LOOP AT T_VBRP.

    endif.

endloop.

Max