‎2007 Oct 29 11:19 AM
Hi,
I have internal table with 5 records. I want to separate out the last record in the internal table.
For ex : itab contains,
12,
10,
15,
09,
13 . i need the last record '13' only. how to fetch the last record from the internal table, i no need the other records.
point will be sure.
Gowri
‎2007 Oct 29 11:22 AM
DESCRIBE ITAB LINES w_lines.
READ TABLE ITAB index w_lines.
It will give you the last record of internal table ITAB.
‎2007 Oct 29 11:23 AM
‎2007 Oct 29 11:23 AM
Hi Gowri,
once the full data is in itab.
describe table itab lines gv_lines.
read table itab into wa index gv_lines.
if sy-subrc = 0.
delete itab.
endif.
append wa to itab.<b>Reward points for helpful answers</b>.
Satish
‎2007 Oct 29 11:24 AM
Hi,
Use describe statement to count the records from internal table, store that value into one variable and read the data from internal table using index.
Give index as a variable.
Regards,
Prashant
‎2007 Oct 29 11:29 AM
hi gowri,
when u use the describe statement the index is at the last line of the internal table.
describe table itab lines l.
read table itab into wa index l.
append wa to itab.
now the itab will have only 1 row that is the last row of the contents it previously had...
hope this will help you.
regards,
sohi
‎2007 Oct 29 11:51 AM
hi gowri
do it:
read table itab.
read table itab index SY-TFILL.
Regards
Allan Cristian
‎2007 Oct 29 11:59 AM
Hi Gowri,
for your query use the following code:
data: count type i value 0.
Describe itab lines n.
Do.
if ( count < n ).
delete itab index count.
else.
exit.
endif.
endo.
Reward if useful.
Regards,
Shilpi
‎2007 Oct 29 12:07 PM
Hi,
try this simle code:
DATA: BEGIN OF ITAB OCCURS 0,
N2(2) TYPE N,
END OF ITAB.
*
DATA: LINE_ITAB LIKE SY-TABIX.
*
START-OF-SELECTION.
*
ITAB-N2 = '12'. APPEND ITAB.
ITAB-N2 = '10'. APPEND ITAB.
ITAB-N2 = '15'. APPEND ITAB.
ITAB-N2 = '09'. APPEND ITAB.
ITAB-N2 = '13'. APPEND ITAB.
*
CLEAR: ITAB.
DESCRIBE TABLE ITAB LINES LINE_ITAB.
*
READ TABLE ITAB INDEX LINE_ITAB.
*
WRITE: / ITAB-N2.
*
Regards, Dieter
‎2007 Oct 29 12:11 PM
<b>data v_lin type i.
describe table itab lines v_lin.
read table itab index v_lin.
loop at itab.
if not sy-tabix eq v_lin.
DELETE ITAB INDEX SY-TABIX.
endif.
endloop.</b>
‎2007 Oct 29 12:20 PM
Hi,
Create another table like that you are using -> itab2.
sort itab1 descending by field.
read table itab1 index 1 into wa.
append wa into itab2.
You will sort the table descending, then the first record was the last. Just read the table and append to the other table. Then you will have only the last record from the first table.
Regards.