‎2006 Aug 01 3:54 AM
hai,
Suppose itab is having 10 records, Write what will be the output of
Loop at itab.
if sy-tabix between 1 and 5.
write: /sy-index.
else if : sy-index between 6 and 10.
write: /sy-tabix.
Endif.
Endloop.
regards,
aravind.
‎2006 Aug 01 3:56 AM
Isn't it going to write simply 1 to 10.
Regards,
Ravi
Note :Please mark all the helpful answers
‎2006 Aug 01 4:07 AM
two different fields are being tested here. SY-TABIX holds the current iteration value within table itab. SY-INDEX could be anything depending on the preceding code, it is typically set by 'do' code rather than 'loop at tables'. Whatever it holds it will be constant in this loop.
SO, for the first 5 iterations SY-INDEX will be written, probaly this will hold '0' so there will be 5 0's listed.
For the next 5 iterations ONLY if SY-INDEX has a value between 6 and 10 will the SY-TABIX be written. So if sy-index is between 6 and 10 you'll see the TABIX written (which will also be 6 thru 10) but if sy-index does not hold 6 thru 10 NOTHING will appear.
ps, 'else if :' needs to be coded as 'elseif' or you'll get a syntax error.
‎2006 Aug 01 5:01 AM
Hi Aravind,
The result would be every number between 1 and 10.
SY-TABIX is a system variable that stores the current position in the internal table.
Although there is difference between SY-TABIX and SY-INDEX, they are the same in this case.
- Priyanka Shukla
Please reward appropriate points.
‎2006 Aug 01 5:15 AM
hi
As said by Neil this code will write only five 0s. For getting the correct value of sy-index you have to use this variable in do-enddo.
If you use the code within 'do - enddo' using
<i>read table itab index sy-index</i> and remaining as your code then you will get numbers 1 to 10 printed in a new line. also the write statement should be like <i>write : / sy-index</i>. there should be one space between '/' and 'sy-index'
regards
anoop
‎2006 Aug 01 5:18 AM
Hi Aravind,
The output of the code will be only 5 Zeroes that would be based on the sy-tabix variable.
sy-Index doesnot vary unless we explicitly increment or decrement the variable.
Hope it clarifies your doubt.
Best Regards,
Ram.
‎2006 Aug 01 5:55 AM
hi aravind,
here sy-index would not come into picture since sy-index is for only looping statements like do...endo, while...endwhile,
whereas sy-tabix is used only for loop...endloop.
reward if worthful.
cheers,
Aditya.
‎2006 Aug 01 6:32 AM
Hi Arvind
It will print just 5 0's at each line. Here value of sy-index will be 0 always because it is not inside any loop like do,while etc etc. But it is the internal table loop. So system field <b>SY-INDEX</b> value will remain 0 for the whole looping.
‎2006 Aug 01 7:42 AM
Hi,
1)SY-INDEX has no effect in <b>LOOP....ENDLOOP</b>, only the SY-TABIX will hold the index of the record that is in the loop pass. So you the output will be all zeroes.
2)The reverse for <b>DO....ENDDO</b> only SY-INDEX will hold the current pass.
<b>Execute the Program to know the difference.</b>
REPORT zztest.
DATA : itab TYPE STANDARD TABLE OF mara WITH HEADER LINE.
START-OF-SELECTION.
SELECT * FROM mara INTO TABLE itab UP TO 100 ROWS.
*---No effect on SY-INDEX
WRITE : / 'SY-INDEX in LOOP...ENDLOOP'.
LOOP AT itab.
IF sy-tabix BETWEEN 1 AND 5.
WRITE: / 'SY-INDEX', sy-index.
ELSEIF sy-index BETWEEN 6 AND 10.
WRITE: / 'SY-TABIX', sy-tabix.
ENDIF.
ENDLOOP.
*---No effect on SY-TABIX
SKIP 1.
WRITE : / 'SY-TABIX in DO...ENDO'.
DO 10 TIMES.
WRITE: / 'SY-INDEX', sy-index,
'SY-TABIX', sy-tabix.
ENDDO.
*---An Exception
SKIP 1.
WRITE : / 'An Exception'.
DO 10 TIMES.
LOOP AT itab.
IF sy-tabix BETWEEN 1 AND 5.
WRITE: / 'SY-INDEX', sy-index,
'SY-TABIX', sy-tabix.
ENDIF.
ENDLOOP.
ENDDO.
<b>This is the Output</b>
<b>SY-INDEX in LOOP...ENDLOOP</b>
SY-INDEX 0
SY-INDEX 0
SY-INDEX 0
SY-INDEX 0
SY-INDEX 0
<b>SY-TABIX in DO...ENDO</b>
SY-INDEX 1 SY-TABIX 1
SY-INDEX 2 SY-TABIX 1
SY-INDEX 3 SY-TABIX 1
SY-INDEX 4 SY-TABIX 1
SY-INDEX 5 SY-TABIX 1
SY-INDEX 6 SY-TABIX 1
SY-INDEX 7 SY-TABIX 1
SY-INDEX 8 SY-TABIX 1
SY-INDEX 9 SY-TABIX 1
SY-INDEX 10 SY-TABIX 1
<b>An Exception</b>
SY-INDEX 1 SY-TABIX 1
SY-INDEX 1 SY-TABIX 2
SY-INDEX 1 SY-TABIX 3
SY-INDEX 1 SY-TABIX 4
SY-INDEX 1 SY-TABIX 5
SY-INDEX 2 SY-TABIX 1
SY-INDEX 2 SY-TABIX 2
SY-INDEX 2 SY-TABIX 3
SY-INDEX 2 SY-TABIX 4
SY-INDEX 2 SY-TABIX 5
SY-INDEX 3 SY-TABIX 1
SY-INDEX 3 SY-TABIX 2
SY-INDEX 3 SY-TABIX 3
SY-INDEX 3 SY-TABIX 4
SY-INDEX 3 SY-TABIX 5
SY-INDEX 4 SY-TABIX 1
SY-INDEX 4 SY-TABIX 2
SY-INDEX 4 SY-TABIX 3
SY-INDEX 4 SY-TABIX 4
SY-INDEX 4 SY-TABIX 5
SY-INDEX 5 SY-TABIX 1
SY-INDEX 5 SY-TABIX 2
SY-INDEX 5 SY-TABIX 3
SY-INDEX 5 SY-TABIX 4
SY-INDEX 5 SY-TABIX 5
SY-INDEX 6 SY-TABIX 1
SY-INDEX 6 SY-TABIX 2
SY-INDEX 6 SY-TABIX 3
SY-INDEX 6 SY-TABIX 4
SY-INDEX 6 SY-TABIX 5
SY-INDEX 7 SY-TABIX 1
SY-INDEX 7 SY-TABIX 2
SY-INDEX 7 SY-TABIX 3
SY-INDEX 7 SY-TABIX 4
SY-INDEX 7 SY-TABIX 5
SY-INDEX 8 SY-TABIX 1
SY-INDEX 8 SY-TABIX 2
SY-INDEX 8 SY-TABIX 3
SY-INDEX 8 SY-TABIX 4
SY-INDEX 8 SY-TABIX 5
SY-INDEX 9 SY-TABIX 1
SY-INDEX 9 SY-TABIX 2
SY-INDEX 9 SY-TABIX 3
SY-INDEX 9 SY-TABIX 4
SY-INDEX 9 SY-TABIX 5
SY-INDEX 10 SY-TABIX 1
SY-INDEX 10 SY-TABIX 2
SY-INDEX 10 SY-TABIX 3
SY-INDEX 10 SY-TABIX 4
SY-INDEX 10 SY-TABIX 5
Regards,
AS