We are going to define a Gateway service in the Service Builder SEGW.
The first stage of implementing a service is to define the data model. For that, we will create custom z tables from scratch.
- Create 2 tables named ZStudent and ZSubjects as shown below.
- In transaction SEGW, create a new project.
- Give the project name ZStudents and a description.
- Right-click on Data Model node and choose Import->DDIC Structure. We are not creating entity types from scratch as the data tables are already created in the Data Dictionary in the previous step.
- Enter a Name, ABAP Structure, select Create Default Empty Set and click on next.
- Select all the fields to include in the service for the student and click on Next.
- Specify the field ID as key. Click on Finish.
- The result is as shown below. The Entity Type, Entity Set and the Service Implementation have been generated.
- Similarly, create the child Entity type and Entity Se. Import another DDIC object for Subjects.
- Click on the Generate Runtime Objects icon. The Service Builder will generate Model Provider classes and Data Provider classes.
- Open the Service Maintenance node and click on Register. Specify the local package, the External Service Name and click on Ok.
- Click on Maintain to open the transaction /IWFND/MAINT_SERVICE.
Select the service from the Service Catalog and in the ICF Nodes section, click on SAP Gateway Client to test the service.
The URI of the service is /sap/opu/odata/sap/ZSTUDENTS_SRV/. You can use various oData Query options such as $metadata, ?format=xml and sap-ds-debug=true.
- Click on Execute to test the service.
- Click on Add URI Option and choose $metadata and sap-ds-debug=true options.
- Execute to see the results below.
Do note that at this point we can only access the metadata of the service. The service will not return any data yet. If you try to get the data for an entity set, you will get an error as shown below.
Business data retrieval logic will be implemented in part 2.