SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation

 SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation

As of our third tutorial in the series on SAP Netweaver Gateway and OData, our data models are built to independently retrieve item data from EKPO and header data from EKKO.Currently, POHeaderSet and POItemSet are not communicating with one another. Real-world applications require us to modify item data in response to input from other entity types or the header, and vice versa.Therefore, there needs to be a link that connects them. The term “Associations” in SAP Netweaver Gateway language refers to the creation of Associations and Navigation Properties between the data model’s entity types.

Association explains how Entity Types are related to one another. A Navigation Property of the Entity Type is likewise generated with the creation of an Association.

Steps to implement Association in OData

Let’s establish a single Association and examine its appearance within the system. Locate the Association folder and perform a right-click to create your first association. Go to t-code SEGW, select Data Model.

Understanding Association vs AssociationSet vs Navigation Property

Between the Principal Entity and Dependent Entity, you must define the Key (Dependent Property, similar to the Foreign Key idea).

In the event that we require AssociationSet fo

What is Association Set?
What is OData?

The link between Entities, Navigation Property, Association, and AssociationSet is summarized in the figure below.

OData

Are definitions of Navigation Properties, Association, and Association Set still necessary?

\NavigationProperty Name=”HeadToItemNav” Relationship=”ZGW_PO_SRV” is the navigation property.Head to Item Ass.
Role From=”FromRole_HeadToItemAss”
/> ToRole=”ToRole_HeadToItemAss”

The code snippet and image above demonstrate that entity types have defined navigation properties. Through Relationship, it indicates the association kind. It also uses FromRole and ToRole to specify the flow direction. To put it briefly, Navigation Property facilitates movement between associations.

Link: – \Link Name=”HeadToItemAss” SAP:content-version=”1″

Link: - \Link Name="HeadToItemAss" <End Type="ZGW_PO_SRV.POHeader" Multiplicity="1" Role="FromRole_HeadToItemAss" /> SAP:content-version="1"
<End Type="ZGW_PO_SRV.POItem" Role="ToRole_HeadToItemAss" Multiplicity="*" />
- <PropertyRef Name="Ebeln" /> - <Principal Role="FromRole_HeadToItemAss"> - <ReferentialConstraint>
- <PropertyRef Name="Ebeln" /> <Dependent Role="ToRole_HeadToItemAss"> </Dependent> </ReferentialConstraint> </Association>

In a similar vein, the code and image above verify that Association gives the FromRole and ToRole their cardinality (multiplicity).It then has a Referential Constraints field that informs the Key field about the connection between the dependent and primary entities. The direction of the data flow is specified by the FromRole and ToRole. In conclusion, the relationship name between two entity types—one being the origin and the other the destination point—is called an association.

– “HeadToItemAssSet” is the AssociationSet Name.
Link=”ZGW_PO_SRV.HeadToItemAss” sap:creatable set to “false”
sap:updatable set to “false” SAP displays as “false” sap:content-version=”1″>

The association between entity sets is called an association set. This serves as the arrays’ (tables’) connection. The Association Set points to the Association, as the image above makes evident. To put it simply, AssociationSet possesses every attribute (cardinality, direction of data flow.

Navigation in SAPNWGW

Have you noticed that the metadata bears the Entity Type’s Navigation Property signature? For the definition of the Association and AssociationSet, see the response below as well.

SAP Netweaver Gateway

In our earlier articles, we have been retrieving one entry from the PO Header using the URI below. You would see there is an extra link if you were to run the same URI again.The Query Option with the Navigation Property we previously defined is present in this additional new link.

URI: (‘4500002012’)/sap/opu/odata/sap/ZGW_PO_SRV

Navigation Property
navigate

A new href link is displayed in the POHeaderSet result when the Query option is set to one primary key. It suggests that by adding the Navigation Property and selecting the Query option, we may go to the PO Item data.

You can see an alternate URL to obtain the specific PO item by expanding one of the results above. The POHeaderSet query’s result displays the alternate link to obtain a single PO item.Is that not helpful?

URI: (Ebeln=’4500001729′,Ebelp=’00010′)/sap/opu/odata/sap/ZGW_PO_SRV/POItemSet

SAP Netweaver Gateway and OData

Question: What distinguishes the two URIs below from one another?
SAP OPU OData SAP ZGW_PO_SRV POHeaderSet(‘4500001729’)/HeadToItemNav is the first URL.
URI 2: “4500001729” in /sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet?$expand=NavigateToItem

The first URI would simply retrieve item level records, whereas the second URI would retrieve item level entries along with header level data display. To put it briefly, the $expand query option shows the dependent entity type and expands the Header information with the assistance of the Navigation property.

We have currently observed data flow from Header to Item.Allow us to present an additional entity type that has the potential to be linked to the item. We will construct a navigation link between this new entity type and POItem Entity. This new entity type’s data would be created, updated, and erased.To put it succinctly, this new entity type and entity set would serve as our guinea pigs for our upcoming CRUD operations.

Let’s now build the new EntitySet, zekkoekpoSet, and Entity Type, zekkoekpo.Please verify that the entity type zekkoekpo was purposefully generated in lower case to demonstrate the case sensitivity of the entity names.You can review the problems that could occur because of the name case in later posts.

You ought to be aware of the following move by now. For this new e
ntity type, Zekkoekpo, we must put into practice the METHODs of the Operations that we wish to apply. All of our work up to this point has been in vain if you still do not know how to apply and redefine the methods.

SEGW

To examine how to implement and redefine the Data Provider Class Methods, please refer to the OData articles, Create Your first OData Service and URIs.

Two methods that contain 0 lines of code have been redefined. Let’s examine the behavior of our OData service. Place external breakpoints at both Entity Methods for testing purposes.

Remember to re-generate your OData Project after adding or removing any components, including Entity Types.

i.. Now let’s call the URI that is meant to invoke the GetEntitySet Method.

Access Point URL: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet

Breakpoints

Verify that the EntitySet Resource triggers the GetEntitySet Method.

ii. Let’s now call the URI that will initiate the GetEntity Method.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebelp=’10’,Ebeln=’4500003480′)
As anticipated, the GetEntity Method is called upon passing the Entity’s primary keys.

