KEMBAR78
Create ODATA Service Using ABAP | PDF | Software Engineering | Information Technology Management
0% found this document useful (0 votes)
151 views13 pages

Create ODATA Service Using ABAP

Odata steps creation step by step.. How to debug and. And moc dpc classes

Uploaded by

Venkat Venky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
151 views13 pages

Create ODATA Service Using ABAP

Odata steps creation step by step.. How to debug and. And moc dpc classes

Uploaded by

Venkat Venky
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Contents
Create ODATA Service using ABAP Coding ............................................................................................... 1
1. Create Structures ............................................................................................................................. 1
2. Create the Model and Data Provider Classes .................................................................................... 2
3. Configuration to Maintain Models and Services ............................................................................... 5
Maintain Models.............................................................................................................................. 6
Maintain Services............................................................................................................................. 6
4. Expose the Gateway Service ............................................................................................................ 8
5. Check the Service’s Metadata .......................................................................................................... 9
6. Create the Associations and Navigations ........................................................................................ 10
Run the service again to check the Metadata for Navigation property and Associations ................. 13

Create ODATA Service using ABAP Coding

1. Create Structures
Tcode - SE11, Structure for PO Header

Email: ypkrbandi@gmail.com 1|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Structure for PO Items

2. Create the Model and Data Provider Classes


Model Provider Class
Tcode - SE24, Create the Model Provider class and add the class /IWBEP/CL_MGW_ABS_MODEL as a
super class

Redefine the method ‘Define’ and add the logic to create the entities with properties.

Email: ypkrbandi@gmail.com 2|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

METHOD define.

"/Declarations
DATA:
lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property TYPE REF TO /iwbep/if_mgw_odata_property.

*************************************************************************************
***********
* Create Entities and add properties
*************************************************************************************
***********

"Define Entity POHeader


lo_entity_type = model->create_entity_type('POHeader').

"Define property PurchaseOrder


lo_property = lo_entity_type->create_property ( iv_property_name = 'PurchaseOrder'
iv_abap_fieldname = 'EBELN').

"Define property as a key


lo_property->set_is_key( ).

"Define property CompanyCode


lo_property = lo_entity_type->create_property( iv_property_name = 'CompanyCode'
iv_abap_fieldname = 'BUKRS').

lo_property = lo_entity_type-> create_property( iv_property_name = 'DocCat'


iv_abap_fieldname = 'BSTYP').

lo_property = lo_entity_type-> create_property( iv_property_name = 'DocType'


iv_abap_fieldname = 'BSART').

lo_property = lo_entity_type->create_property( iv_property_name = 'Status'


iv_abap_fieldname = 'STATU').

lo_property = lo_entity_type->create_property( iv_property_name = 'Vendor'


iv_abap_fieldname = 'LIFNR').

lo_property = lo_entity_type->create_property( iv_property_name = 'PurOrg'


iv_abap_fieldname = 'EKORG').

lo_property = lo_entity_type->create_property( iv_property_name = 'PurGrp'


iv_abap_fieldname = 'EKGRP').

Email: ypkrbandi@gmail.com 3|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

"Add POHeader Structure to entity


lo_entity_type->bind_structure('ZST_PO_HEAD').

"Name the EntitySet POHeader.


lo_entity_type->create_entity_set('POHeaderSet').

*****************************************************************************
*****************

"Define Entity POItems


lo_entity_type = model->create_entity_type('POItems').

"Define property PurchaseOrder


lo_property = lo_entity_type-> create_property( iv_property_name = 'PurchaseOrder'
iv_abap_fieldname = 'EBELN').

"Define property as a key


lo_property->set_is_key( ).

"Define property POItem


lo_property = lo_entity_type-> create_property( iv_property_name = 'POItem'
iv_abap_fieldname = 'EBELP').

"Define property as a key


lo_property->set_is_key( ).

lo_property = lo_entity_type->create_property( iv_property_name = 'Material'


iv_abap_fieldname = 'MATNR').

