‎2009 Mar 19 9:07 AM
hello
I have 100 records in my databse table.i am fetching one record using select single query.i want to know at which position that record exist in database?how can i know that position?i am not using internal table here as so much data is there.
regards
soniya.
‎2009 Mar 19 9:41 AM
With relational database, there is no concept of "position" within a database table.
What are you wanting to achieve?
matt
‎2009 Mar 19 9:13 AM
GOTO se11 > DD03L > Give tabname (MARA) and fieldname (MATNR) > you will get its postion (2) in POSITION field.
Regards,
Sachin
‎2009 Mar 19 9:18 AM
hello
i dont want toknow the position of field.i just want to know a record position.
like,in database table i have field like below.and its having records like a,b,c.....
field1
a
b
c
d
e
i want to know that d record exist at which position.
regards
soniya
‎2009 Mar 19 9:43 AM
Soniya,
you can not predict where a perticular record will reside in databse. there are so many factors in consideratioon when data base records are saved.
there can not be a fixed sequence . it also might chnage on dependening the updates atking place on thet perticular table.
some time data base buffering will also come in picture . If your table is buffered, when you will call select and if the data present in buffere, it will not access db table at all.
So it is never a good practice to write a logic based on database index of records saved,
Always hit db with a Key fileds or some seocndary index fileds.
‎2009 Mar 19 9:16 AM
Hi soniya,
In that select single query, you need to pass the key field value in the where condition to get exactly a single record. If you are not going to use any internal table, make use of the structure of the table itself.
By using Tables declaration statement.
Thanks.
‎2009 Mar 19 9:17 AM
select *
from dbtab
into table itab.
if sy-subrc = 0.
position = sy-dbcnt.
endif.
endselect
Here in position, u will get record number in dbtable.
Edited by: Sachin Dandekar on Mar 19, 2009 2:47 PM
‎2009 Mar 19 9:23 AM
Hi Soniya,
If you are sure that only one record is going to fetch from database table.
Then use below code.
select *
from dbtab
into table itab.
if sy-subrc = 0.
position = sy-dbcnt.
endif.
endselect.
Regards,
Sachin
‎2009 Mar 19 9:55 AM
>
> Hi Soniya,
>
> If you are sure that only one record is going to fetch from database table.
> Then use below code.
>
>
> select * > from dbtab > into table itab. > if sy-subrc = 0. > position = sy-dbcnt. > endif. > endselect. >>
>
> Regards,
> Sachin
syntactically incorrect.
‎2009 Mar 19 10:06 AM
hello matt and santosh
thanks for your correct information.
for others,
for getting one record i am using select single only and I have already mentioned that i dont want to use internal table here.
thanks & regards
soniya.
‎2009 Mar 19 9:38 AM
Hi Soniya,
Try like this.
DATA: s type i.
SELECT *
FROM mara <--- First select all records from database tab to internal table
INTO TABLE itab.
*Loop at internal table, find a unique record's position which is in same position in DB
IF sy-subrc = 0.
LOOP AT itab into wa.
if wa-matnr = '000000000000000127'.
s = sy-tabix. <-- Sy-tabix gives current record position same as in mara table
endif.
ENDLOOP.
ENDIF.
Edited by: Sap Fan on Mar 19, 2009 10:38 AM
Edited by: Sap Fan on Mar 19, 2009 10:40 AM
‎2009 Mar 19 9:41 AM
With relational database, there is no concept of "position" within a database table.
What are you wanting to achieve?
matt
‎2009 Mar 19 9:52 AM
Hi,
It is not the right way to identify the position based on the databse entries.
Still you want to do that here is the logic,
select * from dbtab into table it_tab. "First fetch all entries
select single * from dbtab into wa_tab where <condition>. "Now just get the record which you need
read table it_tab with key keyfield1 = wa_tab-keyfield1 ... transporting no fields.
write: / sy-tabix. "Here sy-tabix will give the position of the recordRegards,
Manoj Kumar P