CDS VIEW Table Function Sorting
CDS VIEW Table Function Sorting
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.
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
}