Skip to Content

RowNum option does works in ABAP programming

Hi hello

i want to select a specific row in a table.

for example i want to select 10 the highest salary from

zemp3 table

i have written the select statement

select distinct salary from zemp3 where RowNum = 10.

it's not working

so kindly if u know any solution please share with me

Add a comment
10|10000 characters needed characters exceeded

Related questions

3 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 03, 2005 at 05:06 AM

    Hi hello

    To select a specific row in a table the command is

    TABLES ZEMP3.

    SELECT * FROM ZEMP3 UPTO 10 ROWS.

    READ TABLE ZEMP3 INDEX = 10.

    this would take the pointer to the 10th row

    regards

    suresh krishnan

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 31, 2004 at 05:33 PM

    Hi Shiva

    You can not use "rownum" in OpenSQL (ABAP) queries. Thus, you should first select all values into an internal table, then sort it and finally get top 10.

    <u><b>e.g.</b></u>

    DATA: BEGIN OF lt_salary OCCURS 0 ,
            salary LIKE zemp3-salary ,
          END OF lt_salary .
    
    SELECT DISTINCT salary FROM zemp3
           INTO TABLE lt_salary .
    
    SORT lt_salary DECREASING BY salary .
    LOOP AT lt_salary .
      WRITE:/ lt_salary-salary .
      IF sy-tabix = 10 .
        EXIT .
      ENDIF .
    ENDLOOP .
    

    I can't figure out whether the following code may also suit since I am not sure whether it orders first and then selects up to n entries or first selects and then orders. For the latter case, your output will not be as you want. However, you can try and see it.

    SELECT DISTINCT salary FROM zemp3
           UP TO 10 ROWS
           INTO TABLE lt_salary
           ORDER BY salary .
    

    This can also be a way:

    TABLES zemp3 .
    SELECT salary FROM zemp3
           ORDER BY salary .
      WRITE:/ zemp3-salary .
      IF sy-tabix = 10 .
        EXIT .
      ENDIF .
    ENDSELECT .
    

    Regarding the number of entries of zemp3 and its indices, one of these 3 (assuming all provides the same output) ways should be the optimum .

    <i>And as a last thing, let me introduce you the SDN forums pointing system: You can assign points to posts you find helpful while solving your question. You can reward points by clicking the yellow star icon at header of each reply post. You can reward;

    - one 10 points (solved)

    - two 6 points (very helpful answer)

    - many 2 points (helpful answer)</i>

    Happy new year...

    *--Serdar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 01, 2005 at 07:06 AM

    Hi,

    Not being able to select 10th row is inline with Dr. E.F. Codd's 12 rules that a database management system (DBMS) must adhere to in order to be considered a relational database. In practice, many database products are considered 'relational' even if they do not strictly adhere to all 12 rules. Rule # 2 states:

    <b>

    Data is Logically Accessible

    </b>

    <i>

    a) A relational database does not reference data by physical location; there is no such thing as the fifth row in the customers table

    b) Each piece of data must be logically accessible by referencing 1) a table; 2) a primary or unique key value; and 3) a column

    </i>

    Hence as Serdar mentioned, you need a solution that works on the app server layer.

    Hope this helps.

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.