Pushing Notifications Made Easy!!! : How to Subscribe?
The ‘What’ part – “Notifications”, you must be familiar with this word if you have used iPhones/BlackBerry or any other smartphones and even Facebook!!! Excited to see the notifications from your friends and family!!! How cool would it be to receive notifications regarding SAP Business Processes in your daily office work? Managers, wouldn’t it be cool to get an employee’s leave request on your mobile instead of getting it in the mail client in your laptop? It must be great to do some office activities from the mobile while having no access to your machine, e.g. in the departmental store, in the shopping mall, etc.
So the next question, how do we do it?? You know, it’s really easy and cool!!! Just follow a few steps mentioned below and you’ll be done in no time. Well, that’s not absolutely true!!! It’ll take some time, but not much. 🙂
Before we start, let’s have a quick introduction of the SAP NetWeaver Gateway Subscription & Notification framework.
Basic fact —– Subscribe to get Notified !!!
It’s important to understand that Subscription & Notification are two different functions in Gateway. The below picture shows the difference in a nutshell.
It exactly works like subscribing for a newsletter. Once you subscribe for it, you receive it. Similarly, in case of a Gateway service, you have to subscribe to a Collection in order to get notified about the Business Process. But that’s not the whole story. We’ll see what else needs to be done in the steps to come. Stay tuned!!!
Sample Use Case —— SAP User Administration
Let’s understand the use case in brief. In an organization, an Admin user wants to keep track of all the new SAP usernames being created/changed/deleted in a system. He doesn’t want to login to the system everyday and check for any new users. Instead, he wants to get notified the moment a user is created/changed/deleted.
He thinks it would be great for him to get these alerts in his iPhone. So, he asks for an application which will connect to the Gateway system and get this information to his mobile device. Now, let’s see what needs to be done in the Gateway system in order to get this working for the Admin.
The development activities for this scenario have been split into two steps:
- Creating a Subscription-Enabled OData Service (Steps covered in this blog)
- Enabling Notification Push for the subscribed users (Watch out for this in the next blog)
Creating a Subscription-Enabled OData Service
Step 1 — Creating Model & Data Provider classes
Let’s create a new OData Service for the above mentioned business scenario, which will be enabled for subscription.
- Create a class Z_CL_PUSHDEMO_MPC by inheriting from /IWBEP/CL_MGW_PUSH_ABS_MODEL.
- Redefine the method DEFINE in this class and create your OData service interface. The sample code can be found here.
- Create another class Z_CL_PUSHDEMO_DPC by inheriting from /IWBEP/CL_MGW_PUSH_ABS_DATA.
- Redefine the method CHECK_SUBSCRIPTION_AUTHORITY and write some code to check if the requesting user is authorized to subscribe to this service. You can find some sample code here. Please note that if you get any authorization error later while running a query on UserCollection, comment this code.
- Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITYSET and write some code to get a list of users. The sample code can be found here.
- Redefine the method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~GET_ENTITY and write some code to get details for a user. The sample code can be found here.
Step 2 — Configuring the OData Service
Once the above steps are completed, maintain the model & service group in the IMG path shown below:
In the Gateway Hub system, activate the above service as shown below.
Activate the service ZPUSHDEMOSRV by clicking on it.
The OData service is now ready to be used for Query & Read operations. 🙂 The table below gives the URLs for various operations supported.
The service document (see below) shows that the ‘UserCollection’ is made subscribable and also you can see two new entities added to the service document (SubscriptionCollection and NotificationCollection).
Now, once you are done with the above steps, you can start with subscribing for a Collection. Nothing much to do here, just a regular HTTP POST as shown below. The sample request body can be found here.
Please note that we will be using a HTTP listener application for receiving the notifications. Hence, the deliveryAddress used while subscribing should be the IP address from the application.
Once you have fired the call, the response is a subscription for this service as shown below.
With this, you have become one of the subscribers for the ‘ZPUSHDEMOSRV‘ SAP NetWeaver Gateway service. Let’s see what else needs to be done for receiving notifications in the next blog – Create a Notification Push Application!
At step, Activate and maintain services->Add services , in field 'system alias' i am passing Alias name of the server(back-end server) on which Data model and service have been created.
After activating the service when i press on call browser,
i get following error in the browser:
<error><code>CX_XSLT_RUNTIME_ERROR/EE1D984A671BED4AAD4D1BD10D509C75</code><message xml:lang="en">No valid source context supplied</message><innererror><transactionid>784C3DE2C55EF1E585DC001F29E5DD9A</transactionid><errordetails/></innererror></error>.
Please help. what could be the reason for this error?
As I can see from the screenshot, the ICF node for ODATA is not active. Please activate it by clicking on "Activate ICF Node" button and try again.
The ICF node for ODATA is already been activated , don't know why its showing grey cross under status tab.
There shouldn't be any problem in the RFC destination connection as i have used same system alias for other gateway services, created using BAPIs or RFCs, which are working fine.
This looks like an ICF node activation issue and nothing specific to Subscription/Notification. Please post the issue in the Discussions forum so that it can be resolved.
Thanks a lot, Anirvan, for this very good and helpful Blog!
Great blog! Looking forward to the next one about
Enabling Notification Push for the subscribed users!
The next one is already available. Please find it here.
What is the service pack that we have to use? I tried with SP3, but several parameters are missing.
You can use SP5 and above. It would be good if the latest version is used which is SP6 - has many other features.
A very informative video has been posted on YouTube channel related to the same topic. Please check the link below:
Did you ever tried to create Subscriptions/Notifications for a service which is created through SEGW ?
I have never tried that. But it doesn't make any difference and should work exactly how its shown above. Let us know if you are facing any specific issue in doing this.
I was at Teched Banaglore last week and as per the information I got, still notifications are not supported in SEGW transaction (SP4), SAP is planning to implement in next release 🙁 ....
Did you try marking the entity set as subscribable.
This you can do by clicking the Entity Set Node in SEGW and then checking the checkbox "Subscribable". This option is available from SP04 in SEGW.
I tried subscriptions and it is updating /IWBEP/D_MGW_SUB table also, but not able to succeed testing notifications.
Well you need to now explain in detail
1) how did you configure your BEP and FND systems
2) how did you push the notifications
3) What error are you getting
You could run the transaction SBGRFCMON transaction in BEP and FND system to see where your notifications are stuck and with what error.
Thanks for a very userful blog, I have a query if you can help, we are trying to push notifications on new work flow items for approval. I am able to successfully subscribe to service http:// /sap/opu/odata/IWWRK/WFSERVICE/SubscriptionCollection
I get a 201 status code , but I do not see the entry in table /IWFND/D_SUB_CNT
Also when I run the job RSWNSEL, i get 0 notifications back, can you suggest if I have done any config wrong?
The subscriptions are going to store in /IWBEP/D_MGW_SUB. Also can you check the /iwfnd/error_log for errors you are getting while posting a notification.
Thanks for the response.. but when I run the program nothing turns up , are there any configurations that I should care for, ??
Thanks in advance for your help.
This Push Notification feature is enabled by SAP NetWeaver Gateway, and it has nothing to do with report program that you have mentioned. Gateway provides necessary APIs to send notification from SAP system. After you have created your subscription please follow the next part of the blog Pushing Notifications Made Easy!!! : Push a Notification.
Thank you so much for nice information. It really interesting.
I have recreated the objects as per the blog but I am not able to find the service which I have created in ECC in Gateway system.Hence I am not able to activate and Maintain the service in Gateway.
I have tried to retrieve the services using different system aliases like 'local', ECC system alias but nothing is fetching me the service created in Backend.
Can you kindly help.
Thanks for the detailed Document, Its really Helpful
Could You please Send me a link for HTTP Listener,
actually i google it but i didn't get .Thanks in advance 🙂
You can use the Membrane monitor (open source):
Hi Anirvan Karmakar
Can we use such service to configure with SAP Mobile Platform to configure Push Notification ( using APNS & GCM ) ?
That is definitely possible. We had created a few PoCs in the past to push notifications from Gateway to mobile devices via SMP. However, I don't have the details with me anymore.
Nice blog. Just a question.,In the existing odata service (Leave Approval) i do not see the subscription collection. Do i have to do any configuration to get the subscription collection?