Quantcast
Channel: SCN : All Content - SAP Gateway
Viewing all articles
Browse latest Browse all 2823

SAP GW - Implement a better OrderBy for Cust EXT Class

$
0
0

Intro

If you have defined your OData Service in transaction SEGW and use the own class (* _DPC_EXT) for Service Implementation,

you may have asked yourself how to use the parameter IT_ORDER of Type  /IWBEP/T_MGW_SORTING_ORDER to implement sorting of your entity table.

 

One way could be to use standard GW util class  /IWBEP/CL_MGW_DATA_UTIL and its method orderBy.

But by using this, it might happen that you stumble upon a constraint where you get an exception if you use a parameter in your orderBy clause which has a underline in its name definition.

 

For example you would use this URL where StartDate is the attribute you want to sort descending:

 

/sap/opu/odata/sap/<YOUR_SERVICE_NAME>/ProjectSet?$orderby=StartDate%20desc

 

The Problem is that 'StartDate' is the attribute name of your gateway service entity and in you backend table it could have the name 'START_DATE'.

 

so  'StartDate' <> 'START_DATE'

 

Because of the implementation of the method orderBy you will get an Error : "RFC Error: Incorrect value in the dynamic table."

 

HowTo

To get arround this pittfall you could use your own util class to sort the table.

It could look like this:

 

IT_ORDER    TYPE /IWBEP/T_MGW_SORTING_ORDER    the sorting order
CT_DATA      TYPE STANDARD TABLE   " * CT_DATA is your Entetyset table returning just after the select from db.  

 

METHOD orderby.   DATA: lt_otab   TYPE abap_sortorder_tab,              ls_oline  TYPE abap_sortorder.   DATA: ls_order LIKE LINE OF it_order.   CONSTANTS:BEGIN OF lcs_sorting_order,                             descending TYPE string VALUE 'desc',                            ascending  TYPE string VALUE 'asc',             END OF   lcs_sorting_order.   LOOP AT it_order INTO ls_order.      ls_oline-name = ls_order-property.     "* Transform OData FieldName to ABAP Field Name     "* 'StartDate' to 'START_DATE'      ls_oline-name =  from_mixed( val = ls_oline-name ).     IF ls_order-order = lcs_sorting_order-descending.          ls_oline-descending = 'X'.     ENDIF.     APPEND ls_oline TO lt_otab.     CLEAR ls_oline.   ENDLOOP.   SORT ct_data BY (lt_otab).


ENDMETHOD.

 

 

The clue is to use intern transform method  from_mixed

This one will transform 'StartDate' to 'START_DATE' and  allows so to sort internal tables.


Viewing all articles
Browse latest Browse all 2823

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>