‎2007 Apr 26 5:11 PM
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 ?
‎2007 Apr 26 5:17 PM
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
‎2007 Apr 26 5:18 PM
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
‎2007 Apr 26 5:18 PM
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
‎2007 Apr 26 5:19 PM
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.
‎2007 Apr 26 5:19 PM
Ravinder,
Just press F1 on ORDER BY and i'm sure you will get the answer.
Regards,
Amey
‎2007 Apr 26 5:19 PM
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
‎2007 Apr 26 5:22 PM
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 ?
‎2007 Apr 26 5:24 PM
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
‎2007 Apr 26 5:25 PM
ORDER BY is performed by the Database server.
SORT BY is performed by the Application server.
Doing at the DB server is much faster.
‎2007 Apr 26 5:29 PM
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?