SAP Netweaver Gateway and SAP OData. Section 3. Options for Queries in OData Service URL

We built our first functional SAP OData Service in the last course. Just one method has to be re-defined in order to obtain POHeaderSet, making it the most basic form of OData. We will continue to work on the same ZGW_PO_SRV service from the previous post, adding features and complexity to delve deeper into OData implementation and present the underlying idea.

Every instructional series in Technicalgyanguru is made to start with basic concepts and straightforward examples before moving on to more realistic, complicated scenarios.It is strongly advised that you take a moment to stop here and quickly review our Introduction to OData and Part II (Create First OData Service) if you are new to OData.

A. READ Operation (GET_ENTITY method, for example)

For all external consumer applications that call the OData Service’s URI, the HTTP Method “GET” is used.

Thus far, we have discovered that the GW Client can access our URI “/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet” and that the browser can access the equivalent Browser URI. Only one method, POHEADERSET_GET_ENTITYSET, has been redefined. The PO Header data is returned as an internal table or array.However, let’s say the consumer system’s front-end application wishes to use our OData service to connect to SAP, supplying the PO number in order to retrieve only that PO number’s contents. To put it concisely, if the consumer application anticipates receiving a single row of data. How are they going to do that?

The consumer system’s URI ought to resemble the one below. They must succeed.

OData error

“Method ‘POHEADERSET_GET_ENTITY’ not implemented in data provider class” is the error message that appears.

What is meant by the error message?It suggests that the Data Provider Class (DPC) would call the POHEADERSET_GET_ENTITY method rather than the POHEADERSET_GET_ENTITYSET method if we only wanted one entry of data. The work area and the entity, as well as the array or internal table and the entity set, must be correlated.

Thus, let’s implement the “POHEADERSET_GET_ENTITY” method in t-code SEGW as suggested by the error notice. Select the GetEntity (Read) Operation with a right-click. Select Proceed to Workbench ABAP. An informational message would appear. Press “continue.”

SEGW

As stated in the previous post, choose the method “POHEADERSET_GET_ENTITY” and click the Redefine method icon.As an alternative, we have the ability to right-click on the method and select “Redefine.”This time, for once, I’ve gone the second route.

OData Data Provide Class

Take out the auto-generated code and replace it with code in method POHEADERSET_GET_ENTITY that looks like the sample below.

Data: ls_key_tab TYPE ekko-ebeln, lv_ebeln LINE OF it_key_tab.

  • IT_KEY_TAB has a value and key name.
    READ TABLE it_key_tab WITH KEY name = “Ebeln” INTO ls_key_tab. If sy-subrc EQ 0, then lv_ebeln = ls_key_tab-value. ENDIF. Case sensitive.
  • Choose one PO entry, and then enter it into the corresponding fields of er_entity where ebeln = lv_ebeln. SELECT SINGLE * FROM ekko.

“Ebeln” and “4500002012” would be the “name” and “value,” respectively, that the importing parameter IT_KEY_TAB.

Please view the output once again. proceeded to t-code /n/IWFND/GW_CLIENT or executed by using the browser’s URI. This time, the URI parameter passes through the PO’s details to be returned.

URI output

What have we discovered recently?To retrieve its details, we must supply the value of the KEY field in the URI.

Let’s switch to JSON as the format and observe how it appears. /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002012’) is the URI.?$format: json

JSON format appears more streamlined.After viewing the data sent by OData, some developers may experiment with the XML and JSON formats to create the solution.

start the update on September 27, 2019
How can I pass the Composite Primary Key in several fields?

The SAP file contains the following: ZWM_ODATA_SRV/ZZCALIBRATE_JSON_Set(CMSASSET=’CMS456788879′, LAST_CAL_DATE=’20160923′,CAL_DUE_DATE=’20230923′)

Your importing key table in the Get Methods will be populated with the primary key field name and value when you pass the entire set of primary keys, i.e., IT_KEY_TAB.

