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

Sy-tabix in loop : Doubt

kesavadas_thekkillath
Active Contributor
0 Likes
1,093

LOOP AT i_lfa1 INTO wa_lfa1 WHERE werks = space.

wf_tabix = sy-tabix.

APPEND wa_lfa1 TO i_lfa1_werks.

DELETE i_lfa1 index wf_tabix.

ENDLOOP.

in the above code the sy-tabix is always 2.

what i want to know is if there is a where clause , should we not use the sy-tabix for deletion.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
872

Hi ,


LOOP AT i_lfa1 INTO wa_lfa1 WHERE werks = space. 
wf_tabix = sy-tabix. 
APPEND wa_lfa1 TO i_lfa1_werks. 
DELETE i_lfa1 .
CONTINUE " Try This ??
ENDLOOP. 

maybe solved ..

Edited by: Serkan Taskan on Jan 28, 2010 3:04 PM

LOOP AT i_lfa1 INTO wa_lfa1 WHERE werks = space.

wf_tabix = sy-tabix.

APPEND wa_lfa1 TO i_lfa1_werks.

DELETE i_lfa1 index wf_tabix.

ENDLOOP.

in the above code the sy-tabix is always 2.

what i want to know is if there is a where clause , should we not use the sy-tabix for deletion.

5 REPLIES 5
Read only

Former Member
0 Likes
873

Hi ,


LOOP AT i_lfa1 INTO wa_lfa1 WHERE werks = space. 
wf_tabix = sy-tabix. 
APPEND wa_lfa1 TO i_lfa1_werks. 
DELETE i_lfa1 .
CONTINUE " Try This ??
ENDLOOP. 

maybe solved ..

Edited by: Serkan Taskan on Jan 28, 2010 3:04 PM

Read only

0 Likes
872

Continue is of no use here.

May just providing the delete without index would help.

But what i want to know is why wf_tabix is always 2.

May be ill get something from sap help.

Read only

0 Likes
872

Hello

From SAP Help


In the case of delete operations after the current table entry (performed with DELETE), the deleted lines are not processed in subsequent loop passes. 

If, for example, you are in the 47th loop pass and delete line 48, the next (i.e. 48th) loop pass will process the old line 49 (i.e. the line following the deleted line) as the new line 48. 
In the next loop pass, SY-TABIX is set accordingly to 48. 

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
872

>

> May be ill get something from sap help.

Hello Keshav,

As a matter of fact , I always do

SAP says:

If you delete the current line or lines in front of the current line, the internal loop counter is decreased by one with each deleted line. In the case of loops on index tables or if using a sorted key, this affects sy-tabix in the subsequent loop pass, and sy-tabix is decreased accordingly

@Dzed: Hail SAP Help !!! Anyways this was common sense & i dont think SAP processor is dumb

Cheers,

Suhas

Edited by: Suhas Saha on Jan 28, 2010 6:46 PM

Read only

Former Member
0 Likes
872

Hi Kesav,

sy-tabix is a system variable by which you will get the the current index of itab in a loop.

In your code it is holding the index where werks has space in the table i_lfa1, which is 2 initially.

Check the index of i_lfa1 where werks is initial after the delete statement.

Thanks,

Suchi.