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

Decrease sy-tabix value in Loop

Former Member
0 Likes
2,238

Hi Experts,

I need to know that is it possible that we can decrease or change value of SY-TABIX.

EXAMPLE:

I am using a;

loop at itab. --> at this stage sy-tabix is 1.

for instance current value of sy-tabix is changed to 4 and now I want to make it 3.

in this case I want to read the 3 value in loop again.

So is it possible that I can change my SY-TABIX value from 4 to 3 and read that 3rd record in the loop?

endloop.

can anyone let me know.

thanks in advance.

Regards,

Yahya

6 REPLIES 6
Read only

Former Member
0 Likes
1,227

Hi

this is not possible directly to change the values of system variables

but the other way is there

what you can do is to move the valuw of sy-tabix in a variable and then loop through the table to that value,

like:

lv_tabix like sy-tabix.

loop at itab into wa where sy-tabix = lv_tabix.

after loop statement.

lv-tabix = sy-tabix.

you code............

before enloop .

lv_tabix = sy-tabix - 1.

endloop.

I am not sure about the above code but you can try something like above.

Thanks

Lalit

Read only

0 Likes
1,227

I HAVE ALREADY TRIED THIS BUT PROBLEM STILL PERSISTS..

THANKS,

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,227

Hello Yahya,

You can try it this way though:

DATA: LV_TABIX TYPE SY-TABIX.

LOOP AT ITAB INTO WA.

* Perform your calculations on LV_TABIX as per your logic & set the value of LV_TABIX
  READ TABLE ITAB INTO WA_TEMP INDEX  LV_TABIX.
  IF SY-SUBRC = 0.
* Write your logic here
  ENDIF.

ENDLOOP.

BR,

Suhas

Read only

Former Member
0 Likes
1,227

Thanks everyone.

I came up with this solution.

 loop at it_ship3

index = index - 1.
      sy-tabix = index.

      read table it_ship3 INDEX index into wa_ship.
      append wa_ship to it_ship4.
endloop.

I have taken that current index value and read data from the table directly with respect to that index.

Regards,

Yahya

Read only

Former Member
0 Likes
1,227

Hi Yahya,

There is no need of

"sy-tabix = index."

It can be removed.

Thanks,

Preyansh

Read only

Former Member
0 Likes
1,227

Dear Preyansh,

I'm using that sy-tabix in other scenario that is not displayed in above code. And that's the only reason for using

"sy-tabix = index."

Still appreciate your input.

Regards,

Yahya