Application Development 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: 

Display records in Reverse order

Former Member
0 Kudos
174

Hi,

How to display the records in the Reverse order.

Display the records from the internal table where the employee salary is highest in his department.

This is my program.

*LINE TYPE.

TYPES:

BEGIN OF TY_EMP,

EMPID(4) TYPE C,

ENAME(30) TYPE C,

DEPT(4) TYPE C,

GRADE(1) TYPE C,

SALARY TYPE I,

END OF TY_EMP.

  • TABLE TYPE

DATA:

FS_EMP TYPE TY_EMP,

IT_EMP TYPE TABLE OF TY_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'X'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 10000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'Y'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 11000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E101'.

FS_EMP-ENAME = 'Z'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 12000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E103'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'B'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 7000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E105'.

FS_EMP-ENAME = 'C'.

FS_EMP-DEPT = 'D100'.

FS_EMP-GRADE = 'C'.

FS_EMP-SALARY = 5000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E100'.

FS_EMP-ENAME = 'D'.

FS_EMP-DEPT = 'D200'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 8500.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E200'.

FS_EMP-ENAME = 'E'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'B'.

FS_EMP-SALARY = 9000.

APPEND FS_EMP TO IT_EMP.

FS_EMP-EMPID = 'E104'.

FS_EMP-ENAME = 'F'.

FS_EMP-DEPT = 'D300'.

FS_EMP-GRADE = 'A'.

FS_EMP-SALARY = 13000.

APPEND FS_EMP TO IT_EMP.

LOOP AT IT_EMP INTO FS_EMP.

WRITE:/ FS_EMP-EMPID,FS_EMP-ENAME,FS_EMP-DEPT,FS_EMP-GRADE,FS_EMP-SALARY.

ENDLOOP.

3 REPLIES 3

Former Member
0 Kudos
55

Hi,

Before using loop at it_emp.

Sort it Like SORT IT_EMP BY SALARY DESCENDING.

Thanks,

Former Member
0 Kudos
55

Hi Ram,

this is pretty simple, use sort.

SORT IT_EMP BY SALARY DESCENDING.

LOOP AT IT_EMP INTO FS_EMP.

WRITE:/ IT_EMP-EMPID, IT_EMP-ENAME, IT_EMP-DEPT, IT_EMP-GRADE, IT_EMP-SALARY.

ENDLOOP.

Hope this solves your issue.

<b>Reward points if this helps,</b>

Kiran

Former Member
0 Kudos
55

Hi

U can do this by sorting.

SORT IT_EMP BY SALARY DESCENDING.

LOOP AT IT_EMP INTO FS_EMP.

WRITE:/ IT_EMP-EMPID, IT_EMP-ENAME, IT_EMP-DEPT, IT_EMP-GRADE, IT_EMP-SALARY.

ENDLOOP.

Regards,

Nikhil