Creating a Web Application Using the SAPUI5 Framework (6)

Continuing the series of short notes on the topic of SAPUI5.

See the post: Creating a Web Application Using the SAPUI5 Framework (1)
See the post: Creating a Web Application Using the SAPUI5 Framework (2)
See the post: Creating a Web Application Using the SAPUI5 Framework (3)
See the post: Creating a Web Application Using the SAPUI5 Framework (4)
See the post: Creating a Web Application Using the SAPUI5 Framework (5)

What will this post cover?

In this article, I’ll outline the sequence of steps required to create an OData service in an ABAP system, which can later be used in a SAPUI5 application to retrieve data from the same system.

Data Source

In the example I’m considering, the data source is a transparent table ZAPP_TABLE of the following type:

With the following content:

Creating the OData Service

Working with an OData service in an SAP system starts by launching transaction SEGW.

See: SAP Gateway Service Builder

While developing the data model for the new OData service, I will be working with entities that represent heterogeneous arrays of data.

My task will be to group and organize these logically, extract them into distinct entities, and assign them meaningful names. These names will be used for the Entity and Entity Set.

See: Entity Types
See: Entity Sets

The following video clip demonstrates the sequence of actions that lead to the creation of a new OData service.

See: SAP Gateway Cookbooks
See: Getting Started with the Service Builder
0:00
/1:17

The entity mentioned above was named "Person" in my case.

Preparing for Data Retrieval

When an OData service is created, a set of ABAP classes is available "out of the box."

See: ABAP Classes

To implement business logic, you must use the Data Provider Class with the suffix *DPC_EXT. From transaction SEGW, you can quickly navigate to the generated *DPC_EXT class by expanding the Runtime Artifacts node and selecting Go to ABAP Workbench from the context menu.

Override the methods *SET_GET_ENTITY and *SET_GET_ENTITYSET.

Source code of the PERSONSET_GET_ENTITYSET method:

DATA: ls_employee_entity TYPE zapp_table.
 
    SELECT * FROM zapp_table INTO TABLE @DATA(lt_table_empl).
    LOOP AT lt_table_empl ASSIGNING FIELD-SYMBOL(<fs_empl>).
      MOVE-CORRESPONDING <fs_empl> TO ls_employee_entity.
      INSERT ls_employee_entity INTO  TABLE et_entityset.
    ENDLOOP.

Source code of the PERSONSET_GET_ENTITY method:

DATA ls_employee_entity_key TYPE zcl_zdemo_app1_mpc=>ts_person.
 
    io_tech_request_context->get_converted_keys(
    IMPORTING
      es_key_values = ls_employee_entity_key
    ).
 
    SELECT * FROM zapp_table INTO TABLE @DATA(lt_employee) WHERE zz_number = @ls_employee_entity_key-zz_number.
 
    READ TABLE lt_employee  ASSIGNING FIELD-SYMBOL(<fs_empl>) INDEX 1.
    IF sy-subrc EQ 0.
      MOVE-CORRESPONDING <fs_empl> TO er_entity.
    ENDIF.
See: SAP Gateway Cookbooks
See: Code Snippets

Activate the changes you made.

Registering the Service

Register the service by going to the Service Maintenance node in transaction SEGW. The following video demonstrates the steps involved in registering the newly created OData service in the system.

See: Service Maintenance
0:00
/0:17

Initial Service Launch

I check whether the service is operational.

0:00
/0:11

What about the EntitySet?

See: List of HTTP status codes

200 – OK
Standard response for successful HTTP requests. The actual response depends on the request method used. For a GET request, the response contains an entity corresponding to the requested resource. For a POST request, it contains an entity describing or representing the result of the action.
0:00
/0:29

What if we select just one record?

0:00
/0:30

Which method of the *DPC_EXT class is triggered when the request is executed?

In the next video, I want to highlight which methods are called when making a request to retrieve the entire EntitySet, as well as when accessing it by a specific key.

0:00
/1:33