You are on page 1of 24

Assignment 2

A to Z of
SAP OData Services
Assignment 2 –Create OData Service in SAP using SEGW

Disclaimer: This assignment is part of the A to Z of SAP OData Services Training


scheduled for 3rd September 2022 at 7:30 AM IST.
Whether you want to start your SAP OData learning or you want to dive deep into complex
SAP OData Development, this specially curated course will be your one stop. Enroll Today
to learn how to build optimized SAP OData Service from the Industry Expert.
Course Curriculum - https://tinyurl.com/au47uvzn
Day wise break up - https://tinyurl.com/5h6uzfnf
Enrollment Fee 124 USD - https://www.zapcademy.com/s/store/courses/description/A-to-Z-
of-SAP-OData-Services
Course Days – 3, 4, 10, 11, 17, 18, 24 Sept, 1, 2 & 8 Oct 2022 IST Dates
Time: 7:30 AM - 10:00 AM IST
Server Access till Oct 31 2022
Recordings will be provided after every live class. Participants will have life time access to
these recordings.

WhatsApp +1-251-727-9273 – for quick response

Assignment:
Create OData Service using Transaction Code SEGW.

1. The service is created to get Purchase Order Header and Item data from tables
EKKO and EKPO respectively.
2. The fields required from Header are as below

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page1


Assignment 2 –Create OData Service in SAP using SEGW

EBELN Purchasing Document Number


BUKRS Company Code
AEDAT Date on which the record was
created
ERNAM Name of Person who Created the
Object
LIFNR Vendor's account number
EKORG Purchasing organization
EKGRP Purchasing Group
WAERS Currency Key
3. The fields required from Item are as below
EBELN Purchasing Document Number
EBELP Item Number of Purchasing
Document
LOEKZ Deletion indicator in purchasing
document
TXZ01 Short Text
MATNR Material Number
WERKS Plant
LGORT Storage location
MENGE Purchase Order Quantity
MEINS Purchase Order Unit of Measure
BRTWR Gross order value in PO currency
4. Create Entity Types for header and item data using structure reference.
5. Generate Service.
6. Maintain Service.
7. Test Service and Service metadata.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page2


Assignment 2 –Create OData Service in SAP using SEGW

Instructions:
1. [TCODE]: Go to Transaction code with name TCODE
2. Replace 00 in the object names with unique 2-digit identifier
3. SAP GUI theme used here is ‘SAP Signature Theme’
Create a package: Z00 (replace 00 with unique number). Every time you need to
enter a package – use this package.

4. Create a TR in [SE01]
Every time you need to select a TR – use this TR. Above TR is only for example.
Please create your own TR. This step is not repeated at all places in the solution.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page3


Assignment 2 –Create OData Service in SAP using SEGW

Solution:
Step 1. [SEGW] Create a project.
Click on Create.

Fill the details as below and click okay.


Tip: Remember to replace 00 with the unique number you are using. For example, if you are
using unique number as 55, your project name will be Z55_PO_DATA and package would be
Z55.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page4


Assignment 2 –Create OData Service in SAP using SEGW

Created project will appear as below. Click Save to save the project.

Note: At all subsequent steps – use the same TR when a TR is asked for. This screenshot is not
repeated further.
Expand the node Data Model by clicking the highlighted triangle icon.

The 3 nodes i.e., Entity Types, Associations and Entity Sets will appear.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page5


Assignment 2 –Create OData Service in SAP using SEGW

Step 2. [SE11] Create structures for Purchase Order Header and Purchase Order Item data.

Enter Data type Z00_POHDR and click Create

Select Structure and click okay.

Add the fields in the structure as per requirement.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page6


Assignment 2 –Create OData Service in SAP using SEGW

Save and activate.


Note: Ignore warning for enhancement category for now. You can also set it to Can be enhanced
(Deep)

Structure should be in active state.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page7


Assignment 2 –Create OData Service in SAP using SEGW

Similarly, create structure for Item data – Z00_POITEM

As this structure contains Quantity (MENGE) and Amount (BRTWR) fields, providing
currency/quantity field reference currency/unit is mandatory.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page8


Assignment 2 –Create OData Service in SAP using SEGW

Step 3. [SEGW] Create Entity Types and Entity Sets.

Right click on Entity Type node and select Create.

Enter Entity Type Name as ‘POHeader’ and check the checkbox for Create Related Entity Set.
Entity Set Name will be populated automatically. Click okay.

