‎2009 Jul 15 7:44 PM
I have an internal table that I loop through using a WHERE statement. I want to be able to tell if its the last run through the loop. If it is, I want to do some additional code. Currently, I loop through it one time to count the number of times, then I loop again for main functionality. Is there a better way to do this?
Here is what I currently do:
mycount = 0.
LOOP AT mytable INTO mywa WHERE kunnr = currentkunnr.
mycount = mycount + 1.
ENDLOOP.
LOOP AT mytable INTO mywa WHERE kunnr = currentkunnr.
IF sy-tabix = mycount.
<CODE>
ENDIF.
<CODE>
ENDLOOP.Thanks,
Curtis
‎2009 Jul 15 7:49 PM
try using At Last.
Loop.
code....
At Last.
Code exclusively tobe done at last one
endat
Endloop.
‎2009 Jul 15 9:00 PM
The AT LAST statement will not work when I have a condition on there loop. Are there any other suggestions?
‎2009 Jul 16 3:10 AM
Hi Davis,
Try this way.
Thanks
Venkat.O
REPORT ztest_notepad.
DATA: BEGIN OF it_nfal OCCURS 0,
einri TYPE nfal-einri,
falnr TYPE nfal-falnr,
falar TYPE nfal-falar,
patnr TYPE nfal-patnr,
END OF it_nfal.
START-OF-SELECTION.
SELECT *
FROM nfal
INTO CORRESPONDING FIELDS OF TABLE it_nfal
UP TO 10000 ROWS.
"Sort internal table by key field which is used in Where condition.
SORT it_nfal BY einri.
LOOP AT it_nfal WHERE einri = 'CGH'.
"It is triggered when it reaches last value.
AT END OF einri.
WRITE 'Test this'.
ENDAT.
ENDLOOP.
‎2009 Jul 15 9:04 PM
Hi ,
Loop at itab.
-
-
at last.
-
-
endat.
endloop.
at last is the event which is exclusively used for the last record.
Hope this will help you.
Thanks,
Rajesh.
‎2009 Jul 16 12:15 AM
You could find out the number of lines in the table first.
DATA: I_TABLE LIKE ZTABLE OCCURS 0 WITH HEADER LINE,
V_LINES TYPE I.
DESCRIBE TABLE I_TABLE LINES V_LINES.
LOOP AT I_TABLE WHERE VALUE = CONDITION.
IF SY-TABIX = V_LINES.
ADDITIONAL CODE HERE
ENDIF.
ENDLOOP.
‎2009 Jul 16 4:16 AM
Try AT END <Field>
This will compare the value of your current record with your next record in the itab. Then, if the next record value in that field is different, this AT END will trigger. Insert your coding here.
Hope this is what you are looking for.
Thanks
Kiran
‎2009 Jul 16 4:23 AM
Hi, Davis
Please use Meaningful Subject Line for next time, Please
Regards,
Faisal