14.01.2020 Views

ABAP_to_the_Future

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

13

SAPUI5

The purpose of the GET_ENTITY_SET method is to pass back a list of all the entities

(monsters) that have been requested by an incoming URL. As can be seen in Listing

13.2, first you start dealing with instructions that have been passed in to the

method (from the URL), such as the sort order (like the SORTCAT table in the ALV),

which is here stored in LT_SORTORDER, then the selection options, and finally

some more obscure things, like paging.

In regard to the selection options, they’re listed in the URL in the form of a string,

but the handler class in the SICF service no de transforms this into the form of a

table of selections ( IT_FILTER_SELECT_OPTIONS), which is passed into the GET_

ENTITY_SET method. Translate that selection table into the format that your monster

model class data retrieval method li kes, and then delegate getting the actual

data to the monster model method RETRIEVE_HEADERS_BY_ATTRIBUTE.

One you have the data, check if the incoming URL requested the data to be sorted

in a particular order. If so, then build up a dynamic table to sort the retrieved

data. Now check to see if the incoming URL specified that you only bring back

certain lines (e.g., the first 10 rows of the table).

Next, an export table is fi lled up with all the entities (monster headers) that you

want to send back to the caller. Right at the end is some code to enable testing

using Eclipse.

Warning: Houston, We Have a Problem

Often, you try and test your application an d get the screen but no data due to something

called CORS (Cross Origin Resource Sharing). Adding the preceding call to set

header solves the SAP Gateway (server) side of the equation. The local device (client)

settings needed will be discussed in Section 13.4.3.

METHOD monsterset_get_entityset.

* Extract any instructions as to how to sort the result list from

* the incoming request

DATA: lt_techorder TYPE /iwbep/t_mgw_tech_order,

lt_sortorder TYPE abap_sortorder_tab.

IF io_tech_request_context IS BOUND.

lt_techorder = io_tech_request_context->get_orderby( ).

ENDIF.

* See if we have any selection criteria passed in

* We adapt the ODATA structure to the BOPF selection structure

DATA: ls_filter_select_options

584

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!