07-13-2020 5:00 PM
Hi,
i want to get the 5th record from the table sbook.
i shall i retrieve it?
regards,
diptojyoti dutta
07-13-2020 5:01 PM
Thank you for visiting SAP Community to get answers to your questions. Since you're asking a question here for the first time, I recommend that you familiarize yourself with https://community.sap.com/resources/questions-and-answers (if you haven't already), as it provides tips for preparing questions that draw responses from our members. For example, you can outline what steps you took to find answers (and why they weren't helpful), share screenshots of what you've seen/done, make sure you've applied the appropriate tags, and use a more descriptive subject line. The more details you provide, the more likely it is that members will be able to assist you.
Should you wish, you can revise your question by selecting Actions, then Edit (although once someone answers your question, you'll lose the ability to edit the question -- but if that happens, you can leave more details in a comment).
Finally, if you're hoping to connect with readers, please consider adding a picture to your profile. Here's how you do it: https://www.youtube.com/watch?v=F5JdUbyjfMA&list=PLpQebylHrdh5s3gwy-h6RtymfDpoz3vDS. By personalizing your profile with a photo of you, you encourage readers to respond.
Kind regards,
--Jerry
07-14-2020 12:01 AM
A database table is not a spreadsheet.
i.e. it does not have a row number or record number.
Think through this and look up some basic videos.
07-14-2020 4:44 AM
diptdutt,
Am not sure about the need of such requirement. May be if you tell us the actual requirement we may come up with better solutions.
One general way is getting the entries into an internal table and later read the internal table using Index values.
Regards!
07-14-2020 9:27 AM
The most important part about your requirement, is that you need to have a defined sort order, otherwise, your requirement is very questionable. If your sort order is the 'primary key', you still will have to define that sort order in your select statement, to always guarantee this order.
With ABAP 7.52, you can use offset and together with up to n rows, you can select your '5th record'. However, it is mandatory that you need to define a ORDER BY statement with OFFSET. This is because like explained above and by default, without a specifically defined order, the returned dataset is not guaranteed a reliable order.
Read the ABAP documentation for more information about SELECT ... OFFSET:
" ABAP 7.52 and higher
SELECT * FROM sbook
ORDER BY carrid, connid, fldate, bookid
INTO TABLE @DATA(result_5th)
UP TO 1 ROWS
OFFSET 4.
cl_demo_output=>write( result_5th ).
SELECT * FROM sbook
ORDER BY carrid, connid, fldate, bookid
INTO TABLE @DATA(result_all).
cl_demo_output=>display( result_all ).
If you have ABAP 7.51 and lower, the SELECT ... OFFSET statement is not available. Therefore, you will have to select all the data up to the requested record and later discharge those records you do not want to have. You could alternatively also implement a SELECT ... ENDSELECT statement and only copy the 5th record and exit the select loop, I wouldnt recommend this though, especially if you are looking for the e.g. 100'000th record, due to performance reasons. (As a side note SELECT ... ENDSELECT is best used in combination with PACKAGE SIZE x.)
" ABAP 7.51 and lower
SELECT * FROM sbook
ORDER BY carrid, connid, fldate, bookid
INTO TABLE @DATA(result_5th)
UP TO 5 ROWS.
DELETE result_5th FROM 1 TO 4.
cl_demo_output=>write( result_5th ).
SELECT * FROM sbook
ORDER BY carrid, connid, fldate, bookid
INTO TABLE @DATA(result_all).
cl_demo_output=>display( result_all ).
09-20-2020 6:04 AM
diptdutt, do you continue to have issues or were you able to solve your problem?
Please add comments to your question that further describe your problem or add an answer that describes how you solved your problem.
If your problem is solved, accept an answer if it helped you, and please close the question.