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

Code Based OData. How to implement orderby

suwandi_cahyadi
Contributor
5,222

Hello,

How to implement orderby in Code based OData? I try CDS based OData expose as RDS in SEGW and create the UI using Fiori Elements List Report. Then I redefine the GET_ENTITYSET in DPC_EXT class and I do not call the super class.

Here is how I currently implement the orderby

    SELECT ....
      INTO TABLE @DATA(lit_data)
....

    " order by
    CALL METHOD /iwbep/cl_mgw_data_util=>orderby
      EXPORTING
        it_order = it_order
      CHANGING
        ct_data  = lit_data.
....
implement paging & stuff

I can debug and show that the internal table it is actually sorted correctly. But somehow, in the List Report application, the record is not shown as in the same order as in the internal table.

How to implement order by correctly?

Thank you.

Accepted Solutions (1)

Accepted Solutions (1)

suwandi_cahyadi
Contributor
0 Likes

Hi,

I solve this by specifying the correct keys in the CDS. So, in the report result there are actually 2 fields that make each record unique, but in the CDS I only specify 1 of those 2 field as the key. I set 2 fields as keys correctly and now the sorting works.

Thank you.

Answers (1)

Answers (1)

gregorw
SAP Mentor
SAP Mentor

Hi,

I've had an issue when using the it_order value. But I've replaced that by the content that you can read with io_tech_request_context->get_orderby( ). And I'm using et_entityset to do the operation:

    DATA: lt_order TYPE /iwbep/t_mgw_sorting_order.

    IF NOT it_order IS INITIAL.

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

      LOOP AT lt_orderby ASSIGNING FIELD-SYMBOL(<fs_orderby>).
        APPEND INITIAL LINE TO lt_order ASSIGNING FIELD-SYMBOL(<fs_order>).
        MOVE-CORRESPONDING <fs_orderby> TO <fs_order>.
      ENDLOOP.

      /iwbep/cl_mgw_data_util=>orderby(
        EXPORTING
          it_order = lt_order
        CHANGING
          ct_data  = et_entityset
      ).
    ENDIF.

Maybe that helps.

Best Regards
Gregor

dkremer
Discoverer
0 Likes

Thanks for the code snippet Gregor. Using it in a project but unfortunately this approach is case-sensitive which means it orders like ABCDabcdÄÖÜäöü.

Is there any way to do it like AaÄäBbCcDd so it is not case-sensitive and the 'Umlaute' are at their corresponding neighbours?