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

odata sap

SAP Netweaver Gateway, OData, and HTTPs in the Part I post, Introduction to SAP Netweaver Gateway and OData. We now have a decent understanding of the RESTful and STATEless concepts. In this post, we’ll create our first OData service in SAP through a hands-on exercise and experiment with the service’s various URIs.In order to update or extract data from SAP, the outside world (Client side) must use HTTP(s) to contact these URIs, which are the Server side of OData endpoints. These URIs must be consumed by SAPUI5 apps in order to connect to SAP and interact with its data. We will add our unique ABAP logic and redefine the conventional methods.

A. Describe the Data Model
Navigate to the SAP Gateway Service Builder (t-code SEGW). Recall it as SE38. Substitute 38 with GW for GateWay. For today’s topic, our helpful t-code is SEGW. Click the Create Icon, enter the project name, description, and package (local or otherwise), and save it.

What is OData?

Four folders are created when the project is established: Data Model, Runtime Artifacts, Service Implementation, and Service Maintenance. Please be aware that the Data Model contains three additional subfolders: Associations, Entity Sets, and Entity Types. By default, all of the folders are empty.

SAPUI5 Hello World

Our own structure, or a work area that can accommodate only one row, is the entity type. You’re right—an entity set is an internal table that can include several entities or rows. ABAPers, are you becoming more self-assured? These two terms are new to you.

Now let’s build our first structure—oops! work area; oops, the correct term in Gateway language is Entity Type.

What is Entity Type?

Select “Create” with a right-click on the Entity Types folder, give it a name of your choice, and don’t forget to check the “Create Related Entity Set” box. In our case, POHeaderSet is our internal table, and POHeader is the structure (work area)..

CRUD Operations

Verify if POHeaderSet Operations was automatically generated in the Service Implementation folder.These are ABAP methods that would be activated upon the calling of the pertinent endpoints.

The internal table and structure/work area fields now need to be defined.

What are data models?

Double After selecting the Properties folder and pressing the “create” icon, begin entering the field names, along with their type and length. We have included Ebeln and Bukrs to the sample. We need to construct our Entity Type, and so on.

Adding one field to the Entity Type at a time seems like too much work, doesn’t it? There must be an improved method. The actions listed above are merely to inform you that this is a thing.In practical tasks, you should apply the technique shown below. By right-clicking and selecting delete, you can remove the POHeader Entity Type and POHeaderSet Entity Set.

Let’s make them once more.

Restful

Select Import the DDIC Structure with a right-click on the Data Model folder. Give your Entity Type the name of the Entity Type and the ABAP structure whose fields you wish to import. Remember to choose the Entity Set checkbox, unless you are certain that an internal table is not required.

Click Next and select the fields you wish to add to your Entity Type from the EKKO (our example) structures.

/IWFND/GW_CLIENT

then,

/IWFND/MAINT_SERVICE

After , Complete

PUT POST

Let’s now import a second entity type, POItem, from EKPO using the previously described procedures.

What is CRUD?

It is evident from the aforementioned graphic that each type of entity will have a unique set of properties and a navigation properties folder. Each Service Implementation Entity Set will furthermore own unique Operations (such as Create, GetEntity, Update, and Delete).

We currently have an item/detail table and a header table. Let’s presume that there is no requirement for more entity types.

B. Put into Practice/Register the Service
Let’s go to create and register our service now.

How to Generate Service?

Select “Generate” and then “OK.” Either save it as local or provide the package and transport number. It should display the success message as follows.

Please take note that the external system must call the real service identified by the Technical Service Name. Along with the Base and Extended Class, two other classes are also generated: the Model Provider Class (MPC) and the Data Provider Class (DPC).

MPC and DPC

Both the Data Provider Class and the Model Provider Class are descended from /IWBEP/CL_MGW_ABS_DATA and /IWBEP/CL_MGW_ABS_MODEL, respectively. The relationship between the created classes and their superclasses (parents) is depicted in the graphic below.

/IWBEP/CL_MGW_ABS_DATA

FYI: The Gateway Service functions are provided by the Data Provider Class.The Gateway Service interface is defined by the Model Provider Class. There is no code that connects DPC and MPC. They use Configuration to communicate with one another.

C. Register the service with Gateway Hub and add it to the service catalog.
After the service has been implemented, it must now be added to the service catalog.

What is Embedded Deployment Statergy?

The majority of online tutorials demonstrate that the Register/Maintain buttons are active and that the System information are included in the Service Maintenance folder (as seen in the image above). You can tell if your system has “Embedded Deployment” if you notice an entry in the Service Maintenance folder.

