SAP OData. - TECHNICAL GYAN GURU https://technicalgyanguru.com All SAP information on 1 place Fri, 20 Sep 2024 13:10:38 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.2 https://technicalgyanguru.com/wp-content/uploads/2024/04/cropped-cropped-technical--32x32.png SAP OData. - TECHNICAL GYAN GURU https://technicalgyanguru.com 32 32 SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation https://technicalgyanguru.com/sap-netweaver-gateway-and-sap-odata-section-iv-odata-service-association-and-navigation/?utm_source=rss&utm_medium=rss&utm_campaign=sap-netweaver-gateway-and-sap-odata-section-iv-odata-service-association-and-navigation https://technicalgyanguru.com/sap-netweaver-gateway-and-sap-odata-section-iv-odata-service-association-and-navigation/#respond Thu, 12 Sep 2024 06:28:00 +0000 https://technicalgyanguru.com/?p=5022 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…

The post SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation first appeared on TECHNICAL GYAN GURU.

]]>
 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?

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 

The post SAP Netweaver Gateway and SAP OData. Section IV. OData Service Association and Navigation first appeared on TECHNICAL GYAN GURU.

]]>
https://technicalgyanguru.com/sap-netweaver-gateway-and-sap-odata-section-iv-odata-service-association-and-navigation/feed/ 0 5022