2006 Oct 17 9:31 PM
Hi,
I have a problem in resetting the index of internal table.
my table has five records.
once i reach third record i am checking for a condition , if that condition is successful i am executing a code.
once i am done with the execution i want to loop the internal table again from third record.
even if the change the sy-tabix to 3 , my internal table loop is reading fourth record .
can you let me know how to resolve this .
Regards,
Roby
2006 Oct 17 9:35 PM
2006 Oct 17 9:49 PM
2006 Oct 17 9:51 PM
Hi Roby,
you can use the above logic that mentioned.
That is...
LOOP AT ITAB FROM 3.
ENDLOOP.
Thanks,
Ramakrishna
2006 Oct 17 9:55 PM
You might get into trouble with an infinite loop here (it'll always be the third record). You could:
loop at itab.
if sy-tabix = 3.
* process.
exit.
endloop.
loop at itab from 3.
* do the other processing.
endloop.
Rob
2006 Oct 17 9:43 PM
Hi Roby,
if you set SY-TABIX inside the loop, it will not work in the next loop iteration.
If you want to read from the third record again, you can write logi like below...
LOOP AT ITAB FROM 3.
ENDLOOP.
Thanks,
Ramakrishna
2006 Oct 17 10:34 PM
Hi Roby,
Another solution would look like this:
* Local
TYPES:
BEGIN OF local_record_type,
field1 TYPE syindex,
field2 TYPE syindex,
END OF local_record_type.
DATA:
number_of_records TYPE i,
local_workarea TYPE local_record_type,
local_table TYPE STANDARD TABLE OF local_record_type.
* Test fill (demo purposes)
DO 10 TIMES.
local_workarea-field1 = sy-index.
local_workarea-field2 = ( 10 - sy-index ).
APPEND local_workarea TO local_table.
ENDDO.
* Your proces starts here
DESCRIBE TABLE local_table LINES number_of_records.
* Controlled process
DO number_of_records TIMES.
CHECK:
sy-index GE 2.
IF sy-index EQ 3.
READ TABLE local_table INDEX sy-index INTO local_workarea.
* Your action
* ...
ENDIF.
* After sy-index reaches 3 and the proces has taken place
* sy-index becomes 4 and you can READ the next record as above
* and do your stuff with it.
* ...
ENDDO.
Regards,
Rob.