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

Can I SORT a database ZTABLE using an ABAP statement ?

Former Member
0 Likes
1,351

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

1 ACCEPTED SOLUTION
Read only

anup_deshmukh4
Active Contributor
0 Likes
705

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

4 REPLIES 4
Read only

Former Member
0 Likes
705

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.

Read only

anup_deshmukh4
Active Contributor
0 Likes
706

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

Read only

ThomasZloch
Active Contributor
0 Likes
705

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

Read only

Clemenss
Active Contributor
0 Likes
705

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