Since dates are defined as characters in the example above, the format is straight characters. On the other hand, you must pass the date field appropriately if you define it as dats.

odata primary key

IT_KEY_TAB won’t be filled in if you only pass the filter and not the entire set of main keys. IV_FILTER_STRING or IV_SEARCH_STRING need to be looked for.

ZWM_ODATA_SRV/ZZCALIBRATE_JSON_Set?&$filter=CMSASSET eq ‘CMS456788879’ /sap/opu/odata/sap/.

More links and navigation choices are added to the result set as we continue to improve the OData Model and Service.As we get to that tutorial stage, we will gradually see them.

B. VIEW a single Entity Type field or property (/Field1)

Sometimes the essential element can be found by pulling only one field from the structure. For instance, you need to identify the vendor who delivered the material if you know the PO number from someplace in your application.

It’s easy; just put the Entity Type field name at the URI, which is the property name.

get one field of the structure

In a similar vein, you know how to obtain the company code that was used to establish the PO.

/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002013’)/Bukrs would be the URI.

get one field of the structure

C. Determine how many entries there are in the system ($count).

We frequently need to know the number of entries that make up our query.To report or to prepare an action based on it, you might need to know the count. For whatever reason, in order to find the number count, you must append $count at the end of your URI.

URL: ZGW_PO_SRV/POHeaderSet/$count /sap/opu/odata/sap

OData in SAP

The Query Count is 10 since we have hard-coded UP TO 10 Rows in our selection statement. Take off the UP TO 10 from the code, then verify the number on your system.

Here’s a challenging query for you.What would the READ URI count be?

This URL points to ZGW_PO_SRV/POHeaderSet(‘4500002012’)/$count in SAP.

I mean, there has to be one? Ultimately, the Primary Key is being passed as the URI argument.

Free Tutorial on SAP Netweaver Gateway

D. Only extract a subset of the entity type’s fields ($select=Field1,Field2,Field3)

Three fields are required in your consuming application, however your OData Service has a data model with ten properties (fields). All of the fields may be pulled, and your application can then be filtered.However, astute coders would only extract what is required. Not any more, not any less.

For example, we require the Company Code, Created By, and PO number for our POHeaderSet entity. Wouldn’t /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet be our URI?$select=Bukrs, Erdan, Edeln.

$SELECT

Add &$format=json at the end to display the same result in JSON format.

POHeaderSet: /sap/opu/odata/sap/ZGW_PO_SRV?$select=Ebeln,Bukrs, and Ernam$format: json

OData free online training

Just so you know, if you see the question mark “?”, it indicates the start of a query option.

Some common query options that don’t require backend programming in an OData model or service are listed above. There are still several query choices that require coding. We’ll talk about them in a different post on another day.

E. Place a breakpoint and examine the methods that are called in debug mode.

I told you that we are in “Hub Deployment with Development in the Backend System” in Part II of our lesson. on our backend system, I developed the OData Model and Service, and now I’m testing the service on our front end system. Now let’s debug and look at which method (one entry, GetEntity) is called when reading.

External Debug

Since we would be contacting the service from a front-end system or a browser, place an External Breakpoint (not a session breakpoint) on the methods POHEADERSET_GET_ENTITY and POHEADERSET_GET_ENTITYSET.

Let’s navigate to the front end system’s t-code /n/IWFND/GW_CLIENT and use HTTP Method GET to execute “/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet.” Press the “Execute” button.

External Debugging in SEGW

Two methods contain breakpoints, but only the POHEADERSET_GET_ENTITY_SET function is called because our URI is given for the entire set—that is, it is a query operation.SAP Netweaver Gateway provides the built-in ability to determine the appropriate DPC technique. Isn’t that awesome?To retrieve the data, developers only need to build the appropriate logic. Netweaver Gateway is responsible for service and model integration.

