Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Database record position

Former Member
0 Likes
1,696

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.

1 ACCEPTED SOLUTION
Read only

matt
Active Contributor
0 Likes
1,355

With relational database, there is no concept of "position" within a database table.

What are you wanting to achieve?

matt

11 REPLIES 11
Read only

Former Member
0 Likes
1,355

GOTO se11 > DD03L > Give tabname (MARA) and fieldname (MATNR) > you will get its postion (2) in POSITION field.

Regards,

Sachin

Read only

0 Likes
1,355

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

Read only

0 Likes
1,355

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.

Read only

Former Member
0 Likes
1,355

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.

Read only

Former Member
0 Likes
1,355

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

Read only

Former Member
0 Likes
1,355

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

Read only

matt
Active Contributor
0 Likes
1,355

>

> 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.

Read only

0 Likes
1,355

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.

Read only

awin_prabhu
Active Contributor
0 Likes
1,355

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

Read only

matt
Active Contributor
0 Likes
1,356

With relational database, there is no concept of "position" within a database table.

What are you wanting to achieve?

matt

Read only

Former Member
0 Likes
1,355

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 record

Regards,

Manoj Kumar P