‎2006 Mar 13 4:29 AM
Hi experts,
Is there any way to get last record from any db table?
Thanks
kaki
‎2006 Mar 13 4:33 AM
Hi,
report adtest.
data: index type i.
data : begin of itab occurs 0.
include structure zdbtable.
data: end of itab.
select * from zdbtable into table itab .
Describe table itab lines index.
read table itab index index.
write index.Regards,
Anjali
‎2006 Mar 13 4:33 AM
Hi,
report adtest.
data: index type i.
data : begin of itab occurs 0.
include structure zdbtable.
data: end of itab.
select * from zdbtable into table itab .
Describe table itab lines index.
read table itab index index.
write index.Regards,
Anjali
‎2006 Mar 13 4:40 AM
Hello Kaki,
As such there is no way you can get the number of records in a db table without querying it.
So, in your case, first get all the records from database into an internal table. Then using the DESCRIBE keyword find the number of records in that internal table. Then read that internal table using that total number of records as index.
Hope this would be useful.
Regards
Priya
‎2006 Mar 13 4:41 AM
hi
U can be used MAX in the select query. i.e. Suppose Material or Sales order u want select then u can use
SELECT MAX (VBELN) .........
Hope this will be useful.
regards
vinod
‎2006 Mar 13 4:45 AM
HI
YOU CAN USE THE CODE
<b>DESCRIBE TABLE ITAB LINES SY-TFILL.
READ TABLE ITAB INDEX SY-TFILL.</b>
TO GET THE LAST RECORD INSERTED TO A TABLE
IF USEFUL PLEASE REWARD POINTS
REGARDS
ANOOP
‎2006 Mar 13 5:02 AM
hi,
first declare a variable of type i. say count.
data : count type i.
next, select all the rows from the database table into an internal table, so that we get the total number of rows in the table.
The total count corresponds to the last row in the table.
select * from tablename into table internaltablename.
Describe table internaltablename lines count.
read table internaltablename index count.
This will have the last row read from the internal table.
regards,
Smitha
‎2006 Mar 13 5:06 AM
Hi kaki,
1. Is there any way to get last record from any db table?
Last in what sense ?
2. Last added to the table ?
3. If so then,
if the fields are available in the table,
ie. (add date)
then still we can get.
4. Other wise, there is not technique
by which database can provide
the last record.
(the sequence of records returned in
sql by the database,
is never the same way, i mean,
no body can guarantee that it returns
the last record, at the last)
5. eg
suppose we want to get the lastest record from
ekko table,
then based upon the field AEDAT
we can write this logic
(just copy paste in new program)
REPORT abc.
*----
DATA : aedat LIKE ekko-aedat.
DATA : ekko LIKE TABLE OF ekko WITH HEADER LINE.
*----
First get MAX / LATEST date
SELECT SINGLE MAX( aedat ) FROM
ekko INTO aedat.
*----
Then get the record
SELECT * FROM ekko
INTO TABLE ekko
WHERE aedat = aedat.
BREAK-POINT.
*----
*
*PARAMETERS : a RADIOBUTTON GROUP g1 USER-COMMAND rad,
b RADIOBUTTON GROUP g1.
*
*PARAMETERS : t1(10) TYPE c DEFAULT 'Hello' MODIF ID p,
t2(10) TYPE c DEFAULT 'Abdul' MODIF ID q.
*
*
**----
*
*INITIALIZATION.
a = 'X'.
*
*
**----
*
*
*AT SELECTION-SCREEN OUTPUT.
LOOP AT SCREEN.
IF a = 'X'.
IF screen-group1 = 'Q'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
ENDIF.
ENDIF.
*
*
*
*
IF b = 'X'.
*
IF screen-group1 = 'P'.
screen-input = 0.
screen-invisible = 1.
MODIFY SCREEN.
ENDIF.
ENDIF.
*
*
*
ENDLOOP.
regards,
amit m.
‎2006 Mar 13 5:40 AM
‎2006 Mar 13 5:53 AM
select * into corresponding fields of table wa_zgkpf from zgkpf.
(populate data of table into wa)
read table wa_zgkpf index sy-dbcnt.
(read the last record of wa)
required field is wa_zgkpf-docno.
hope this will give u idea
‎2006 Mar 13 5:38 AM
‎2006 Mar 13 5:43 AM
hi,
what i have done here is that
i have read the data from the table
<b>marav </b>into an internal table <b>itab</b>.
after which i have read the last index
of the internal table and displayed.
try the following logic.
*----
data: begin of itab occurs 0,
matnr like marav-matnr,
end of itab.
data: i_lines like sy-tabix.
select matnr from marav into corresponding
fields of table itab.
clear i_lines.
describe table itab lines i_lines.
read table itab index i_lines.
write:/ itab-matnr.
*----
reward if found helpful...
cheers,
Aditya.
‎2006 Mar 14 12:46 PM
Hi,
you can try to use Select upto 1 row and use decending in select statment.
sample code:
data: wa_matnr like mara.
select * into wa_matnr
from mara up to 1 rows
order by matnr descending.
endselect.
- Niranjan