The URI “/sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet(‘4500002013′)” should now be executed. to Read a single DataSet entry. When you execute, the debugger will halt at the breakpoint in the POHEADERSET_GET_ENTITY method.

CRUD

Even if it was too clear, we wanted to display it here in case any of you are still on an outdated SAP NetWeaver system. Those eager readers might benefit from our screenshots.

Too much POHeaderSet. Let’s also obtain some item info. Not everything is accurate, after all.

F. Clarify the POItem READ and QUERY Operations methods.

Return to the ZGW_PO->Service Implementation->POItemSet->GetEntity (Read) -> Right Click -> SEGW t-code. Proceed to Workbench ABAP.

SEGW

POITEMSET_GET_ENTITY’.

Redefine class methods

To fetch the data, remove the auto-generated commented code and write your own logic. You can look at the code below. The “field name” and “value” of the Key fields that are anticipated to be sent to the Method (often as the Parameters of the URI) are contained in the importing parameter IT_KEY_TAB.

Method GET_ENTITY
POITEMSET_GET_ENTITY METHOD.

ls_key_tab data SMGW_name_value_pair, TYPE /iwbep, lv_ebeln, TYPE ebeln, lv_ebelp Ebelp is the type.

  • Obtain the values of the important properties.
    READ TABLE it_key_tab WITH KEY name = “Ebeln” INTO ls_key_tab.
    lv_ebeln = ls_key_tab-value IF sy-subrc = 0. ENDIF.
  • Obtain the values of the important properties.
    READ TABLE it_key_tab WITH KEY name = “Ebelp” INTO ls_key_tab.
    lv_ebelp = ls_key_tab-value IF sy-subrc = 0. ENDIF.
  • Pick one row.
    IN THE CORRESPONDING FIELDS OF er_entity, SELECT SINGLE * FROM ekpo WHERE ebeln = lv_ebeln AND ebelp = lv_ebelp.

ENDMETHOD.

Redesign the “POITEMSET_GET_ENTITYSET” method in a similar manner to create your logic for retrieving the array of data, or internal table. You can look at the excerpt that follows.

GET_ENTITYSET
POITEMSET_GET_ENTITYSET METHOD.
DATA: lv_ebeln TYPE ebeln, ls_key_tab TYPE /iwbep/s_mgw_name_value_pair.
  • Obtain the values of the important properties.
    READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = ‘Ebeln’.
    lv_ebeln = ls_key_tab-value IF sy-subrc = 0. ENDIF.

IF lv_ebeln DOES NOT START OFF.

ELSE, SELECT * FROM ekpo INTO THE TABLE et_entityset’S CORRESPONDING FIELDS WHERE ebeln = lv_ebeln.

SELECT * INTO THE CORRESPONDING FIELDS OF TABLE et_entityset, UP TO 10 ROWS FROM ekpo.

ENDIF.

ENDMETHOD.

Note that all of the code snippets are merely examples. The needs of the application and the project requirements would determine the real logic.

All of the query operations that we completed for the POHeaderSet may now be completed on the POItemSet. We apologize for the brevity of the points below; we have previously supplied the HeaderSet specifics above.

i. ZGW_PO_SRV/POItemSet /sap/opu/odata/sap

URL and URI

Kindly pay attention to every href (link). They serve as guides for developers as they construct their queries for end-user apps.

ii. ZGW_PO_SRV/POItemSet?$format=json /sap/opu/odata/sap

JSON format

iii. ZGW_PO_SRV/POItemSet(Ebeln=’6000000251′,Ebelp=’00010′) in /sap/opu/odata/sap
The href from the URI result above is what we’ve utilized in this instance.

URL in OData

iv. ZGW_PO_SRV/POItemSet?$select=Ebeln,Ebelp,Werks /sap/opu/odata/sap
Take out just three Data Model fields.

select option in query

v. Where is ZGW_PO_SRV/POItemSet in SAP?$select=Werks,Ebelp, and Edeln$format: json

select and format