lo_property = lo_entity_type->create_property( iv_property_name = 'Plant'


iv_abap_fieldname = 'WERKS').

lo_property = lo_entity_type->create_property( iv_property_name = 'StorLoc'


iv_abap_fieldname = 'LGORT').

lo_property = lo_entity_type->create_property( iv_property_name = 'Qty'


iv_abap_fieldname = 'MENGE').

lo_property = lo_entity_type->create_property( iv_property_name = 'UOM'


iv_abap_fieldname = 'MEINS').

lo_property = lo_entity_type->create_property( iv_property_name = 'ItemText'


iv_abap_fieldname = 'TXZ01').

Email: ypkrbandi@gmail.com 4|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

"Add POItems Structure to entity


lo_entity_type->bind_structure('ZST_PO_ITEMS').

"Name the EntitySet POItems.


lo_entity_type->create_entity_set('POItemsSet').

ENDMETHOD.

Data Provider Class


Create the Data Provider class and add the class /IWBEP/CL_MGW_ABS_DATA as a super class

3. Configuration to Maintain Models and Services


Tcode - SIMG, navigate to Maintain Models

Email: ypkrbandi@gmail.com 5|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Maintain Models
Tcode - /IWBEP/REG_MODEL to Maintain Model
Give the Technical Model Name and Model Version, click on create

Provide the Model Provider Class and description

Maintain Services
In SIMG, navigate to Maintain Services

Email: ypkrbandi@gmail.com 6|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Tcode - /IWBEP/REG_SERVICE to maintain the services


Give the Technical Service Name and Service Version, click on create

Provide the description, Data Provider Class and save it, and click on Assign Model

Give the Model Name and Model Version

Email: ypkrbandi@gmail.com 7|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

4. Expose the Gateway Service


Tcode - /IWFND/MAINT_SERVICE
Click on the Add Service

Give the system alias as local and Technical Service Name, select the service and click on add selected
services

Click on local object for package assignment and click on save

Email: ypkrbandi@gmail.com 8|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Navigate to back

5. Check the Service’s Metadata


Select the service and click on SAP Gateway Client

Tcode - /IWFND/GW_CLIENT, add the Metadata URI Option to check the metadata

Email: ypkrbandi@gmail.com 9|Page


Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

6. Create the Associations and Navigations


Add the below logic to create Associations and Navigation Properties

METHOD define.

"/Declarations
DATA:
lo_entity_type TYPE REF TO /iwbep/if_mgw_odata_entity_typ,
lo_property TYPE REF TO /iwbep/if_mgw_odata_property,
lo_annotation TYPE REF TO /iwbep/if_mgw_odata_annotation,
lo_association TYPE REF TO /iwbep/if_mgw_odata_assoc,
lo_ref_constraint TYPE REF TO /iwbep/if_mgw_odata_ref_constr,
lo_assoc_set TYPE REF TO /iwbep/if_mgw_odata_assoc_set,
lo_nav_property TYPE REF TO /iwbep/if_mgw_odata_nav_prop.

*************************************************************************************
***********
* Create Entities and add properties
*************************************************************************************
***********

"Define Entity POHeader


lo_entity_type = model->create_entity_type('POHeader').

"Define property PurchaseOrder


lo_property = lo_entity_type->create_property( iv_property_name = 'PurchaseOrder'
iv_abap_fieldname = 'EBELN').
"Define property as a key
lo_property->set_is_key( ).

"Define property CompanyCode


lo_property = lo_entity_type->create_property( iv_property_name = 'CompanyCode'
iv_abap_fieldname = 'BUKRS').

lo_property = lo_entity_type->create_property( iv_property_name = 'DocCat'


iv_abap_fieldname = 'BSTYP').

lo_property = lo_entity_type->create_property( iv_property_name = 'DocType'


iv_abap_fieldname = 'BSART').

lo_property = lo_entity_type->create_property( iv_property_name = 'Status'


iv_abap_fieldname = 'STATU').

