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

access next element inside the loop

Former Member
0 Likes
2,876

Hello Friends,

I would like to know if its possible to access the next comming element inside the loop as we have in java, FOR loop ++ or +1 stuff.

Actually I have to create dynamic selection ( fields- name, sign, value, I have in an internal table) and inside the where clause I have to put 'AND' or 'OR' depending upon if field is same or change....if the field is same I have to use OR and if field changes I have to use AND.

Many thanks for your kind inputs,

Regards,

So I just have to see the next field inside the loop, if next is same, I will place OR at the end of previous statement, and if next comming field is different I have to place AND at the end of previous statement.

7 REPLIES 7
Read only

Former Member
0 Likes
1,410

loop at itab.

lv_tabix = sy-tabix + 1.

read table itab into wa index lv_tabix.

  • now the work area wa will have the next record.

endloop.

Regards,

Ravi

Read only

Former Member
0 Likes
1,410

Hi ,

Use this.


  DATA : l_index TYPE sy-tabix.

  LOOP AT t_marc INTO wa_marc.
    l_index = sy-tabix + 1.
    READ TABLE t_mara INTO wa_mara read table itab INDEX l_index.

"Some Processing

    CLEAR l_index. 
  ENDLOOP.



Regards,

Arun S.

Message was edited by: Arun Sambargi

Read only

Former Member
0 Likes
1,410

Hi,

Use sy-tabix+1 for internal table and

sy-index+1 for do loop.

loop at itab.

lv_index = sy-tabix.

lv_index = lv_index + 1.

read table itab index lv_index.

if sy-subrc eq 0.

endif.

endloop.

Regards

Amole

Read only

0 Likes
1,410

Hi All,

many thanks for your kind inputs, all replies were more or less same, so points will be awarded on first come first serve bases, but many thanks to all of you for your kind replies,

I will be get back if it works as i expected

till then...

One question: if table index + 1 (sy-tabix+1) does not exists, I will get DUMP ???

Message was edited by: Shah H

Read only

0 Likes
1,410

Hi

If index + 1 does not exist then it will return

SY_SUBRC <> 0

i.e

SY-SUBRC = 4

Sameena

Message was edited by: sameena attarwala

Read only

Former Member
0 Likes
1,410

hi Shah,

Declare a local variable that holds sy-tabix value.

data : lv_tabix type sy-tabix.

loop at itab.

*Increase the value by 1.

lv_tabix = sy-tabix + 1.

read table itab into wa index lv_tabix.

  • now the work area wa will have the next record.

**//here you can do your processing.

endloop.

Hope this will help you.

Regards,

Richa

Read only

Former Member
0 Likes
1,410

Hi Shah,

first get the value of sy-tabix in a local variable i.e.

l_index.

loop at t_itab.

l_index = sy-tabix.

l_index = l_index + 1.

read table t_itab index l_index.

endloop.

hope this works for u.

Seema