2012 Nov 14 4:03 AM
Hi all,
Can I SORT a database ZTABLE using an ABAP statement ? I know SORT statement works on itabs.
However can I sort a ZTABLE using ABAP ? Or can I put a condition somewhere that whenever an entry e.g NAME is entered into a ZTABLE it always remain sorted based on the NAME column ?
Thanks
Noman
2012 Nov 14 5:55 AM
Hello Noman ,
- You very well have a addition of syntax
ORDER BY <Field> [ASCENDING|DESCENDING]
<Field> [ASCENDING|DESCENDING] ...
While you fetch the data into a internal table from the custom table using a select query .
- You can verywell create a Index too but as you suggest that your field is a Char type but While creating the index
- Mind the lenght of the Field
- The volume of the data in the Table
- The Hit Rate of the Index you will be creating .
Hope this helps...
Anup Deshmukh
2012 Nov 14 5:01 AM
Basically, SORT cannot be directly used with DB Tables.
>>NAME is entered into a ZTABLE it always remain sorted based on the NAME column ?
What is the need for this?
If your intention is to increase the performane during search, then you can create index for the Table with NAME as index key.
2012 Nov 14 5:55 AM
Hello Noman ,
- You very well have a addition of syntax
ORDER BY <Field> [ASCENDING|DESCENDING]
<Field> [ASCENDING|DESCENDING] ...
While you fetch the data into a internal table from the custom table using a select query .
- You can verywell create a Index too but as you suggest that your field is a Char type but While creating the index
- Mind the lenght of the Field
- The volume of the data in the Table
- The Hit Rate of the Index you will be creating .
Hope this helps...
Anup Deshmukh
2012 Nov 14 10:35 AM
You have sorted indexes for quick access, and you can use SQL and ABAP constructs like ORDER BY to retrieve the data in a predictable sequence, or SORT the result set afterwards.
So what is the use of sorting the data stored inside the DB table?
Please clarify the context.
Thomas
2012 Nov 14 11:04 AM
Hi Noman,
SAP/ABAP communicates with a relational database. By definition, a database sort order is determined by it's primary key.
This means: A database table is sorted. You can not sort it.
A better approach may be to explain what is your goal, what is the desired result or function?
Regards
Clemens