lo_property = lo_entity_type->create_property( iv_property_name = 'Vendor'


iv_abap_fieldname = 'LIFNR').

Email: ypkrbandi@gmail.com 10 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

lo_property = lo_entity_type->create_property( iv_property_name = 'PurOrg'


iv_abap_fieldname = 'EKORG').

lo_property = lo_entity_type->create_property( iv_property_name = 'PurGrp'


iv_abap_fieldname = 'EKGRP').

"Add POHeader Structure to entity


lo_entity_type->bind_structure('ZST_PO_HEAD').

"Name the EntitySet POHeader.


lo_entity_type->create_entity_set('POHeaderSet').

*************************************************************************************
*********

"Define Entity POItems


lo_entity_type = model->create_entity_type('POItems').

"Define property PurchaseOrder


lo_property = lo_entity_type->create_property( iv_property_name = 'PurchaseOrder'
iv_abap_fieldname = 'EBELN').
"Define property as a key
lo_property->set_is_key( ).

"Define property POItem


lo_property = lo_entity_type->create_property( iv_property_name = 'POItem'
iv_abap_fieldname = 'EBELP').

"Define property as a key


lo_property->set_is_key( ).

lo_property = lo_entity_type->create_property( iv_property_name = 'Material'


iv_abap_fieldname = 'MATNR').

lo_property = lo_entity_type->create_property( iv_property_name = 'Plant'


iv_abap_fieldname = 'WERKS').

lo_property = lo_entity_type->create_property( iv_property_name = 'StorLoc'


iv_abap_fieldname = 'LGORT').

lo_property = lo_entity_type->create_property( iv_property_name = 'Qty'


iv_abap_fieldname = 'MENGE').

lo_property = lo_entity_type->create_property( iv_property_name = 'UOM'


iv_abap_fieldname = 'MEINS').

Email: ypkrbandi@gmail.com 11 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

lo_property = lo_entity_type->create_property( iv_property_name = 'ItemText'


iv_abap_fieldname = 'TXZ01').

"Add POItems Structure to entity


lo_entity_type->bind_structure('ZST_PO_ITEMS').

"Name the EntitySet POItems.


lo_entity_type->create_entity_set('POItemsSet').

*************************************************************************************
******************************
*************************************************************************************
**********************************************
* Create ASSOCIATIONS
*************************************************************************************
**********************************************

lo_association = model->create_association(
iv_association_name = 'POHeadToPOItems'
iv_left_type = 'POHeader'
iv_right_type = 'POItems'
iv_right_card = 'M'
iv_left_card = '1'
iv_def_assoc_set = abap_false ).
* Referential constraint for association - POHeadToPOItems
lo_ref_constraint = lo_association->create_ref_constraint( ).
lo_ref_constraint-
>add_property( iv_principal_property = 'PurchaseOrder' iv_dependent_property = 'PurchaseOrder' ).
lo_assoc_set = model->create_association_set( iv_association_set_name = 'POHeadToPOItemsSet'
iv_left_entity_set_name = 'POHeaderSet'
iv_right_entity_set_name = 'POItemsSet'
iv_association_name = 'POHeadToPOItems' ).

*************************************************************************************
**********************************************
* Create NAVIGATION PROPERTIES
*************************************************************************************
**********************************************
* Navigation Properties for entity - POHeader
lo_entity_type = model->get_entity_type( iv_entity_name = 'POHeader' ).
lo_nav_property = lo_entity_type-
>create_navigation_property( iv_property_name = 'POHeadToPOItems'
iv_abap_fieldname = 'POHEADTOPOITEMS'
iv_association_name = 'POHeadToPOItems' ).
ENDMETHOD.

Email: ypkrbandi@gmail.com 12 | P a g e
Prepared by Yogi Pavan - SAP ABAP Consultant Linkedin – Bandi Yogi Pavan Kumar Reddy

Run the service again to check the Metadata for Navigation property and Associations

Email: ypkrbandi@gmail.com 13 | P a g e

You might also like