Introduction to ABAP Channels
Most ABAP applications use polling techniques to achieve an event-driven communication.For pushing an event from an ABAP backend to a browser based user agent like SAPUI5, Web Dynpro, Business Server Pages (BSP) or WebGUI, a polling in multi-seconds interval is frequently used. This is a quite system resource consuming technique. In SAPGUI usually the timer control is used to detect an event in the ABAP backend system. ABAP Channels technology targets to replace such inefficient eventing based on polling techniques through push notifications based on publish-subscribe infrastructure and WebSockets in ABAP.
In which situations you will benefit from ABAP Channels? This blog describes the typical business usage scenarios: Say Goodbye to Polling: Real-time events in ABAP with ABAP Channels.
ABAP Channels infrastructure was delivered with SAP NetWeaver AS ABAP 7.40 support package 2 (SP2) for simple tests and prototyping and released with 7.40 support package 5 (SP5).
The basic idea of the ABAP Channels (see Figure 1) is the native support of interactive and collaborative scenarios based on event-driven architecture. The scope of ABAP Channels consists of the following communication channels:
- ABAP Push Channel for bi-directional communication with user agents via WebSockets in ABAP. In the Figure 1 the documents tagged with letter “P” mark the ABAP Push Channel communication paths.
- Publish/subscribe infrastructure for exchange of messages between either user sessions (Session C => Session A) or user session and user agents
(Session C => User Agent B) residing on different application servers via ABAP Messaging Channels. In the Figure 1 the documents tagged with letter
“M” mark the ABAP Messaging Channels communication paths.
Figure1: ABAP Channels support real-time eventing in ABAP
The ABAP Channels support the following use cases:
- ABAP Push Channel(APC) The WebSocket integration in ABAP.
- ABAP Messaging Channel(AMC): Eventing framework for message exchange between different ABAP sessions based on publish/subscribe channels.
- Collaboration scenario: UsingAPC and AMC to push messages from ABAP sessions to WebSocket clients by binding publish/subscribe channels to a WebSocket connection.
Figure 2: ABAP Channels use cases in ABAP
General recommendations for usage of ABAP Channels
SAP recommendations for a common programming model for use of ABAP channels are:
- Use one WebSocket connection for collaboration scenario
- Use SAP Push Channel Protocol (PCP) messaging protocol
Use one WebSocket connection for collaboration
For collaboration scenarios which take use of WebSocket (ABAP Push Channel), it is recommended to share – whenever possible – a single WebSocket connection per client (e.g. browsertab/UI application) for consumption of different types of frequently updated content (feed): e.g. changes applied to a business object, or notification regarding incoming external information (news, weather, sport, chat, activation/deactivation of logs, traces, debugging, etc.).
This is because:
- This will avoid the unnecessary creation of parallel WebSocket connections for each feed, which is a limited resource at the both communication sides i.e. at the client and the server.
- Any additional WebSocket connection leads to performance degradation due to WebSocket protocol specific network traffic (e.g. due to keeping alive ping-pongs packages). Furthermore the lifecycle handling of the WebSockets leads to additional complexity at both communication sides.
- Moreover the situation will worsen when in the UI dependencies between different feeds exist, e.g. because a UI area contains an aggregation of information provided by different feed providers.
Figure 3 shows roughly how the messages are exchanged between an UI application running in a browser and using WebSocket connection (ABAP Push Channel) to ABAP sessions. The ABAP Messaging Channels (AMC 1… 4) are bound to the ABAP Push Chanel (APC). Either the UI Client can act as feed producer sending notifications about business object changes on UI to the subscribed WebSocket clients (Sessions 1…4) or vice versa: ABAP Sessions can publish messages about business object changes to their respective AMCs and they will be pushed by APC to the subscribed WebSocket clients (UI areas of business objects BO 1…4)
Figure 3: One WebSocket Connection (APC) for collaboration scenario
Use common messaging protocol Push Channel Protocol (PCP)
Starting with AS ABAP 7.40, SP05 it is recommended to send and receive messages in ABAP Channels in format of SAP’s own Push Channel Protocol (PCP).
The Push Channel Protocol (PCP) is a message based protocol with message format similar to a HTTP message format.
The proposal of having a common messaging protocol is also valid for most of well-known service oriented infrastructures, e.g. SOA, REST or OData based services. This enables an application developer to publish and consume the services in the same way. Furthermore with this strategy an extension of the provided services is possible, as additional optional fields/metadata can be added to the existing message without breaking the downport compatibility rules.
In context of ABAP Channels the consumption of different feeds by a single WebSocket connection requires a common higher protocol and message type on top of WebSocket for those feeds which are pushed from server. This is necessary because in the WebSocket message handling at the UI client side should be a unique and reliable way to identify the different message types and to assign the appropriate consumer UI area. In worst case if the feeds do not share the same protocol and each feed provider sends different message type, e.g. feed <f1> sends its messages as a kind of custom XML document, feed <f2> as JSON and feed <f3> as binary, it would be hardly possible to process the messages in a simple and reliable way in the WebSocket message handling.
More about how to exchange messages in ABAP Channels with PCP will be published soon on SCN.
Using ABAP Channels
More detailed information about how to use ABAP Channels in the following series of blogs by Masoud Aghadavoodi Jolfaei
- ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels
- ABAP Channels Part 2: Publish/Subscribe Messaging Using ABAP Messaging Channels
- ABAP Channels Part 3: Collaboration Scenario Using ABAP Messaging and ABAP Push Channels
- ABAP Channels Part 4: Specification of the Push Channel Protocol (PCP)
For live demonstration and step-by-step implementation guidance take a look at our ABAP Channels Video Tutorials.
For tangible examples in the system see also the blog ABAP Channels Examples.
See also FAQ – ABAP Channels.
Very informative blog..
This will truly reduce the overhead that exists in polling to check if the object is changed or not.
Thanks For Information
Nice Blog. Thanks for sharing.
I hope that this is the right place to post my question?
We want to create a Socket.IO client Lib to connect from Application Server to another Host that runs Socket.IO Server. Socket.IO is either a Websocket based communication or a XHR Polling based communication (repeating HTTP Requests).
Well for creating a ressource saving library, websockets are the better to go with. I already saw that there is an interface existing for websocket client connections IF_APC_WS_CLIENT, that probably is similar to the if_http_client interface for HTTP requests.
As long as I do not find any futher documumentation on this ( IF_APC_WS_CLIENT, CL_APC_WS_CLIENT class and interface ) on SCN or Internet, what do I have to say to our SAP Server Administrator? Which version do I need that he is going to upgrade our Test System. NW 7.5 or EHP 8 (Q1/2016). Will this version contain any documentation (for example RFC configuration SM59) for it, or will just be the plain class without any examples? Will it support only ws protocol or also wss (websocket secure) similar to http and https. I want to avoid that our sytem administrator installs NW 7.5, and we are still missing the needed classes/interfaces.
Thanks in advance for a response.
for ABAP channels developments SAP NetWeaver AS ABAP 7.4 Support Package 8 (NW 7.4 SP08) is a good starting point, you don't necessarily need NW 7.5. To understand ABAP Push Channel API, which you need to use, please take a look at ABAP Channels Documentation at SAP Help Portal containing also implementation examples or follow the link to the ABAP Push Channel blog linked in this blog above. The youtube video on ABAP Push Channel demonstrates step-by-step the development process.
I hope this helps.
Thanks a lot. I really appreciate your quick response. ABAP Push Channel blog
contains a very important note at the end. "A stateful APC communication and also an APC client library are under development." This the one I am looking for :-).
Thanks Olga for your help again in advance.
the new functionalities, e.g. APC client or APC server steteful, are part of the AS ABAP 7.5 delivery. Just have a look into the APC documention: http://help.sap.com/saphelp_nw75/helpdata/de/99/911508963d452c80d9def3dd864f4f/content.htm?frameset=/de/99/911508963d452c80d9def3dd864f4f/frameset.htm¤t_toc=/de/f3/d99aa19ceb44c89907697382aa8726/plain.htm&node_id=3&show_children=false
Thanks a lot, this was excactly I was looking for. Great!
Thanks also to Olga.
Thanks for this blog. Is it possible to use AMC/APC with classical Dynpros?
you can use AMC in Dynpro-based applications.
The APC was developed as prototype as SAPGUI Push Channel as well (with AS ABAP 740 SP8 and SAPGUI 740) but not released for productive usage in the SAPGUI. For installation and support strategy of SAPGUI refer to note "147519 - Maintenance strategy / deadlines for SAP GUI".
"not released for productive usage in the SAPGUI" means it cannot be used by any means?
the SAPGUI Push Channel prototype can be used only for test purposes and there are currently no plans for productization.
I just copy&paste here the step-by-step usage of SAPGUI Push Channel provided by Masoud within the comments to the blog Say Goodbye to Polling: Real-time eventing in ABAP with ABAP Channels
With SPC it is possible to update SAPGUI controls or the whole SAPGUI screen as well, e.g. after receiving notifications via SPC from different back-end sessions. Furthermore there is a user-specific switch which is off by default to avoid the productive usage by developers and customers. We provided also in the 740 SP8 a simple test report for SPC. If your test environment fulfills the above-mentioned requirements, i.e. using ABAP Application Server 740 SP8 and SAPGUI 740, then you can activate the switch by maintaining the user specific SET/GET parameter “SAPGUI_PUSH_CHANNEL = X” in the own user profile. For running a test report with SPC just carries out the following instructions:
Additionally execute the report RS_AMC_SEND_MESSAGE in a second SAPGUI session (to send a message to the SPC session) with the following parameters:
After execution of the RS_AMC_SEND_MESSAGE report you will get a popup prompted on the first SAPGUI session executing the report RS_AMC_RECEIVE_MESSAGE without any interaction, i.e. without double clicking the list. This shows how the SAPGUI screen gets updated automatically with the content of the received data using SPC.
please also refer to the FAQ – ABAP Channels, section “Can I use ABAP Channels to update SAP GUI frontends directly?“ regarding push message to SAP GUI.
is it possible, even in ABAP 7.5, to send Messages to specific Users or only to specific channels?
I would like to implement notifications in UI5 to inform a user about an backend event.
to a spcefic channel. You can take use of a channel with activity scope "client" and determine the SHA1 hash value of sy-uname (user name), e.g. based on the function module “CALCULATE_HASH_FOR_CHAR”, to use this as channel extension id and thus as "target user specific channel" to send a message to a specific user, based on the assumption that the target user accesses a report which act as AMC consumer for the above-mentioned channel.
Please keep in mind that from security point of view you should use a client specific channel and do not use 1:1 the user id (i.e. sy-uname) as extension but rather apply a canonical transformation, e.g. SH1 hash of user id, to user id to create the extension id. The security constrains based on the fact, that the AMC channels are used in log and traces (i.e. not only in application server but also in HTTP(S) proxies and reverse proxies and browser logs) if the channel is bound to a WebSocket connection (based on APC application).
What can be the implications of using APC/AMC when events start happening very often? For instance I’m using mixed APC/AMC scenario for informing the technicians about the some errors (e.g. IDOC postings) and, suddenly, the errors start happening very often.
Any best practice for such scenarios?
there exists a limitation for the number of AMC channels bound to WebSocket connections which can be adjusted using profile parameter, but for pushing messages to UI (WebSocket client) there exists (more or less) no limits for the number of messages transferred to the WebSocket client. Our tests, partly based on loadrunner, show that it is very hard to reach those (theoretical) limits. Just try to simulate the "heavy load" situation in your development system and if you would see any issues regarding dropping of message just let us know.
I just had a quick look at one of the videos.
All the examples on the web (a) send messages out from SAP to UI5 and (b) focus 1005 on the ABAP part and ignore the web part.
Thus I was happy to see that in the video the front end part was mentioned, however briefly.
I have taken a screenshot of the ON_INIT method from the video, it is naturally very blurry but I will try to copy it to one of my own applications to see how I go.
The concept is really simple, but the syntax , and the exact place to put the code is not as obvious to ABAP people as it may appear to web developers.
Another explanation how to work with WebSockets is in the Masoud's blog ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels
I am updating a Table using Program - A and using an ALV Report Program - B to display the data of the Table.
Using message channel sender in Program A when saving in the Table and
Using message channel receiver in the ALV Report Program B to refresh the ALV.
I am using statement - Wait for Messaging Channel, but its interrupting the program and no functions can be performed in the ALV during the waiting time.
As per the example of Chat program, the screen is active even while waiting for messages.
Can such be performed in the receiver message Program ALV Report B for dynamic refresh ?
Waiting for an early response.
Thanks and Regards,
please refer for the answer to your question to the FAQ - ABAP Channels, the related question "Can I use ABAP Channels to update SAPGUI frontends directly?".
Great and very useful post !
Thanks for Sharing...