Under the Embedded Deployment option, SAP Netweaver gateway components are installed as add-ons on the SAP backend system itself.The backend system is where the OData modeling and the external Service exposure are carried out.

An advantage of the strategy for embedded deployment is:
i. Saves money because no specialized Gateway Hub is required.
ii. In the event of two distinct systems (different front ends), it is quicker because of the runtime overhead caused by remote calls.

Thank you for your time. 

A. Describe the Data Model
Navigate to the SAP Gateway Service Builder (t-code SEGW). Recall it as SE38. Substitute 38 with GW for GateWay. For today’s topic, our helpful t-code is SEGW. Click the Create Icon, enter the project name, description, and package (local or otherwise), and save it.

What is OData?

Four folders are created when the project is established: Data Model, Runtime Artifacts, Service Implementation, and Service Maintenance. Please be aware that the Data Model contains three additional subfolders: Associations, Entity Sets, and Entity Types. By default, all of the folders are empty.

SAPUI5 Hello World

Let me briefly explain entity types and entity sets before you ask yourself that question.Ultimately, Technicalgyanguru is available to assist you in navigating the SAP Gateway learning curve with ease.

Our own structure, or a work area that can accommodate only one row, is the entity type. You’re right—an entity set is an internal table that can include several entities or rows.ABAPers, are you becoming more self-assured? These two terms are new to you.

Now let’s build our first structure—oops! work area; oops, the correct term in Gateway language is Entity Type.

What is Entity Type?

Select “Create” with a right-click on the Entity Types folder, give it a name of your choice, and don’t forget to check the “Create Related Entity Set” box. In our case, POHeaderSet is our internal table, and POHeader is the structure (work area)..

CRUD Operations

Verify if POHeaderSet Operations was automatically generated in the Service Implementation folder.These are ABAP methods that would be activated upon the calling of the pertinent endpoints.

The internal table and structure/work area fields now need to be defined.

What are data models?

Double After selecting the Properties folder and pressing the “create” icon, begin entering the field names, along with their type and length. We have included Ebeln and Bukrs to the sample. We need to construct our Entity Type, and so on.

Adding one field to the Entity Type at a time seems like too much work, doesn’t it? There must be an improved method. The actions listed above are merely to inform you that this is a thing.In practical tasks, you should apply the technique shown below. By right-clicking and selecting delete, you can remove the POHeader Entity Type and POHeaderSet Entity Set.

Let’s make them once more.

Restful

Select Import the DDIC Structure with a right-click on the Data Model folder. Give your Entity Type the name of the Entity Type and the ABAP structure whose fields you wish to import. Remember to choose the Entity Set checkbox, unless you are certain that an internal table is not required.

Click Next and select the fields you wish to add to your Entity Type from the EKKO (our example) structures.

/IWFND/GW_CLIENT

then,

/IWFND/MAINT_SERVICE

After , Complete

PUT POST

Let’s now import a second entity type, POItem, from EKPO using the previously described procedures.

What is CRUD?

It is evident from the aforementioned graphic that each type of entity will have a unique set of properties and a navigation properties folder. Each Service Implementation Entity Set will furthermore own unique Operations (such as Create, GetEntity, Update, and Delete).

We currently have an item/detail table and a header table. Let’s presume that there is no requirement for more entity types.

B. Put into Practice/Register the Service
Let’s go to create and register our service now.

How to Generate Service?

Select “Generate” and then “OK.” Either save it as local or provide the package and transport number. It should display the success message as follows.

Please take note that the external system must call the real service identified by the Technical Service Name. Along with the Base and Extended Class, two other classes are also generated: the Model Provider Class (MPC) and the Data Provider Class (DPC).

MPC and DPC

Both the Data Provider Class and the Model Provider Class are descended from /IWBEP/CL_MGW_ABS_DATA and /IWBEP/CL_MGW_ABS_MODEL, respectively. The relationship between the created classes and their superclasses (parents) is depicted in the graphic below.

/IWBEP/CL_MGW_ABS_DATA

FYI: The Gateway Service functions are provided by the Data Provider Class.The Gateway Service interface is defined by the Model Provider Class. There is no code that connects DPC and MPC. They use Configuration to communicate with one another.

C. Register the service with Gateway Hub and add it to the service catalog.
After the service has been implemented, it must now be added to the service catalog.

What is Embedded Deployment Statergy?

The majority of online tutorials demonstrate that the Register/Maintain buttons are active and that the System information are included in the Service Maintenance folder (as seen in the image above). You can tell if your system has “Embedded Deployment” if you notice an entry in the Service Maintenance folder.

