OData Gateway
Architect / Cross-trackAdvanced

GET_ENTITYSET with Filters, Paging and Sorting

Implement list APIs properly using filters, $top, $skip and efficient Open SQL.

Explanation

GET_ENTITYSET is one of the most important OData methods because it returns list data to Fiori or external clients. A poor implementation selects all data and returns a huge response. A production-ready implementation reads filter values, applies WHERE conditions, respects $top and $skip and returns only required fields. Fiori apps often use paging and filters automatically. If the backend ignores them, performance becomes poor. A good ABAP Gateway developer maps OData filter conditions to Open SQL carefully and validates mandatory filters for high-volume tables.

Code example

ABAP Code
* Purpose:* Implement GET_ENTITYSET with filter and paging awareness.* Do not return all records blindly to Fiori. METHOD invoiceset_get_entityset.   DATA lt_filters TYPE /iwbep/t_mgw_select_option.  DATA lv_top     TYPE i.  DATA lv_skip    TYPE i.   * Read OData filter select options from request context  lt_filters = io_tech_request_context->get_filter( )->get_filter_select_options( ).   * Read paging values sent by Fiori/client  lv_top  = io_tech_request_context->get_top( ).  lv_skip = io_tech_request_context->get_skip( ).   * In real code, extract required filter values from LT_FILTERS.  * Example: customer, company code, date range.   SELECT vbeln, fkdat, kunag, netwr    FROM vbrk    INTO TABLE @DATA(lt_invoice)    UP TO @lv_top ROWS    WHERE kunag = @lv_customer      AND fkdat BETWEEN @lv_from AND @lv_to.   * Map DB result to entityset output  et_entityset = CORRESPONDING #( lt_invoice ). ENDMETHOD.

Real project scenario

An invoice list service initially returned all invoices and timed out in Fiori. After mapping customer/date filters and applying top/skip, response time improved significantly.

Common mistakes

- Ignoring filters. - Ignoring $top and $skip. - Returning huge datasets. - Filtering in ABAP after selecting all records.

Best practices

- Map filters to WHERE conditions. - Respect paging. - Limit returned fields. - Validate mandatory filters. - Avoid huge payloads.

Interview angle

Senior interviewers ask how to improve slow OData list APIs. Mention filter mapping, paging and database-side selection.