Hi Experts,
Do we have a way to fetch data from specific row numbers of a database table in an ABAP program.
The requirement is as follows: 'The user may enter the 'from' row number and 'to' row number on the selection screen.
The program is supposed to process only those rows from the database table. Also none of the key feild values are known during this.
Please note the table may contain millions of records.
Thanks & Regards,
Diptee
Hi Diptee,
This is not a very good technique of retrieving data. Ask if the selection logic can be enhanced...
If you have to go about it anyways, check if the table has a sr. no or counter of any kind?
If it does, you may frame the where clause between the 'from' and 'to' row number.
Regards,
Xineohpi.
Not possible. There is no nth record in RDBMS.
Hi kesavadas,
why is it not possible?
P.S : My question is out of pure curiousity.
It's because the order of rows are not defined or fixed.
You can use select..endselect and use the sy-dbcnt to know the row no. But the same row will be in some other position tomorrow due to data manipulation, reorganization etc. So the concept of nth record is not valid.
Kesav
According to Diptee the 'from' and 'to' parameters will be specified in the i/p.
Assuming the report user will be checking the table and then entering the parameters, the requirement only requires a simple select stmt:
SELECT *
FROM <TABNAME>
INTO TABLE <INT_TABNAME>
WHERE SRN BETWEEN p_from AND p_to.
legend: SRN : SERIAL NO. of the records,
p_from : i/p parameter for specifying from records no
p_to : i/p parameter for specifying from records no
However vague the requirement sounds, i believe it can be solved.
Regards,
Xineohpi.
So you have a field called as SRN ? Then its possible.
Think about this requirement for a while!
So the user will be "checking" the table, ... by doing what? Paging through several million rows, displayed on the screen, not ordered by any criteria and not filtered by any condition?
*this will be funny*
And then the user decides: I need to process data from row 345.789 up to row 345.987
And the user will then process this data in any not yet specified way, without knowing keys and after that the user will never find row 345.789 back again because another user had deleted rows 123.456 up to row 123.987, so all the other rows following those will change their number (see why there is no such SRN? The DB would go mad about wasting CPU cycles to maintain this completely useless numbers).
Some DBs have a virtual column to apply numbers to a resultset (NOT to table data), which can be very tricky to work with if one is not aware about how these columns are built and when.
Volker
Hi Xineohpi Iphoenix,
That is not good logic of course, there may not be that kind of requirement.
or else if you want that much ,
take whole table data into one internal table,
insert intaernaltable1 lines from n1 to n2 into another internal table2.
use the 2nd internal table2. This may work but not good approch.
Regards
Chaitanya
Please check who has raised the question.
Btw the table supposedly has millions of records. Selecting all the records into an internal table w/o any conditions will immensely affect d/b load and the expense of passing the records to another internal table will be another story altogether.
As posted earlier, if the table has counter or serial number, it is possible to filter and fetch the records efficiently..
Hi check below code i used native sql because their is only possibility with rowid to find row because their is no concept of row number ,
Hey this code is just for information purpose but this is not good idea to find out row ,
better you can fetch record from table based on criteria .
more better information you can find about this by any RDBMS book. ![]()
types: BEGIN OF ty,
MATNR type makt-MATNR,
maktx type makt-maktx,
rowid type char50,
END OF ty.
DATA : it_wa TYPE STANDARD TABLE OF ty WITH HEADER LINE,
wa TYPE ty.
data : c1 type makt-matnr value '000000000110000005',
c2 type char50 value 'AAAiwKAAHAAArrMAAC'.
START-OF-SELECTION.
PERFORM get_data.
IF it_wa[] IS NOT INITIAL.
LOOP AT it_wa into wa.
write : / wa-matnr , wa-maktx , wa-rowid.
ENDLOOP.
ENDIF.
FORM loop_output.
it_wa = wa.
APPEND it_wa.
ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form GET_DATA .
" For finding rowid use where clause in below native sql statement ( where matnr = :c1 )
EXEC SQL PERFORMING loop_output .
select matnr, maktx, rowid into :wa
from makt where rowid = :c2
ENDEXEC.
endform. " GET_DATA
Thanks All,
We do not have a serial number feild in our table; hwnce it seems like we can only achieve the requriement using native SQL.
Please suggest if there can be any alternatives, which will not be taxing upon the performance of the program.
Thanks and Regards,
Diptee
This has been discussed many times. There is no such thing as first, next or last row in a table. Whatever row you decide is first may turn up in a different order in a different select - particulary if something like a database re-org is done in the meantime.
Rob