We discovered that our methods operate even in the absence of code, allowing us to construct our logic.To extract data from EKKO and EKPO and enter it into our Entity Type zekkoekpo, let’s write some basic code.

OData
zekkoekposet_get_entity is the method.

ls_key_tab data TYPE /ls_request_input_data, /iwbep/s_mgw_name_value_pair ZCL_zgw_purchase_mpc is the type.ts_ and ls_zekkoekpo Zekkoekpo type, lv_ebeln TYPE lv_ebelp, ebeln Ebelp is the type.
* Obtain the values of the relevant properties.
TABLE READ it_key_tab INTO ls_key_tab WITH KEY name = "Ebeln"
lv_ebeln = ls_key_tab-value IF sy-subrc = 0. ENDIF.
* Obtain the values of the relevant properties.
READ TABLE it_key_tab INTO ls_key_tab WITH KEY name = 'Ebelp'.
lv_ebelp = ls_key_tab-value IF sy-subrc = 0. ENDIF.

In the event where both lv_ebeln and lv_ebelp are not initial.
CHOOSE A SINGLE HOMANDTT HOEBELN i\ebelp HOBUKRS HOBSART i~matnr i~werks i~meins i~menge i~loekz
WHERE h~ebeln = lv_ebeln AND i~ebelp = lv_ebelp, FROM ( ekko AS h INNER JOIN ekpo AS i ON h~ebeln = i~ebeln ) INTO er_entity.

ENDIF.

ENDMETHOD.


Now let's test this URI using the just added code.

URI: /sap/opu/odata/sap/ZGW_PO_SRV/zekkoekpoSet(Ebelp=’10’,Ebeln=’4500003480′)

So far, everything is well. Our logic is used to fetch and show the data. Let’s now establish an association between the zekkoekpo Entity Types and the POItem.


Let’s examine the metadata once more.The new Association, AssociationSet, and Navigation Property would be displayed. URI: /sap/opu/odata/sap/ZGW_PO_SRV/$metadata
Now let’s examine the Navigation Property.

Let’s say you have no idea how to use the Navigation Link in the URI to frame the Query Option. Simply frame the URI for the one POItemSet that you are already familiar with. Look for the href in the XML.All the links to obtain the same value using different URIs are available there.

Let’s now call the new Navigation Query Option URI in addition to our URI: /sap/opu/odata/sap/ZGW_PO_SRV/POItemSet(Ebeln=’4500003480′,Ebelp=’10’)/ItemToCustomNav

The fundamentals of associations, association sets, and navigation properties are as follows.To distinguish between the Navigation and Association and Association Set, try to adhere to a naming convention.The majority of us attempt to name the Association and Navigation properties similarly. Therefore, we are unsure if they are Navigation Properties or Associations when we utilize them in URIs to frame the Query Option. It is easier to recognize what you are working with when you include an identifier, such as Nav, Ass, or AssSet.

More CRUD (Create, Read, Update, Delete) operations are what I wanted to demonstrate in this piece, but I believe that chapter deserves more attention than a passing mention.

We would also explore more operation methods, such as PUT, DELETE, and POST. We have just utilized the GET Operation thus far.Our Guinea Pig Entity Type zekkoekpo will be given data to populate and brought to life. Please continue to watch.

Part V: CRUD Functions in OData Services Up Next

What more would you like to add to this article? Have you encountered any difficulties comprehending SAP Netweaver Gateway or OData? Would you like to share any actual project specifications or solutions?Do not hesitate to speak up. Kindly share your opinions in the space provided for comments.

I sincerely appreciate your time.!

you may be interested in this blog here:-

SAP S/4HANA Cloud Public Edition 2408: A Comprehensive Guide to Product Implementation

Salesforce Course Professional System Skills 

Related Posts

SAP Netweaver Gateway and OData. Section VI. Commonly Asked Questions

The SAP Netweaver Gateway and OData Tutorials’ five earlier sections included practical exercises along with some technical insights.Those lessons would be helpful and sufficient for ABAPers, but in order to…

SAP Netweaver Gateway and OData. Section VII. Help with Debugging, Trace, Cache Cleaning, and F4

SAP Netweaver Gateway and OData. Section VII. Help with Debugging, Trace, Cache Cleaning, and F4, We anticipate that by this point, every reader is familiar with the process of creating…

Leave a Reply

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

You Missed

ABAP Programming Model for SAP Fiori – 11 – Enabling Draft Functionality for Transactional Apps

  • By Varad
  • September 17, 2024
  • 2 views
ABAP Programming Model for SAP Fiori – 11 – Enabling Draft Functionality for Transactional Apps

Just 4 Versions of the same program to understand OOPs ABAP

  • By Varad
  • September 16, 2024
  • 5 views

SAP Netweaver Gateway and OData SAP. Section I: A Brief History

  • By Varad
  • September 16, 2024
  • 3 views
SAP Netweaver Gateway and OData SAP. Section I: A Brief History

SAP Netweaver Gateway and OData. Section Two. Make your initial ODataService.

  • By Varad
  • September 14, 2024
  • 3 views

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

  • By Varad
  • September 13, 2024
  • 4 views

SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation

  • By Varad
  • September 12, 2024
  • 7 views