This blog post is a continuation of a series of tree posts, about how to create and consume gateway service, the first one and three can be found here:

How to create and consume a gateway service via SAPUI5 – Part 1


How to create and consume gateway service via SAPUI5 – Part 3


All the prerequisites are listed in previews article, please read the first part before you continue.

In this second part, we will see how to create an OData service that will be used in the SAPUI5 application.

Let´s start…

Creating OData Service

To create the Odata service we need to access the SEGW transaction, and proceed with a few steps:

  • Access SEGW transaction, you will enter Sap Netweaver Gateway Service Builder.
  • Start by creating a new project, to do this, click in “New Project”.

/wp-content/uploads/2016/03/image1_919554.jpg

  • In “Create Project” window, enter the project name “ZHelloOData”, description “Hello Odata Service” and inform your Z package under Package.

/wp-content/uploads/2016/03/image2_919555.jpg

  • After creating the project, your project structure will look like the one in the image below.

/wp-content/uploads/2016/03/image3_919574.jpg

  • Next you need to create a service based in the SCARR table. To do this, right click on “Data Model” folder, choose Import->DDIC Structure.

/wp-content/uploads/2016/03/image4_919575.jpg

  • A wizard window will be displayed, in the first step, enter the Name “SCARR” and in ABAP Structure, enter SCARR again. Check if “Create Default Entity Set” is marked. When done, click on the Next button.

/wp-content/uploads/2016/03/image5_919576.jpg

  • In the next step, mark all of the checkboxes and then click in Next again.

/wp-content/uploads/2016/03/image6_919577.jpg

  • In the last step, choose the key fields, according to the image below, and then click in Finish.

/wp-content/uploads/2016/03/image7_919578.jpg

  • After these tree steps, the project will look like that:

/wp-content/uploads/2016/03/image8_919579.jpg

  • Now let´s generate the Runtime objects. Click in the button marked below.

/wp-content/uploads/2016/03/image9_919580.jpg

  • The popup window for choosing the appropriate request will be displayed, select the same request which we used in the first tutorial, or create a new one if you prefer.

/wp-content/uploads/2016/03/image10_919581.jpg

  • In the next step, it will be displayed the “Model and Service Definition” window, keep all of the fields as it is suggested and confirm.

/wp-content/uploads/2016/03/image11_919582.jpg

  • Then, choose your Z package and a request again.

/wp-content/uploads/2016/03/image12_919595.jpg

  • At the end of these steps, the “Runtimes Artifacts” will be generated. See the image below and confirm if everything is OK.

/wp-content/uploads/2016/03/image13_919596.jpg

Registering and testing the Service

Now we are going to register the service and make a first test. Please proceed with the following steps:

  • Double click on the “Service Maintenance” node, and then click “Register”. See the image below.

/wp-content/uploads/2016/03/image14_919597.jpg

  • In the “Add Service” window, we have to keep all the values as suggested, entering only the package name. Then click “Continue”. Check the image below.

/wp-content/uploads/2016/03/image15_919598.jpg

  • Next inform your previously created request.
  • If everything is OK you will have a green light in “Registration Status”.

/wp-content/uploads/2016/03/image16_919599.jpg

  • With everything OK, you can go to “Gateway Client” and test the recently created service. Click in “Gateway Client”.

/wp-content/uploads/2016/03/image17_919600.jpg

  • A new window will be displayed. To test, click on the “Execute” button and then check if the HTTP response has the code 200. Confirm the link to your service, you will need this link in the third part of this article. This link is used to access our recently created service.
  • You can also check the results in your browser, entering the URL marked below.

/wp-content/uploads/2016/03/image18_919795.jpg

Developing the Service Implementation

  • Now we are going to develop the service to query the results of the SCARR table. Let’s return to Sap Netweaver Service Builder (SEGW).
  • First, open the “Service Implementation” tree structure. Then, right click on “GetEntitySet (Query)” and choose “Go to ABAP Workbench”. See the example in the image below.

/wp-content/uploads/2016/03/image19_919605.jpg

  • In the popup click in Yes, then confirm the creation of the implementation.

/wp-content/uploads/2016/03/image20_919606.jpg

  • The ABAP workbench will be displayed, then open the SCARRSET_GET_ENTITYSET method. Then, confirm the creation of the method.

/wp-content/uploads/2016/03/image21_919610.jpg

/wp-content/uploads/2016/03/image22_919611.jpg

  • Now let´s implement the code to select data from SCARR table. See the image below, and activate the objects.

/wp-content/uploads/2016/03/image23_919613.jpg

  • For a final test, open the Gateway Client again, click in execute and check the name of the collection created. You can also do this, informing the URL in you browser.

/wp-content/uploads/2016/03/image24_919814.jpg

  • With the collection name, we need to change the URL to test if the results will be displayed.

/wp-content/uploads/2016/03/image25_919815.jpg

Well, we finish the second part here, in the last part of this series we are going to consume the service created in this article in a SAPUI5 application.

See you in the next post!

Regards, Balbino.

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply