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

second highest salary

Former Member
0 Likes
3,105

there is a field in internal table that contains salary of employees. How can I get the second highest salary and if there r two or more second highest salary , how can I get it?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,595

Hi,

first u create one duplicate table with all thos entries.

then in that table. get the max value of the salary and then remove that field from the duplicate table and now try to find out the highest value in that table then after that find how many rows are there with that value then u can get all the second highest salaries..

if it is usefull plzz reward plzz dont forget to reward..

plz dont forget to reward plzzzz....

there is a field in internal table that contains salary of employees. How can I get the second highest salary and if there r two or more second highest salary , how can I get it?

4 REPLIES 4
Read only

Former Member
0 Likes
1,596

Hi,

first u create one duplicate table with all thos entries.

then in that table. get the max value of the salary and then remove that field from the duplicate table and now try to find out the highest value in that table then after that find how many rows are there with that value then u can get all the second highest salaries..

if it is usefull plzz reward plzz dont forget to reward..

plz dont forget to reward plzzzz....

Read only

Former Member
1,595

HI Tanuj

How about using sub query while using the select statement.

Eg:


DATA: g_mnr TYPE fcmnr.

SELECT MAX( mnr ) INTO g_mnr FROM t247
   WHERE spras = sy-langu
   AND   mnr < ( SELECT MAX( mnr ) FROM t247
                    WHERE spras = sy-langu ).

WRITE:/ g_mnr.

In above example am trying to retreive second highest month.

Regards

Eswar

Read only

Former Member
0 Likes
1,595

Hi tanuj joshi,

Try like this code.

Data:

begin of itab occurs 10,

name(20),

sal type i,

end of itab.

sort itab by sal descending.

read table itab index 2.

write: itab-sal,

'Is the second higest salary'.

Plzz reward if it is useful,

Mahi.

Read only

Former Member
0 Likes
1,595

Hi tanuj joshi,

Try like this code.

>Data :

> sal1 type i,

> sal2 type i.

>

>Data:

> begin of itab occurs 10,

> name(20),

> sal type i,

> end of itab.

>

>

>sort itab by sal descending.

>

>

>loop at itab.

>

>at first.

> itab-sal = sal1.

>endat.

>

> if itab-sal ne sal1 and itab-sal ge sal2.

> write / itab-sal.

> itab-sal = sal2.

> else.

> exit.

> endif.

>

>endloop.

Plzz reward if it is useful,

Mahi.