Under the Embedded Deployment option, SAP Netweaver gateway components are installed as add-ons on the SAP backend system itself.The backend system is where the OData modeling and the external Service exposure are carried out.

An advantage of the strategy for embedded deployment is:
i. Saves money because no specialized Gateway Hub is required.
ii. In the event of two distinct systems (different front ends), it is quicker because of the runtime overhead caused by remote calls.

Gateway Hub

One benefit of integrating development and deployment of the hub in the backend system strategy is:
i. Greater security because there is only one point of access—the Gateway Hub—to the SAP Backend system for space.
ii. Direct access to Backend DDIC and business data for OData Model/Services is still available through the Gateway, despite its components being in separate SAP systems.
iii. The backend may still be running an older version of NW 7.3/7.4 while the gateway hub may be running an advanced, more recent version. The new release of the gateway would support SAPUI5.

A disadvantage is the increased expense and upkeep required, as well as the extra runtime brought on by remote calls.

Hub Deployment with Development in the Backend System

returning to our display.Since we are currently in our backend system, we are automatically unable to register and manage our service there. We must access our Gateway Hub, also known as our front end system, which houses our Netweaver Gateway.

Open the Front-end system (Gateway Hub) and enter the t-code /n/IWFND/MAINT_SERVICE. This T-code should be committed to memory or saved in your favorite list.It is required for all OData services.

/n/IWFND/MAINT_SERVICE

The Service Catalog still does not include our service. Our service is only accessible to the general public once we have added it to the Service catalog.

Add service to Catalog Service

Click the Add Service button, enter the external service name (ZGW_PO_SRV in our example) and the backend system alias. The service you built on the backend will be available to you. When you click on it, the Service (technical/external) name and the Model’s technical name (ZGW_PO_MDL) will appear. Then, you can choose to save. Return to the screen of the Service Catalog.

Locate your service and select it. It would appear in the lower right corner of the System Aliases pane. Let’s use the SAP Gateway Client to test it. Alternately, employ t-code /IWFND/GW_CLIENT (keep this t-code in mind also). You may test using the Call Browser option as well. We shall use SAP Gateway Client for the time being.

/IWFND/GW_CLIENT

oops! This error appears. With the notice “No authorization to access Service,” the status is 403, forbidding access. Let us investigate the Authorization Object problem in t-code SU53 and request access to this authorization from your SAP Security Team.

No authorization to access Service
Role needed to access Gateway Service

What was the source of the ZGW_PO_SRV_0001? The screen below could be useful.

Verify These as Well: SAP ABAP for HANA Courses

assuming that your permission is in effect. Using t-code /n/IWFND/GW_CLIENT or t-code /n/IWFND/MAINT_SERVICE, we may choose the service and click SAP Gateway Client. Press the Execute button. This instance, the success status code is 200.

SEGW

Many congratulations! Your first OData service has just been established, managed, and activated.

Our URI (/sap/opu/odata/sap/ZGW_PO_SRV/?$format=xml) has format XML like the image above. JSON (/sap/opu/odata/sap/ZGW_PO_SRV/?$format=json) will be used instead. They are informed that they have two Entity Sets in both XML and JSON.

What is metadata?

It displays the Names of the Entity Type (work area/structure). We have two in our OData (POHeader and POItem). Additionally, it displays the names of the entity sets (internal tables), which in our instance total two (POHeaderSet and POItemSet). The page would have a link at the bottom. This is the URL that launches your web service in a browser. Copy the link, then paste it into your browser (your SAP Front End login credentials are required).

How does OData service look in JSON format?

If all you had to use to access this SAP OData service as a non-SAP web developer was the service name and URI. You would like to use the structures in your non-SAP application, hence you would like to know the specifics. You would use?$format to verify the details as a first step.

Here are two well-liked methods for format verification.

  1. json in?$format
    ZGW_PO_SRV at http://txaixegd01.Technicalgyanguru.com:8000/sap/opu/odata/sap/?$format=json

2.?$format=xml
ZGW_PO_SRV at http://txaixegd01.Technicalgyanguru.com:8000/sap/opu/odata/sap/?$format=xml

XML and JSON

If an OData service fault occurs, how can ABAPers locate it?
You will receive the notice “Run transaction /IWFND/ERROR_LOG on SAP Gateway hub system” to identify the problem if you input the URI incorrectly or if it is not functioning.

An ABAPer’s friend in stormy weather would be T-code /n/IWFND/ERROR_LOG. Look for the URI in the message.

/iwfnd/error_log

Check the /n/IWFND/ERROR_LOG screen.

Now let us check if we can pull some data for POHeaderSet.

