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 Loop back to previous record

Former Member
0 Likes
3,253

Hello Experts,

I need your help.

I am looping at an internal table. I have to check for a condition. If this condition is true, I need to check for another condition on the previous record.

This is the IT content:

SINCHFCiVision Heffen

Z200720000126800P0000005544041229320005217381935Eversdijk M. M.

K200720000126800

D200720000126800 01/0001 00002007

!

!

!

I need to check for first letter of each line ie., S, Z, K and D in this case. Based on the letter, I need to check some condition on previous record.

Currently I am using LOOP AT. Within this loop, how can we go back to the previous record?

Thank you,

Warm regards,

Deepak

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,700

Hello


data: pointer type i.
loop at itab.
  pointer = sy-tabix - 1.
  if itab-field = 'S' or itab-field = 'Z' or itab-field = 'K' or itab-field = 'D'.
    read table itab index pointer.
    if sy-subrc = 0.
      ..... do anything here .....
    endif.
  endif.
endloop.

Hello Experts,

I need your help.

I am looping at an internal table. I have to check for a condition. If this condition is true, I need to check for another condition on the previous record.

This is the IT content:

SINCHFCiVision Heffen

Z200720000126800P0000005544041229320005217381935Eversdijk M. M.

K200720000126800

D200720000126800 01/0001 00002007

!

!

!

I need to check for first letter of each line ie., S, Z, K and D in this case. Based on the letter, I need to check some condition on previous record.

Currently I am using LOOP AT. Within this loop, how can we go back to the previous record?

Thank you,

Warm regards,

Deepak

5 REPLIES 5
Read only

former_member156446
Active Contributor
0 Likes
1,700

hi you can use the sy-tabix.

loop at itab into wa_itab.

if condition = true.
  vl_previous = sy-tabix - 1.
  read table itab index vl_previous.
   if sy-subrc eq 0.
    ur code...
  endif.

else...

 some other code..


endloop.

Read only

Former Member
0 Likes
1,701

Hello


data: pointer type i.
loop at itab.
  pointer = sy-tabix - 1.
  if itab-field = 'S' or itab-field = 'Z' or itab-field = 'K' or itab-field = 'D'.
    read table itab index pointer.
    if sy-subrc = 0.
      ..... do anything here .....
    endif.
  endif.
endloop.

Read only

0 Likes
1,700

Thank you so much everybody.

Points rewarded!!!

Cheers,

Deepak

Read only

Sidh_M
Participant
0 Likes
1,700

hi,

Try using two internal table containing same records.

call that 2nd internal table within loop of 1st internal table.

Loop at itab1.

if ( your condition ).

loop at itab2.

endloop.

endif.

endloop.

Best Regards,

SUDHIR MANJAREKAR

Read only

Former Member
0 Likes
1,700

Before ENDLOOP. move your current work area to temparory workarea. So when you are on the second record. you will get the reference of first record from temp. Work area.

You can overwrite this temp. workarea once your conditions are satisfied or everytime.

Loop at Itab

Your logical conditions to

..

.

.

.

..

move itab to temp_itab.

endloop