Skip to Content
avatar image
Former Member

ABAP Query to display top 5 employees who are having highest salary

How will you write a query in abap to display top 5 emplyeee records who are having Highest Salary Among all the employees.

Please Reply...

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

2 Answers

  • avatar image
    Former Member
    Mar 17, 2010 at 08:00 AM

    Hi,

    if you know table and field which contains this information,

    then the query would be:

    SELECT *
      UP TO 5 ROWS
      INTO TABLE gt_itab
      FROM table_name
      WHERE specify_some_conditions
      ORDER BY salary_field DESCENDING.
    

    Regards,

    --

    Przemysław

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi Kush,

      Before writing any Database Query, always keep 2 important thumb rules in your mind :

      1. Keep the number of data base access small

      2. Keep the amount of data transfer small.

      As you mentioned the Database Table has only 100 records, you can locally buffer the Table. So, make a local buffering and then you can sort the table based on the salary.

      Select *

      from Table_name

      into table gt_itab.

      Sort gt_itab by salary descending.

      Now you can read the entries one after the another based on the index.

      Have a look at the following code for an efficient performance feature. Goto SE38 and have a look at the ABAP Examples.

      demo_select_some_columns. Package : SABAPDEMOS

      Hope this will help.

      Thanks,

      Samantak.

  • avatar image
    Former Member
    Mar 17, 2010 at 02:40 PM

    Moderator message - Please do not ask or answer basic questions - thread locked Rob

    Add comment
    10|10000 characters needed characters exceeded