10-17-2008 9:43 AM
Hello,
It's 'Probie' again
How do you get the last record out of a table without knowing anything about the entry?
Thanks.
10-17-2008 9:45 AM
is it an interview question?
if it is an internal table, then determine the number of lines of the table (DESCRIBE ... ) and read the last line of the table : READ TABLE ... INDEX n (the number you just got). Of course it works only with STANDARD and SORTED tables, not for HASHED ones
10-17-2008 9:45 AM
is it an interview question?
if it is an internal table, then determine the number of lines of the table (DESCRIBE ... ) and read the last line of the table : READ TABLE ... INDEX n (the number you just got). Of course it works only with STANDARD and SORTED tables, not for HASHED ones
10-17-2008 10:04 AM
seems to be an interview question. It is hardly of any practical relevance.
Siegfried
10-17-2008 12:54 PM
Hi,
SELECT * from Databasetable into the Internal Table.
Use Describe Statement to know the Number of Entries in the Internal Table.
Read the Internal Table with Index = Total no of Entires in the Table....
10-17-2008 12:56 PM
Hi,
Use DESCRIBE statement to know the number of lines in that Internal Table,
Then Use
IF sy-tabix = 'a'.
Logic.
ENDIF.
Ex:-
DATA : a TYPE i.
DESCRIBE TABLE itab LINES a.
LOOP at itab.
IF sy-tabix = 'a'.
Logic.
ENDIF.
ENDLOOP.
Where a is the variable which has the total number of records value from DESCRIBE statement.
Regards
Bala Krishna
10-17-2008 1:18 PM
I solved it like this:
DATA: P0000 like p0000 OCCURS 0 with header line.
SELECT *
FROM PA0000
INTO corresponding fields of table p0000.
DESCRIBE TABLE p0000 LINES NUMBER.
READ TABLE p0000 INDEX NUMBER.
PERNR = p0000-pernr.
Thanks for all your help.
10-17-2008 1:25 PM
I wonder what you want here... The last record after a DB selection in this case is more or less random.
If you need the highest personal number, than you can :
SELECT MAX( pernr ) ...
(probably the highest number was created last time, but it also depends on the number ranges)
10-17-2008 1:24 PM
as I said, this question is absolutely useless.
If the data come from a database table, and no order or sort is used, then the end in the table in no defined order.
Any line could be the solution!
So fastest solution performance-wise is a select * dbtab (no WHERE condition)!
Siegfried
02-16-2009 8:31 AM
Hi,
The Simplest and shortest way is to read the values into an Internal table.
then Simply do.
Immediatly after the query you can write.
*Read ITAB index sy-dbcnt*
I found it to be simplest and shortest method.
regards
Vishal