In Part 3, different artifacts in OData service are covered. In this part, we will check the implementation of the OData service and its Get Operation. As we know all the logic parts of the OData service are to be implemented in the DPC_EXT class. In the DPC_EXT class, there are a couple of methods created while generating the Project. Let’s check methods that are created for entity set.

To navigate to the DPC_EXT class there are two ways one is from Tcode SE24 or SE80 and the second way is directly from the project itself as shown below

OData service Implementation

In the class, you can see there a couple of methods, we will cover most of them in the due course. But for now, focus on the methods which are associated with the entity set.

Methods associated with entity set
There are 5 methods associated with each entity set.

As a whole, there are 5 operations(CRUD-Q) in OData that are as shown below and mapped to HTTP methods. But for now, we will check the GET Operation which is also known as single read operation.

Read Operation

Read operation is used for Reading a single record. To implement the same we need to redefine the method called ORDERHEADERSET_GET_ENTITY.

Redefine get_entity method

After redefining the method- the following code implemented

  METHOD orderrheaderset_get_entity.
    DATA:lv_vbeln TYPE vbak-vbeln.
    "Get the Key value
    lv_vbeln = VALUE #( it_key_tab[ name = 'Vbeln' ]-value OPTIONAL ). "New syntax
    lv_vbeln = |{ lv_vbeln ALPHA = IN }|.

***    If you are using Old syntax Then-Begin
*    READ TABLE it_key_tab INTO DATA(ls_key_tab) WITH KEY name = 'Vbeln'.
*    IF sy-subrc EQ 0.
*      lv_vbeln = ls_key_tab-value.
*      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
*        EXPORTING
*          input  = lv_vbeln
*        IMPORTING
*          output = lv_vbeln.
*    ENDIF.
****  End

    "Fetch the record from the table
    SELECT SINGLE vbeln
                  erdat
                  erzet
                  ernam
                  audat
                  netwr
                  waerk
                  vkorg
                  vtweg FROM vbak
      INTO CORRESPONDING FIELDS OF er_entity
      WHERE vbeln = lv_vbeln.
  ENDMETHOD.

If you check in the above code, I have highlighted it_key_tab and er_entity. These two parameters play a major role.

  • it_key_tab = importing parameter which holds the KEY fields in the form of name-value pair which are passed from the URI. Note that the name should be same as the entity type property name (case sensitive)
  • er_entity = exporting parameter of the method. Which to be filled by this method and sends back as a response.

If you are confused with the new syntax used in the above code then please read the blogs

Read Statement in ABAP 7.4 – Pretty Printer SAP

Adding/Removing Leading Zero – Pretty Printer SAP

Ok, now let’s start testing the implementation. To test the service implementation, we need to register the service. So that it will expose to the outer world. Below are the steps

Register service
Click on the register button to register the service as this embedded type deployment so it will open in the same system else in case of central hub deployment option upon clicking register button it will take u to the frontend system. This same Registration process can be performed in the /IWFND/MAINT_SERVICE Tcode
Register OData service
as you can during service registration the service name and the model name are used
SAP Gateway client
once the service is registered you can test the service in the Tcode /IWFND/GW_CLIENT

Now it will open up the tcode /IWFND/GW_CLIENT

/IWFND/GW_CLIENT

URI for GET/Single read operation would in the format of

/sap/opu/odata/SAP/<Service name>/<Entity Set>(<key name>='<key value>’)

in our case its /sap/opu/odata/SAP/ZXYZ_SAMPLE_ODATA_SRV/OrderrHeaderSet(Vbeln=’18581′)

SAP Gateway client /iwfnd/gw_client

Note: To debug the code, you set the external break-point in the method. In the case of central hub scenario then there must a Trusted RFC between the frontend and backend system. Based on the RFC configuration external breakpoint can set for RFC user/for testing user. (we will check the scenario of central hub system in due course)

The most common error, we used to get when er_entity that is the response is sent as empty

Response window in gateway

Also, sometimes you may have to change logic but it is not reflecting or breakpoints are not set for debugging. In that case, you may try to close the transaction & back again or clear the cache

clear cache in sap gateway

Additional

In the GET_ENTITY method, there is one parameter called io_tech_request_context which holds information about the request and it is a type reference of below interface having following methods

io_tech_request_context type
The most commonly used method is get_converted_key() which returns a work area of type entity type with applied conversion exit

Let’s check an example

    DATA(lt_tab) = io_tech_request_context->get_keys( ). "Return key value pair

    DATA:ls_entity LIKE er_entity.
    io_tech_request_context->get_converted_keys(
      IMPORTING
        es_key_values = ls_entity  "Applied Conversion like leading zero
    ).
debugging result
result
in the URI even if pass Vbeln=’32316‘ but the method get_converted_keys will return value with leading zero of vbeln

Next Part: Query Operation(GET_ENTITYSET) in OData – Part 5-ABAP Skill

Previous Part:OData Service Creation In SAP – Part 3 – ABAP Skill


2 Comments

Query Operation(GET_ENTITYSET) in OData – Part 5-ABAP Skill · July 14, 2021 at 7:00 am

[…] entity set, there is a method called <entityset name>_GET_ENTITYSET . in the previous part (part 4), we covered the GET_ENTITY method which is returning response as single records(in ABAP word it is […]

OData Service Creation In SAP – Part 3 - ABAP Skill · July 18, 2021 at 5:37 am

[…] Apart from these four classes, there is a technical service name(ending with SRV) and model(MDL) name generated which is used for service registration purposes.We will discuss more details about artifacts in due course. Next Part:Get Operation in OData Service – Part 4 – ABAP Skill […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *