Application Development 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: 

Sy-tabix

Former Member
0 Kudos

At the end of first loop sy-tabix carries value 3.

why its not get cleared when second loop starts.

In the second loop value starts from 3+

  • Monday

CLEAR: WA_BPSTAB, WA_BPSTAB2 .

LOOP AT GT_FINAL ASSIGNING <GT_FINAL>

WHERE DAY = '1'.

<b> MOVE SY-TABIX TO LV_INDEX_MON.</b>

clear sy-tabix.

  • MOVE <GT_FINAL>-MATNR TO WA_BPSTAB-MONDAY.

WRITE <GT_FINAL>-MATNR TO WA_BPSTAB-MONDAY.

MOVE <GT_FINAL>-QUANTITY TO WA_BPSTAB2-MONDAY.

APPEND WA_BPSTAB TO GT_BPSTAB.

APPEND WA_BPSTAB2 TO GT_BPSTAB.

LS_SUM_MON = LS_SUM_MON + <GT_FINAL>-QUANTITY.

ENDLOOP.

*WRITE <GT_FINAL>-QUANTITY RIGHT-JUSTIFIED TO LV_DUMMY.

*Tuesday

LV_COUNTER = 13 .

LOOP AT GT_FINAL ASSIGNING <GT_FINAL>

WHERE DAY = '2'.

<b>MOVE SY-TABIX TO LV_INDEX_TUE.</b>

READ TABLE GT_BPSTAB ASSIGNING <GT_BPSTAB>

INDEX LV_COUNTER.

IF SY-SUBRC = 0 .

WRITE <GT_FINAL>-MATNR TO <GT_BPSTAB>-TUESDAY.

ADD 1 TO LV_COUNTER .

READ TABLE GT_BPSTAB ASSIGNING <GT_BPSTAB>

INDEX LV_COUNTER.

IF SY-SUBRC = 0 .

MOVE <GT_FINAL>-QUANTITY TO <GT_BPSTAB>-TUESDAY.

ADD 1 TO LV_COUNTER .

ENDIF.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi John,

when you loop on some codition, sy-tabix gets filled with the no. of record in the loop which is satisfing the where condition.

you better to declare a variable and increment the variable in the loop and get into lv_index_mon.

-Anu

4 REPLIES 4

Former Member
0 Kudos

U need to clear the sy-tabix before processing the Loop.

CLEAR SY-TABIX.

LOOP AT GT_FINAL ASSIGNING <GT_FINAL>

WHERE DAY = '1'.

..........

..........

ENDLOOP.

CLEAR SY-TABIX.

LOOP AT GT_FINAL ASSIGNING <GT_FINAL>

WHERE DAY = '2'.

..........

..........

ENDLOOP.

This will work fine in ur case now...

Former Member
0 Kudos

Hi John,

when you loop on some codition, sy-tabix gets filled with the no. of record in the loop which is satisfing the where condition.

you better to declare a variable and increment the variable in the loop and get into lv_index_mon.

-Anu

Former Member
0 Kudos

I would advice you to try and CLEAR the contents of GT_FINAL and <GT_FINAL> before the second loop.

I think it should work...

Regards

Anurag

Former Member
0 Kudos

Hi,

If u r using nested loops ( ie, loops with in loops ) it is better to avoid the use of sy-tabix.Take some index say ind1 for first loop pass and index2 say ind2 for secondloop pass , increment ind1 value after the outer loop pass is completed , increment ind2 value after the inner loop pass is completed.