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

Difference between SORT and Order by Clause!!

Former Member
0 Likes
3,192

Hi,

Can anyone give me the difference between SORT and ORDER BY?

Thanks!!

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,684

Hi,

You can sort a standard or hashed table in a program. To sort a table by its key, use the statement

SORT ASCENDING .

The statement sorts the internal table ASCENDING

BY ASCENDING

...

ASCENDING .

The table is now sorted by the specified components ASCENDING

ASCENDING ...

The lines are sorted by the columns .....

Example

DATA: BEGIN OF WA,

CARRID TYPE SFLIGHT-CARRID,

CONNID TYPE SFLIGHT-CONNID,

MIN TYPE I,

END OF WA.

SELECT CARRID CONNID MIN( SEATSOCC ) AS MIN

INTO CORRESPONDING FIELDS OF WA

FROM SFLIGHT

GROUP BY CARRID CONNID

ORDER BY CARRID MIN DESCENDING.

WRITE: / WA-CARRID, WA-CONNID, WA-MIN.

ENDSELECT.

The output is as follows:

The lines of the database table SFLIGHT are grouped according to the columns CARRID and CONNID, and the system finds the minimum value of the column SEATSOCC for each group. The selection is sorted by CARRID in ascending order and by the minimum value of SEATSOCC in descending order, using the alias name MIN for the aggregate expression.

with regards,

sowjanya

2 REPLIES 2
Read only

Former Member
0 Likes
1,684

Hi,

SORT is used to sort internal tables in abap programs

order by is used in select query to retrieve data form database tables

by ascending or descending

Regards,

V.Balaji

Reward if Usefull...

Read only

Former Member
0 Likes
1,685

Hi,

You can sort a standard or hashed table in a program. To sort a table by its key, use the statement

SORT ASCENDING .

The statement sorts the internal table ASCENDING

BY ASCENDING

...

ASCENDING .

The table is now sorted by the specified components ASCENDING

ASCENDING ...

The lines are sorted by the columns .....

Example

DATA: BEGIN OF WA,

CARRID TYPE SFLIGHT-CARRID,

CONNID TYPE SFLIGHT-CONNID,

MIN TYPE I,

END OF WA.

SELECT CARRID CONNID MIN( SEATSOCC ) AS MIN

INTO CORRESPONDING FIELDS OF WA

FROM SFLIGHT

GROUP BY CARRID CONNID

ORDER BY CARRID MIN DESCENDING.

WRITE: / WA-CARRID, WA-CONNID, WA-MIN.

ENDSELECT.

The output is as follows:

The lines of the database table SFLIGHT are grouped according to the columns CARRID and CONNID, and the system finds the minimum value of the column SEATSOCC for each group. The selection is sorted by CARRID in ascending order and by the minimum value of SEATSOCC in descending order, using the alias name MIN for the aggregate expression.

with regards,

sowjanya