0% found this document useful (0 votes)
3K views

CDS VIEW Table Function Sorting

The document describes two ways to add sorting to a CDS view. The first uses a table function with a class method that performs a SQL query with an ORDER BY clause. The second defines a view that groups on a key and aggregates the maximum value of another field, then joins this view to the original table to apply the implicit sorting. Both approaches allow sorting data in a CDS view without native view sorting capabilities.

Uploaded by

Gamers game
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3K views

CDS VIEW Table Function Sorting

The document describes two ways to add sorting to a CDS view. The first uses a table function with a class method that performs a SQL query with an ORDER BY clause. The second defines a view that groups on a key and aggregates the maximum value of another field, then joins this view to the original table to apply the implicit sorting. Both approaches allow sorting data in a CDS view without native view sorting capabilities.

Uploaded by

Gamers game
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CDS VIEW Table Function Using Sort

In CDS VIIEW , This is no possible way to do a sorting for table But , we achieve using OOPS
class object. Sorting helps us to make data align clean and clearly . So using of sorting is
good way in some place.
Example Code:
Part 1.
@endusertext.label : ’CDS View Sorting’
Define table function zji_tf_sorting
Returns
{
Mandt: mandt;
Ebeln:ebeln;
Ebelp:ebelp;
Matnr:matnr;
Maktx:maktx;
}
Implemented by method zcl_sort=>get_sorting;

Part 2:
Class zcl_sort definition public.
Public section.
Interfaces if_amdp_marker_hdb.
Class-methods get_sorting for table function zji_tf_sorting.
Endclass.
Class zcl_Sort implementation.
Method get_sorting for database function for hdb language sqlscript
Options read-only using ekpo makt.
Return select ekpo.mandt , ebeln , ebelp , ekpo.matnr , maktx from ekpo
Left outer join makt on ekpo.matnr = makt.matnr order by ebelp desc;
Endmethod.

Order by helps to make the sort option for CDS View

There is another way of making sort option without table Function, Examples on given
below.
Part 1:
@abapcatalog.sqlviewname: ‘zjoins’
@abapcatalog.complier.complierfilter: ‘TRUE’
@accesscontrol.authorizationcheck: #CHECK
@endusertext.label : ’CDS View Sorting’
Define view zsorting as select from ekpo
{
Key Ebeln,
Max(ebelp) as ebelp;
} group by ebeln

Part 2:
@abapcatalog.sqlviewname: ‘zjoins’
@abapcatalog.complier.complierfilter: ‘TRUE’
@accesscontrol.authorizationcheck: #CHECK
@endusertext.label : ’Source target’
Define view ztarget as select from zsorting left outer join ekpo on
Zsorting.ebeln = Ekpo.ebeln and zsorting.ebelp = ekpo.ebeln
{
Key Ekpo.ebeln,
Ekpo.ebelp,
Matnr,
maktx
}

You might also like