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

Order by

Former Member
0 Likes
1,009

In this code :

DATA T100_WA TYPE T100.

SELECT * FROM T100

INTO T100_WA

WHERE SPRSL = SY-LANGU AND

MSGNR < '010'

ORDER BY PRIMARY KEY.

ON CHANGE OF T100_WA-ARBGB.

ULINE.

WRITE: / '**', T100_WA-ARBGB, '**'.

ENDON.

WRITE: / T100_WA-MSGNR, T100_WA-TEXT.

ENDSELECT.

What ll be the diff if we dont the order by clause.

And wat is the use of order by clause.

when exactly do we use it ?

10 REPLIES 10
Read only

Former Member
0 Likes
967

HI ravinder,

We would get the records in a sorted order if we do it this way.

the problem in this approach is that it takes a lot of time.(Performance issue).

Regards,.

ravi

Read only

Former Member
0 Likes
967

Hi

T100 stores all messages

When you use SORT BY all the key field values are sorted and displayed in the alphabetical order

if you don't use ORDER BY

they will come without order, as they are stored in table.

menas sorting will not be done.

reward points if useful

regards,

Anji

Read only

Former Member
0 Likes
967

Hi,

Sorts the lines of the selection.

Syntax

... ORDER BY PRIMARY KEY |... <si> [ASCENDING|DESCENDING]...

Sorts the selection in ascending or descending order according to the primary key or the contents of the fields listed.

Regards,

Bhaskar

Read only

Former Member
0 Likes
967

Records in a DB table are not necesarily stored in an "orderly" fashion - by the primary key, for example.

The ORDER BY clause allows you to sequence/order the returned DB records in a fashion/order that is most efficient for your application code. It simply reduces extra application code that you might need to write.... and it makes your application prog run faster. It is ALWAYS faster to have the DB records returned to the app prog in a pre-ordered fashion... rather than having the app prog do the ordering after receiving the records from the DB.

Read only

Former Member
0 Likes
967

Ravinder,

Just press F1 on ORDER BY and i'm sure you will get the answer.

Regards,

Amey

Read only

Former Member
0 Likes
967

Hi,

The ORDER BY clause is used to give the records in the sorted manner...

In the database table it is not necessary the records will be stored in the sorted order..

IN your case...There are just displaying the unique message IDs ...otherwise..

THE ON CHANGE OF ...will trigger for every change in the message id..

If it is is not sorted then it will show duplicate records in the output..

If it is sorted then it will not show duplicate records..

SELECT * FROM T100

INTO T100_WA

WHERE SPRSL = SY-LANGU AND

MSGNR < '010'

ORDER BY PRIMARY KEY.

ON CHANGE OF T100_WA-ARBGB.

ULINE.

WRITE: / '**', T100_WA-ARBGB, '**'.

ENDON.

WRITE: / T100_WA-MSGNR, T100_WA-TEXT.

ENDSELECT.

Thanks,

Naren

Read only

Former Member
0 Likes
967

Order by is used for sorting.

then even the key Sort does the same job .

what is the diff b/w order by and sort ?

Read only

0 Likes
967

Order by operates on database table.

sort operates on internal tables.

But , order by is an obsolete statement and hence use sort statement on internal tables.

Regards,

Ravi

Read only

0 Likes
967

ORDER BY is performed by the Database server.

SORT BY is performed by the Application server.

Doing at the DB server is much faster.

Read only

0 Likes
967

Ravi,

<b>"But , order by is an obsolete statement "</b>

I hope this statement is not true. ORDER BY is part of SQL natively.

Where have you seen that SAP has made it obsolete in OpenSQL?