cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sort oder of CDS-View

Former Member
49,631

Hi Experts,

I don;t understand how can I maintain the sort order of CDS view? For example I want to create cds view of table SPFLI and sort it by connnid. How can I do this. I use statement

DEFINE VIEW Z_spfli_view AS SELECT FROM spfli {

     connid as number,

}

And after that I can;t use ORDER BY. So how can I sort the result list? Maybe some annotations can be used?

Best Regards,

Mikhail

Accepted Solutions (1)

Accepted Solutions (1)

pfefferf
Active Contributor

Hello,

for a HANA CDS View you can use "order by". For an ABAP CDS View no "order by" is possible. You have to to the sort when you consume the view in e.g. an Open SQL Statement.

Regards,

Florian

Former Member
0 Likes

ok, so, I have no possibility to sort it without starting ABAP Report? I just want to create smart template fiori application. For this I created a CDS view, then generated ODATA service. Is it possible maybe to create some 'consumption' view and use some analytical annotations? I need to sort it without coding. Or it is absolutely impossible?

pfefferf
Active Contributor
0 Likes

There exists no annoation to define a kind of "default sort" (UI Annotations - Reference - SAP Library). On the backend side it would also make no sense to define a hard sort criterion because from the client side different sort criteria may be used (specific to the requirements).

On the client side you could add a default sort criterion during start up which is then applied as filter to the binding of the OData service.

Herbert_Stoe
Newcomer
0 Likes
.... so SAP learned that order by might be useful - in thinking that the database should handle the performance load (if possible) and not the application server, I got the impression that ABAP CDS is implemented improperly considering sorting..

Answers (1)

Answers (1)

stephenl1
Participant

You can use the KEY keyword in front of the fields in your view that you want to sort the view by. These fields must all be listed as the first fields in your view. You should also specify the

role of annotation AbapCatalog.preservekey: True at the top of your code. See Key definition in cds views for more details.