[ABAP] OData: $orderby implementieren

Variante 1

* https://blogs.sap.com/2013/09/03/sap-gw-implement-a-better-orderby-for-cust-ext-class/
* http://www.techippo.com/2016/08/sorting-query-options-orderby-sap-odata-service.html
* http://www.saplearners.com/orderby-query-option-in-sap-netweaver-gateway/
* https://blogs.sap.com/2017/12/06/display-countfilterorderbyinlinecounttop-and-skip-operations-using-odata-services/

METHOD xyz_get_entityset.

  ...

  DATA(it_orderby) = io_tech_request_context->get_orderby( ).

  IF line_exists( it_orderby[ property = 'MATNR' ] ).
    DATA(lv_orderby) = it_orderby[ property = 'MATNR' ].

    CASE lv_orderby-order.
      WHEN 'asc'.
        SORT: et_entityset BY name ASCENDING.
      WHEN 'desc'.
        SORT: et_entityset BY name DESCENDING.
    ENDCASE.
  ENDIF.

  ...

ENDMETHOD.

Variante 2

METHOD xyz_get_entityset.

  ...

  DATA(it_orderby) = io_tech_request_context->get_orderby( ).

  READ TABLE it_orderby INTO DATA(ls_orderby) INDEX 1.
  IF sy-subrc = 0.
* generische Order-Property verwenden, wenn z.B. nur ein Sortierkriterium vorhanden
* (z.B. beim Anklicken von Tabellenfeldern)
    CASE ls_orderby-order.
      WHEN 'asc'.
        SORT: et_entityset BY (ls_orderby-property) ASCENDING.
      WHEN 'desc'.
        SORT: et_entityset BY (ls_orderby-property) DESCENDING.
    ENDCASE.
  ENDIF.

  ...

ENDMETHOD.

[OData] Übersicht zu OData-Abfrageoptionen (Query-Optionen)

Option       | manuell implementieren
-------------+-----------------------
$count       | nein
$expand      | nein
$filter      | ja
$format      | nein
$inlinecount | ja
$link        | nein
$orderby     | ja
$select      | nein
$skip        | ja
$skiptoken   | ja
$top         | ja
$value       | nein

Links