Skip to Content

Create your first service with SAP Gateway 2.0 SP4

Here is the second part of my journey (also known as “How-to create a simple mobile app for newbies”):

Part    I: Make sure your phone can access SAP Gateway

Part   II: Create your first service with SAP Gateway

Part  III: Develop your mobile app on Eclipse

Part IV: Test your mobile app on your phone

Part  V: Troubleshooting… and finally make it work!

Useful links:

New E2E Tutorial: Gain Hands-on Developer Experience with SAPUI5 and SAP NetWeaver Gateway

Gateway Service Builder (SEGW) with a focus on DDIC Importer

Step 1: activate SAP Gateway

Start tcode SPRO and click the following IMG to activate SAP Gateway:

/wp-content/uploads/2013/04/11_200634.png

A popup will be shown where you have to click the “Activate” button.

Then click the “Manage SAP system aliases” as shown below:

/wp-content/uploads/2013/04/12_200635.png

Add the following entry and save:

/wp-content/uploads/2013/04/13_200645.png

Start tcode SICF and activate service Default_Host/sap/opu and all its subnodes:

/wp-content/uploads/2013/04/26_200686.png

Step 2: create a new project

Start tcode SEGW and click the “New” button to create a new project which will hold our brand new service dedicated to read business partner data (I created everything as local objects because obviously on my own PC I do not intend to transport anything, but remember to enter a correct package on a “real” development system):

/wp-content/uploads/2013/04/10_200633.png

Right click the “Data Model” Node and select Import >> DDIC Structure

/wp-content/uploads/2013/04/14_200646.png

In the next screen, select structure BUT000, flag checkbox “As entity type” and press “Enter” (if you do not press “enter” at this point in time, the system will overwrite the name of the entity and give it the name of the structure). Now fill in the name “Partner” and select the components you want. On my system I marked every component with usage “Ignore” except the following ones:

/wp-content/uploads/2013/04/15_200654.png

Now double click on the node named “Entity Set”, and add the following entry:

/wp-content/uploads/2013/04/16_200655.png

Save and generate your service:

/wp-content/uploads/2013/04/16_200655.png

Step 2: fix any generation error

If you selected exactly the same components as I did, the system will probably throw the following error during generation:

/wp-content/uploads/2013/04/17_200658.png

In fact, the name of my entity was the same as one of its component… which seems to be forbidden. So let’s fix it by double clicking on the “Properties” subnode of our “Partner” entity, and rename component “Partner” to “PartnerNo”:

/wp-content/uploads/2013/04/18_200659.png

Save and activate again.

If other issues are thrown, try to fix them accordingly.

Step 3: add some code to retrieve partner data

Now expand “Service Implementation” Node, and right click the “GetEntitySet” node to select “Go to implementation” as shown below:

/wp-content/uploads/2013/04/18_200659.png

Ignore the popup that is telling you no implementation was found.

Redefine method PARTNERSET_GET_ENTITYSET (do not change it directly, otherwise your code will be lost with next generation of the service):

/wp-content/uploads/2013/04/19_200669.png

To keep things very simple, I decided to return every entry found in BUT000 table (in my case this is a sandbox system so this table contains only 2 entries):

/wp-content/uploads/2013/04/20_200670.png

Now redefine method PARTNERSET_GET_ENTITY. As far as I’m concerned I used the same “KISS” principle as above:

/wp-content/uploads/2013/04/21_200671.png

Save and activate everything.

Step 4: activate and test your service

Go to the SPRO and select the following IMG:

/wp-content/uploads/2013/04/22_200678.png

Click the “Add service” button

/wp-content/uploads/2013/04/23_200679.png

Fill-in the required information to retrieve your service and select its technical name:

/wp-content/uploads/2013/04/24_200680.png

In the popup that is displayed you do not have to change any value. Just fill in a package name:

/wp-content/uploads/2013/04/25_200684.png

Come back to the previous screen: you should now see your “Z_Partner…” service. Click the “Call browser” button to test it:

/wp-content/uploads/2013/04/26_200686.png

If everything goes as expected, you should see something like this (meaning the service is up and running):

/wp-content/uploads/2013/04/30_200691.png

Step 5: troubleshooting

OK nice, our service seems to work fine. But is it?

If you try to start the following URL, you should see a list of business partners:
http://<host>:<port>/sap/opu/odata/sap/Z_PARTNER_SRV_SRV/PartnerSet

But instead of the expected list, you’ll probably face an HTTP 500 error page:

/wp-content/uploads/2013/04/31_200697.png

In my case that was happening because I selected components CHDAT and CHTIM when I created the “Partner” entity… Unfortunately if those fields are left blank in the database, the service is throwing an exception at some point in the program. So I expected this to be a bug in the software and searched for OSS notes. [Update: thanks to Sebastien BENOIT who added a comment below, I now know that I should have marked the checkbox ‘nullable’ in the entity types properties to tell the system that this exception could be ignored].

However, as I couldn’t find any patch, I tried to simply remove those components from my service definition by clicking the delete button (tcode SEGW >> Data Model >> Entity Types >> Partner >> Properties) :

/wp-content/uploads/2013/04/33_200698.png

I saved and activated my service again.

But the problem still remained… so I analyzed the service metadata via the following URL:

http://<host>:<port>/sap/opu/odata/sap/Z_PARTNER_SRV_SRV/$metadata

I realized that even though those components were successfully removed via tcode SEGW, they were still there in the service definition… So I suspected another bug in the software. [Update: to regenerate your service after a change, it seems that you need first to delete the assignment to a system, then delete the service itself, only then will your changes be taken into account]

Again, I couldn’t find any notes, and I didn’t know how to change the service metadata manually, so instead of creating a new service from scratch again, I opened all business partners created in my system (they were only 2) to change of one their properties. After saving my modifications, fields CHDAT and CHTIM were no longer empty in the database and the service was working smoothly:

/wp-content/uploads/2013/04/34_200702.png

Conclusion

It took me approx. 4 hours to reach this point where I finally have a Gateway service up and running on my laptop… Let’s see if I can create a mobile app consuming that service now: go to Part III.

To report this post you need to login first.

10 Comments

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

    1. Nicolas Busson Post author

      Thanks Andy!

      I’ve just published Part III… hope it will be useful too even if I couldn’t test my application to be 100% sure it is correct.

      =)

      Cheers,

      Nicolas.

      (0) 
  1. Sebastien BENOIT

    Nice blog, for the issue with the date/time you just have to set your properties as “Nullable” in your entity types and then the exception is skipped.

    Also to regenerate your service after a change, delete first the assignment to a system, then delete the service itself, after that you can recreate it and the changes will be taken into account.

    (0) 
  2. Juergen Wahlmann

    Good report. I have an issue with the PartnerSet URI (http://<host&gt;:<port>/sap/opu/odata/sap/Z_PARTNER_SRV_SRV/PartnerSet), all I get is this:

    <error xmlns=”http://schemas.microsoft.com/ado/2007/08/dataservices/metadata>

    <code>005056A509B11ED199D88292AB9400FE</code>

    <message xml:lang=”en>

    In the context of Data Services an unknown internal server error occured

    </message>

    </error>

    I already added two Partners through the BP transaction.

    I’m totally new to ABAP development and still have to grasp on all the concepts behind it, so frankly I seldom know what to do after SAP GUI Login.

    Any idea what might cause this or where to look to find out?

    (0) 

Leave a Reply