sap/opu/odata/sap/ZGW_PO_SRV/POHeaderSet in your SAP t-code /IWFND/GW_CLIENT.

Method not implemented
Redefine methods

We generated the Entity Types/Set in our backend system’s t-code SEGW, started the service, and registered it. MPC and DPC were produced. However, the DPC procedures remained unchanged.To extract data from the backend system and fill the Entity Set (internal table), we must build our ABAP code and logic. We can view the output of our OData service call once the entity set has been filled.

Let’s just redefine the procedure without writing any code. What output—or response—do you anticipate receiving from the OData service?

As we are improving the inherited class, we work in the extended class, not the Base class, when we go into change mode.

Redefine methods

Move the pointer to the method that needs to be redefined. Select “Re-define method” and press Enter. A little auto-generated code would appear.

Step by Step creation of OData services

In the following post, we will discover all of the importing and exporting parameters of the procedures. Save as is for the time being, then activate the class. Verify that the method “POHEADERSET_GET_ENTITYSET” is listed in the subdirectory “Redefinition.” This implies that we have effectively redefined our procedure.

Output of OData Service

Let’s now create a brief statement that will activate the method and retrieve 10 entries from the Purchase Order table EKKO.

POheaderset_get_entityset is the method.

SELECT * INTO THE CORRESPONDING FIELDS OF TABLE et_entityset, UP TO 10 ROWS FROM ekko.

ENDMETHOD.

Let’s now examine the output once again.

SEGW

There are ten entries displayed. Each row’s details are visible if you enlarge the entries.

Now,

json format output of OData

Let’s end our day here. We’ll put all the other strategies into practice and work with the URIs to change them to suit our needs in the following post. We would demonstrate how to construct Association and Navigation links (i.e., Navigation and Association between data models) to move, pull, or push data to and from various entities. The upcoming piece will have loads of code and be more interactive. So please continue to watch.

Extra Materials for This Article

i. Development in the Gateway Hub and Hub Deployment
For SAP Netweaver Gateway, there is a third Deployment Strategy in addition to the first two. The title is “Development and Hub Deployment in the Gateway Hub.”

Hub Deployment with Development in the Gateway Hub

Hub Deployment with Development in the Gateway Hub Drawbacks
i. There is no direct access to backend data dictionary objects. For the development of OData Services, the data source can only be the currently available RFCs and BAPIs.
iii. Higher maintenance requirements and expenses in comparison to an embedded deployment option utilizing a single system.

ii. How does the web browser determine the URL for the OData Service?


In order to test our OData Service in the SAP screen, we used t-code /IWFND/MAINT_SERVICE and SAP Gateway Client (or straight from t-code /IWFND/GW_CLIENT). It was also observed that the URL could be accessed with a web browser and tested similarly to the SAP Gateway Client.However, how is the URL for a web browser actually created?

Answer: The real URL

Now another question arises, how do we know the Hostname, Service (Port Number) and ICF path of our SAP system?
Ans: Go to t-code SICF. Execute it with default values. Menu Goto->Port Information. The pop-up window would have the Hostname and the Service name (Port Number) for the system.

How to get Hostname and port of SAP system

 sap->opu->odata->sap->zgw_po_srv.

ICF path of sap system

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?Would you kindly do

  • Related Posts

    Important T codes for FI GL AR AP

    Details of T Codes Accounting for Finances SPRO Put in the IMG OX02 Company Code to Create, Verify, and Delete OX03. Create Business Area Functional Areas for OKBD OB45 Establish…

    Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

    A few days ago, one of my SAP BI/BW friends requested a program that would accept any table as input and download it as a file to the local machine.…

    Leave a Reply

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

    You Missed

    Important T codes for FI GL AR AP

    • By Varad
    • December 21, 2024
    • 18 views
    Important T codes for FI GL AR AP

    Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

    • By Varad
    • December 20, 2024
    • 13 views
    Dynamically Download Data From Any SAP Table in ABAP-740 – Part 1

    Error While Setting Up Trusted System RFC

    • By Varad
    • December 19, 2024
    • 10 views
    Error While Setting Up Trusted System RFC

     Credit Management T codes in SAP

    • By Varad
    • December 18, 2024
    • 24 views
     Credit Management T codes in SAP

    Troubleshooting SAP BD22: Delete Change Pointer Not Picking Correct Processed Messages

    • By Varad
    • December 17, 2024
    • 56 views
    Troubleshooting SAP BD22: Delete Change Pointer Not Picking Correct Processed Messages

    Working with Shell Scripts in SAP ABAP Environment

    • By Varad
    • December 16, 2024
    • 34 views
    Working with Shell Scripts in SAP ABAP Environment