Skip to Content
Author's profile photo Aisurya Puhan

XSOdata with Navigation Property

A sample example for XSOdata  with Navigation Property


Scenario of Purchase Order(PO) Header and Item: In a single service we can navigate to Item level from Header to Item with Association .

Lets start with very basic example of VBAK (PO Header), VBAP(PO Item).


Example Code in a .XSOdata file


service namespace "workshop.aisurya.XSOdata" {
"<YourSchema>"."VBAK" as "POHeader" with ("MANDT","VBELN","ERDAT") navigates ("ToPoItemAssctn" as "ItemRef");
"<YourSchema>"."VBAP" as "POItems" with ("MANDT","VBELN","POSNR","MATNR","ARKTX");
association "ToPoItemAssctn" principal "POHeader"("VBELN")
multiplicity "1" dependent "POItems"("VBELN") multiplicity "*";
}

Below Image for reference

/wp-content/uploads/2016/02/1_895801.png

Activate the changes and Run As XS Service.

Lets check the Metadata of service.

https://<Host:Port>/workshop/aisurya/XSOdata/po.xsodata/$metadata

/wp-content/uploads/2016/02/2_895817.png

As highlighted in the image(ItemRef) is a navigation property from Header to Item level.

Lets test the service only for 2 records by providing query option as (top=2).

https://<Host:Port>/workshop/aisurya/XSOdata/po.xsodata/POHeader?$top=2&$format=json



/wp-content/uploads/2016/02/3_895819.png

Here ItemRef is the navigation property of corresponding PO Items with URI. We can explicitly open in new tab and get the result also .

Now lets check Expand option for Showing Header and Corresponding Items.

$Expand Feature to fetch Corresponding Item along with Header.

https://<Host:Port>/workshop/aisurya/XSOdata/po.xsodata/POHeader?$top=2&$format=json&$expand=ItemRef

POHeader (MANDT=’800′, VBELN=’0000004970′)


/wp-content/uploads/2016/02/4_895828.png



Now this service can be consumed in different UI ‘s  depending upon the requirement.


Assigned tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      can you please explain how to consume this URI into the UI elements like tables ? for eg : i have a deader table and when i click i want another table to fill with item details.

       

      Author's profile photo Aisurya Puhan
      Aisurya Puhan
      Blog Post Author

      This might help

      https://archive.sap.com/discussions/thread/3928243

      Author's profile photo Luis Benavides
      Luis Benavides

      Hi Aishwarya,

      Many thanks for your post, it's make me helped to understand the syntax of OSDL of the navigation property (association).

      Well done 🙂

      Author's profile photo Aisurya Puhan
      Aisurya Puhan
      Blog Post Author

      You are welcome.

      Author's profile photo Divi Srilaxmi
      Divi Srilaxmi

      Hi Aisurya,

      Thank you for the information!

       

      Could you please tell me how we can add conditions in the code? Ex. If I need VBTYP = 'C' records, In this case how can I add my condition?

      Author's profile photo Aisurya Puhan
      Aisurya Puhan
      Blog Post Author

      Hi Divi,

       

      You have to pass the filter parameters like

      for eg :  POHeader (MANDT=’800′, VBELN=’0000004970′)

       

      Thanks,

      Aisurya

      Author's profile photo Harshil Patel
      Harshil Patel

      Thanks  Aisurya Puhan ,

      for this wonderful Blog,

      but some of the fields in this code i did not understood.

      could you please help me out.

      with ("MANDT","VBELN","ERDAT") navigates ("ToPoItemAssctn" as "ItemRef");

      this "MANDT","VBELN" are all column fields.

      and what is inside this navigates?

      if anyone knows please reply ASAP.

       

      Author's profile photo Aisurya Puhan
      Aisurya Puhan
      Blog Post Author

      Hi Harish,

      Yes these  (“MANDT”,”VBELN” ,"ERDAT" ) are the columns from Header (POHeader) as a key and it navigates to the association. And the association is nothing but the  Items (POItems).

      Aisurya