You should be aware by now that we can use the ampersand “&” to apply two sets of query settings if necessary. We are utilizing the “select&format” query option for this example.

vi. /ZGW_PO_SRV/POItemSet/$count /sap/opu/odata/sap

Odata URI and count

vi. /ZGW_PO_SRV/POItemSet/$count /sap/opu/odata/sap

Let’s end our day here. We discovered how to construct our own custom logic and redefine the methods in this session.We investigated and verified that the GET_ENTITYSET method is called for the QUERY (array) operation and the READ operation calls the GET_ENTITY method. We also became familiar with the frequently used query options.

Thus far, POHeader and POIteam are retrieved independently from our data, which is obtained by a GET HTTP method call. We will demonstrate HTTP methods such as POST, PUT, PATCH, DELETE, and others in later articles. Furthermore, since entity types must be related, we must extract item data from headers and vice versa in real projects. Therefore, a link must exist for the data to move between datasets. Through associations and navigations, we can accomplish that.

table for name value pairs
Debugging in SWGW

ii. What distinguishes a URI, URL, and URN?


I don’t know a lot about these phrases or how they operate. Furthermore, we ABAPers may not also require to be aware of the specifics. However, we ought to be somewhat familiar with these acronyms.

These are a few of a URI’s higher level elements.Protocol, Host, Port, Resource, and Query Parameters.

Various components of a URI

To put it simply, the URN is Mickey Mouse (Name) – a Name.
The address is Disney World, Florida; this is a locator.How do we get to the address?Travel by air, sea, land, or rail? You are also able to walk.The method of getting there is comparable to protocols such as HTTP(S), FTP, MAILTO, and so on.A Protocol must be specified in a URL; this is a must.
An identifier is a URI.

An identifier can be both a name and a locator. URN and URL can therefore be URI.

The Difference Between URLs and URIs

As was already established, the URL must specify how to get to the Locator. Is it accessible via the http protocol, ftp, mailto, etc.? It becomes a URL whenever the protocol is defined.

Thus, while all URLs are URIs, not all URIs are URLs.

When testing our OData Service in SAP t-code /IWFND/GW_CLIENT, we use the URI or URL?We should say URI in unison just to be safe. But take another look at the screen. Additionally, we are designating HTTP as the Protocol.Thus, you are also technically correct if you claim that we are using a URL.

Understand URI URL URN

Uniform Resource Identifiers (URIs) can be categorized as names (URNs), locators (URLs), or both. Whereas a person’s street address is similar to a Uniform Resource Locator (URL), a person’s name acts similarly to a URN.

I sincerely appreciate your time!

you may be interested in this blog here:-

Navigating SAP’s E070 Table in SAP: The Heartbeat of Transport Management

Launch Your Journey: Top Salesforce Courses for Beginners in 2024

Related Posts

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

The documents that are connected to the invoice in the Ariba Network system should be transferred to the VIM system via PI Integration as part of the Ariba Supplier Invoice…

Attachments for SAP XI/PI – ARIBA Invoices sent via PI to S/4HANA

Integration with SAP systems has never been more intriguing, especially with Ariba, Workday, Concur, Successfactors, Fieldglass, Hybris, and other satellite cloud solution vendors banging on doors every day. 🙂 I…

Leave a Reply

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

You Missed

SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

  • By Varad
  • November 8, 2024
  • 2 views
SAP XI/PI – Invoice Attachment Transfer from ARIBA to VIM

11 Steps to Include a New Field in an Already-Existing SAP LSMW Batch Input Recording

  • By Varad
  • November 6, 2024
  • 2 views

Part 23 of ABAP for SAP HANA. How Can AMDP Be Used to Access Database Schema Dynamically?

  • By Varad
  • November 4, 2024
  • 2 views

S/4HANA VDM 1 Employing CDS Virtual Data Model for Embedded Analytics

  • By Varad
  • November 1, 2024
  • 5 views