Status bar will show below message.

The Entity Type POHeader will appear as below.

Now, add ABAP Structure as Z00_POHDR created in Step 2.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page9


Assignment 2 –Create OData Service in SAP using SEGW

Observe that Entity Set with name POHeaderSet is automatically created.

Right click on the POHeader node and select ImportProperties.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page10


Assignment 2 –Create OData Service in SAP using SEGW

Select all properties and click next.

Set up EBELN as key and click Finish.

Expand the POHeader node and double click on Properties to see all imported properties.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page11


Assignment 2 –Create OData Service in SAP using SEGW

Similarly, create Entity Type for Item Data. Right click on Entity Type node and select Create.

Enter entity name as POItem, check the checkbox to Create Related Entity Set.

Add ABAP structure name as Z00_POITEM.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page12


Assignment 2 –Create OData Service in SAP using SEGW

Right click on node POItem and select ImportProperties.

Select all properties and click Next.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page13


Assignment 2 –Create OData Service in SAP using SEGW

This time select PO Number i.e. EBELN and Item Number ilel EBELP both as keys.

Click Finish to get message that properties are added successfully. Ignore warnings if any at this
point.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page14


Assignment 2 –Create OData Service in SAP using SEGW

Step 4. [SEGW] Generate the OData Project.


Click on generate.

All the fields will be populated already. You may choose to remove extra Z in all class names.
i.e., instead of ZCL_Z00_ use ZCL_00_. It is fine if you don’t do this and keep the names
proposed.
Click okay.

Provide package Z00.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page15


Assignment 2 –Create OData Service in SAP using SEGW

Save in TR.

The project will be generated.

Note: Remember, ZCL_00_PO_DATA_DPC_EXT is the data provider class extension where actual
code will be implemented.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page16


Assignment 2 –Create OData Service in SAP using SEGW

The project tree should appear as below at this point.

The Runtime Artifact shows service name Z00_PO_DATA_SRV. This is the service name that will
be used to register / activate the service.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page17


Assignment 2 –Create OData Service in SAP using SEGW

Step 5. [/n/IWFND/MAINT_SERVICE] Maintain the service.


Note: The transaction code here is only /IWFND/MAINT_SERVICE. However, just using this does
not work as per the strange ways of SAP. So, use /n or /o before this t-code always.
Click on Add Service

Select System Alias as LOCAL & Technical Service Name from previous step i.e.,
Z00_PO_DATA_SRV and click on Get Services.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page18


Assignment 2 –Create OData Service in SAP using SEGW

Service will appear in the bottom section. Select the service and click on Add Selected Services.

Enter the package Z00 and click okay.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page19


Assignment 2 –Create OData Service in SAP using SEGW

Select TR. This popup up will appear 2 times.

You will get a popup saying service is created and metadata is loaded.

Now, go back and click on Filter.

Provide service name as Z00_* (You can also provide full name).

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page20


Assignment 2 –Create OData Service in SAP using SEGW

Your service will appear as below. Now, click on SAP Gateway Client.

SAP Gateway Client is the tool to test OData Services.

Since we have generated, registered and activated the service – we should be able to test the
service and the metadata.
Service URI: /sap/opu/odata/sap/Z00_PO_DATA_SRV/?$format=xml
Click Execute.

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page21


Assignment 2 –Create OData Service in SAP using SEGW

Response code is 200 which means service call is successful.

Similarly, test metadata with URL: /sap/opu/odata/sap/Z00_PO_DATA_SRV/$metadata

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page22


Assignment 2 –Create OData Service in SAP using SEGW

Tip: To add metadata option, below button can be used.

Service Creation is now complete. Next step to implement the service operations continues in
next assignment.

If you want to Master SAP OData Services Building, then ENROLL Today.
Course Curriculum - https://tinyurl.com/au47uvzn
Day wise break up - https://tinyurl.com/5h6uzfnf
Enrollment Fee 124 USD - https://www.zapcademy.com/s/store/courses/description/A-to-Z-
of-SAP-OData-Services
Course Days – 3, 4, 10, 11, 17, 18, 24 Sept, 1, 2 & 8 Oct 2022 IST Dates
Time: 7:30 AM - 10:00 AM IST
Server Access till Oct 31 2022

WhatsApp +1-251-727-9273 – for quick response


email: mail@zapyard.com

WhatsApp +1-251-727-9273 mail@ZAPYard.com Page23

You might also like