My journey creating a SAPUI5 mobile app at home [Part II]
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”):
Step 1: activate SAP Gateway
Start tcode SPRO and click the following IMG to activate SAP Gateway:
A popup will be shown where you have to click the “Activate” button.
Then click the “Manage SAP system aliases” as shown below:
Add the following entry and save:
Start tcode SICF and activate service Default_Host/sap/opu and all its subnodes:
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):
Right click the “Data Model” Node and select Import >> DDIC Structure
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:
Now double click on the node named “Entity Set”, and add the following entry:
Save and generate your service:
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:
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”:
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:
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):
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):
Now redefine method PARTNERSET_GET_ENTITY. As far as I’m concerned I used the same “KISS” principle as above:
Save and activate everything.
Step 4: activate and test your service
Go to the SPRO and select the following IMG:
Click the “Add service” button
Fill-in the required information to retrieve your service and select its technical name:
In the popup that is displayed you do not have to change any value. Just fill in a package name:
Come back to the previous screen: you should now see your “Z_Partner…” service. Click the “Call browser” button to test it:
If everything goes as expected, you should see something like this (meaning the service is up and running):
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:
But instead of the expected list, you’ll probably face an HTTP 500 error page:
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) :
I saved and activated my service again.
But the problem still remained… so I analyzed the service metadata via the following URL:
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:
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.