100% found this document useful (1 vote)
771 views49 pages

ABAP Channels Part 1 - WebSocket Communication Using ABAP Push Channels - SAP Blogs PDF

Uploaded by

Lk Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
771 views49 pages

ABAP Channels Part 1 - WebSocket Communication Using ABAP Push Channels - SAP Blogs PDF

Uploaded by

Lk Soni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 49

4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Products
Products Industries
Industries Support
Support Training
Training Community
Community Developer
Developer Partner
Partner

About
About

Home / Community / Blogs + Actions

ABAP Channels Part 1: WebSocket


Communication Using ABAP Push
Channels
November 18, 2013 | 15,888 Views |

Masoud Aghadavoodi Jolfaei


more by this author

ABAP Connectivity
abap | channel | communication | event | messaging | notificatios | pub

share
0 share
0 tweet share
0 like
6

Follow

Introduction

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 1/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

For introduction to ABAP Channels please refer to Introduction to ABAP


Channels. For tangible examples in the system see also the blog ABAP
Channels Examples. See also FAQ – ABAP Channels.

This blog focuses on the WebSocket integration in ABAP, also known as ABAP
Push Channel (APC).

For live demonstration and step-by-step implementation take a look at


ABAP Push Channel Video.

Integration of WebSocket into ABAP engine

In order to pass an event from the ABAP engine to an HTML5 based user agent
we decided to integrate the WebSocket protocol into the ABAP
engine.WebSocket provides a bi-directional communication channel over a
TCP/IP socket. It is designed to be implemented in web browsers and web
servers, but in general it can be used by any client or server application.
The WebSocket JavaScript API is standardized by the W3C, whereas the
WebSocket protocol (RFC 6455) is standardized by the IETF. The
WebSocket protocol is supported by many new browsers, e.g. Chrome 14,
Firefox 7.0, IE 10 and Safari on iOS6 (and higher).

The implementation of the WebSocket protocol (RFC 6455) in ABAP is called


ABAP Push Channel (APC).The APC communication is stateless per default,
i.e. each WebSocket message leads to he creation of an individual ABAP
session for execution of the respective method. After termination of the method
the session will be released. In contrast to the existing request-response-based
communication protocols, e.g. Remote Function Call (RFC) and HTTP(S), APC
is a message-based protocol, i.e. per default the execution of a message does
not lead to a response. However on top of the messaging protocols various
communication patterns can be built, also a request-response-based
communication. This is possible because the APC session has been
implemented as a new session type..

It is important to have an understanding for the WebSocket events and


methods before starting to explain how the WebSocket protocol has been
integrated into the ABAP engine. The following simple sample code snippet
shows how to use the JavaScript WebSockets interface (the essential
events and methods are in bold format):

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 2/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

WebSocket JavaScript example code

// open a WebSocket connection

var ws = new WebSocket(“ws[s]://host.domain:port/path?query_string”);

ws.onopen = function()

// WebSocket is connected, send data using send()

ws.send(“Sending Message ….”);

alert(“Message is sent…”);

};

ws.onmessage = function (msg)

// process received Message

alert(msg.data);

// optionally close connection


ws.close();

};

ws.onclose = function()

// WebSocket is closed.

alert(“Connection is closed…”);

};

In APC framework the involved events and methods are very similar. A
simple APC class handler would have the following events and methods.

In order to support WebSocket specification for subprotocols according to


RFC 6455 has the APC server interface IF_APC_WS_EXTENSION been

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 3/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

refactored and the new interface IF_APC_WSP_EXTENSION with 740


SP08 has been established.

APC example code (before 740 SP08)

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 4/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

APC example code (before 740 SP08)

CLASS YCL_APC_WS_EXT_YEXAMPLE IMPLEMENTATION.

METHOD if_apc_ws_extension~on_start( i_context type ref to if_apc_ws_context


).

” WebSocket connection has been established

ENDMETHOD.

METHOD if_apc_ws_extension~on_message( i_message type ref to


if_apc_ws_message ).

” Message has been received

TRY.

“ Echo the message on WebSocket connection

data(lo_message_manager) = i_message->get_context( )-
>get_message_manager( ).

lo_message = lo_message_manager->create_message( ).

lo_message->set_text( i_message->get_text( ) ).

” Send message

lo_message_manager->send( lo_message ).

CATCH cx_apc_error INTO lx_apc_error.

ENDTRY.

ENDMETHOD.

METHOD if_apc_ws_extension~on_close.

” WebSocket is closed

ENDMETHOD.

ENDCLASS.

The new version of APC class handler would have the following events and
methods, which also supports the Push Channel Protocol (PCP) as
https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 5/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

subprotcol.

APC example code (from 740 SP08)

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 6/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

APC example code (from 740 SP08)

CLASS YCL_APC_WSP_EXT_YEXAMPLE IMPLEMENTATION.

METHOD if_apc_wsp_extension~on_start(
i_context type ref to if_apc_wsp_server_context
i_message_manager type ref to if_apc_wsp_message_manager ).

” WebSocket connection has been established

ENDMETHOD.

METHOD if_apc_wsp_extension~on_message(
i_message type ref to if_apc_wsp_message
i_message_manager type ref to if_apc_wsp_message_manager
i_context type ref to if_apc_wsp_server_context ).

” Message has been received

TRY.

“ Echo the message on WebSocket connection

lo_message = i_message_manager->create_message( ).

lo_message->set_text( i_message->get_text( ) ).

” Send message

i_message_manager->send( lo_message ).

CATCH cx_apc_error INTO lx_apc_error.

ENDTRY.

ENDMETHOD.

METHOD if_apc_wsp_extension~on_close(
i_reason type string
i_code type type i
i_context_base type ref to if_apc_wsp_server_context_base ).

” WebSocket is closed

ENDMETHOD.

ENDCLASS.

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 7/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

The following diagram (figure 2.0) shows the interaction model of WebSocket
client, e.g. HTML5-enabled browser, and APC framework in the ABAP engine of
the NetWeaver application server.

Figure 2.0: WebSocket/APC interaction model in ABAP

The main advantage of the integration model is based on the fact that
WebSocket connections are administrated by an ICM process, i.e. the end-
point of a connection is the ICM process and not the ABAP session. This
design helps to reduce resource consumption during inactivity phases of
WebSocket communication. Furthermore APC applications are stateless per
default.This means that each received message is handled in a dedicated
session. The application can preserve its state information either in shared
object areas or database tables.

Creating an ABAP Push Channel (APC) application

This section contains a step by step description of the creation of an ABAP


Push Channel application.

Before starting with development of an APC application we should check the


prerequisites for the WebSocket environment in ABAP. From support package 5
upwards the WebSocket configuration is active per default. The WebSocket
connection uses the same ports as the maintained HTTP and HTTPS ports and
there is no explicit entry for “WEBSOCKET” and “WEBSOCKETS” services in

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 8/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

service entries of transaction SMICM. This is different in lower releases. In


NetWeaver 740 support package 2 up to support package 4, the WebSocket
port parameters were maintained actively. This can be done in two different
ways:

Manually and temporarily in the transaction SMICM (via


menu entry “Goto” -> “Service” and again in menu “Service” -
> “Create“) you can choose a proper port number for the field
“New Service Port” , e.g. 50090 or 44390 for secure or non-
secure WebSocket (WS), and then in the field “Protocol” enter
“WEBSOCKET” (non-secure WebSocket) or “WEBSOCKETS”
(secure WebSocket).

Alternatively, enabling ABAP to use WebSockets can be performed


by setting ICM profile parameters. In the profile of the instances
supporting WebSockets, some parameters must be added.
Example:

icm/server_port_101 = PROT=WEBSOCKET,PORT=0,TIMEOUT=-1
icm/server_port_102 = PROT=WEBSOCKETS,PORT=0,TIMEOUT=-1

assuming that 101 and 102 are not yet used by other server_ports.

Port number is always 0. Timeout is always -1.

An ABAP Push Channel (APC) application can be created in two ways.

In transaction SE80 using the context menu entry (“Right-Click


on top-level package object) “Create” -> “Connectivity” ->
“ABAP Push Channel” (see figure 2.1):

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 9/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Figure 2.1.

As of release 740 SP5: In the transaction SAPC using the


context menu entry (“Right-Click”) on the “ABAP Push
Channel” entry and selecting “Create” (see figure 2.2):

Figure 2.2.

In the next step, the name of the APC application has to be


enteredand the popup screens have to be confimed (press
“Enter”). In this example “YAPC_WS_TEST” is used as
application name (see figure 2.3):

Figure 2.3.

Also choose an appropriate package entry, in this case as


“Local Object” (see figure 2.4):

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 10/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Figure 2.4.

Additionally, the field “Description” has to be maintained (see


figure 2.5):

Figure 2.5.

Next step: save the application (see figure 2.6):

Figure 2.6.

Now the associated design time entities, i.e. in the transaction


SICF service path /sap/bc/apc/<name space>/<application
name> and the corresponding APC application class, have to be
generated (see figure 2.7):

Figure 2.7.

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 11/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Confirm the generation step.

In the next steps the basic implementation of the APC extension


class will be initiated. To do so, double-click on the class name,
here YCL_APC_WS_EXT_YAPC_WS_TEST (see figure 2.8):

Figure 2.8.

The before-mentioned action leads to the display of the class


YCL_APC_WS_EXT_YAPC_WS_TEST in the class builder
environment (see figure 2.9):

Figure 2.9.

Change the display mode to change, i.e.click “Display” <->


“Change” (see figure 2.10).

Figure 2.10.

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 12/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

The required actions are the implementation of the methods


ON_START and ON_MESSAGE. The ON_START method is
executed as soon as the WebSocket connection setup phase is
accomplished successfully. The ON_MESSAGE method is
executed when receiving a message. As the extension class is
inherited from an abstract class to implement the ON_START and
ON_MESSAGE methods these methods have to be redefined.
Optionally also the method ON_CLOSE and ON_ERROR can be
redefined, i.e. implemented, as well. To do so, choose the
respective method, i.e. ON_START, and press “Rede ne” (see
figure 2.11):

Figure 2.11.

In this example the only action which is processed during


ON_START execution is to send a text message to the
WebSocket client, after inserting the following code in the method
ON_START:

The example coding for 740 with support package less than
SP08 is:

METHOD if_apc_ws_extension~on_start.

TRY.

* send the message on WebSocket connection

DATA(lo_message_manager) = i_context-
>get_message_manager( ).

DATA(lo_message) = lo_message_manager-
>create_message( ).

lo_message->set_text( |{ sy-mandt }/{ sy-uname }:


ON_START has been successfully executed !| ).

lo_message_manager->send( lo_message ).

CATCH cx_apc_error INTO DATA(lx_apc_error).

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 13/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

MESSAGE lx_apc_error->get_text( ) TYPE ‘E’.

ENDTRY.

ENDMETHOD.
And the coding for 740 SP08 and later is:

METHOD if_apc_ws_extension~on_start.

TRY.

* send the message on WebSocket connection

DATA(lo_message) = i_message_manager-
>create_message( ).

lo_message->set_text( |{ sy-mandt }/{ sy-uname }:


ON_START has been successfully executed !| ).

i_message_manager->send( lo_message ).

CATCH cx_apc_error INTO DATA(lx_apc_error).

MESSAGE lx_apc_error->get_text( ) TYPE ‘E’.

ENDTRY.

ENDMETHOD.

the method contains the code below (see figure 2.12):

Figure 2.12.

Save the method (click “Save”) in the “Class Builder” (see


figure 2.13):

Figure 2.13.

and leave the method (click “Back”), see figure 2.14:

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 14/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Figure 2.14.

In the ON_MESSAGE method both a message text and the


received message are sent to the WebSocket client, after
inserting the following code in the ON_MESSAGE method:

The example coding for 740 with support package less than
SP08 is:

METHOD if_apc_ws_extension~on_message.

TRY.

* retrieve the text message

DATA(lv_text) = i_message->get_text( ).

* create the message manager and message object

DATA(lo_context) = i_message->get_context( ).

DATA(lo_message_manager) = lo_context-
>get_message_manager( ).

DATA(lo_message) = lo_message_manager-
>create_message( ).

* send 1st message

lo_message->set_text( |{ sy-mandt }/{ sy-uname }:


ON_MESSAGE has been successfully executed !| ).

lo_message_manager->send( lo_message ).

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 15/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

* send 2nd message, i.e. echo the incoming message

lo_message->set_text( lv_text ).

lo_message_manager->send( lo_message ).

CATCH cx_apc_error INTO DATA(lx_apc_error).

MESSAGE lx_apc_error->get_text( ) TYPE ‘E’.

ENDTRY.

ENDMETHOD.

And for 740 SP08 and later release is:

METHOD if_apc_ws_extension~on_message.

TRY.

* retrieve the text message

DATA(lv_text) = i_message->get_text( ).

* create the message object

DATA(lo_message) = lo_message_manager-
>create_message( ).

* send 1st message

lo_message->set_text( |{ sy-mandt }/{ sy-uname }:


ON_MESSAGE has been successfully executed !| ).

i_message_manager->send( lo_message ).

* send 2nd message, i.e. echo the incoming message

lo_message->set_text( lv_text ).

i_message_manager->send( lo_message ).

CATCH cx_apc_error INTO DATA(lx_apc_error).

MESSAGE lx_apc_error->get_text( ) TYPE ‘E’.

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 16/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

ENDTRY.

ENDMETHOD.

The method contains the code below (see figure 2.15):

Figure 2.15.

Additionally save the method (click “Save”) in the “Class


Builder” (transaction SE24), see figure 2.16:

Figure 2.16.

and leave the method (click “Back”), see figure 2.17:

Figure 2.17.

Finally, activate the class (click “Activate”) in the “Class


Builder”, see figure 2.18:

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 17/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Figure 2.18.

and leave the “Class Builder” via Back (see figure 2.19):

Figure 2.19.

Optionally, you can maintain the virus/content scan IDs for


incoming and outgoing messages at any time (see figure 2.20):

Figure 2.20.

Now the APC application has to be activated as well, to do so


press Activate (see figure 2.21):

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 18/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Figure 2.21.

To test the application just press the Test icon (see figure
2.22):

Figure 2.22.

This action launches the Web Dynpro application


WDR_TEST_APC in a browser (see figure 2.23) which
supports the WebSocket protocol (RFC 6455) (e.g. Chrome
version >= 16, Firefox version >= 11, Internet Explorer version
>= 10 and Safari on iOS version >= 6). In case of any issue it
should be double checked that the Web Dynpro service path
“/sap/bc/webdynpro/sap/wdr_test_apc” in the transaction SICF
is active.

Figure 2.23.

Limitation: In the present version of APC framework is the size of


WebSocket/APC messages exchanged between client and server limited to

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 19/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

~64 kbytes. Furthermore the WebSocket support in Web Dispatcher is


released with the version 7.41 and for installation of a new version of Web
Dispatcher please refer to SAP note 908097.

APC Security

Each APC application has a path entry in the transaction SICF. With a new
installation this entry is inactive per default. For an active usage of an APC
application the associated APC path in SICF transaction has to be activated
before. The path to an APC application is /sap/bc/apc/<name
space>/<application name>. For each APC application you can maintain a
dedicated virus/content scan ID for outgoing and incoming messages.
Furthermore we recommend to use the existing escape methods in ABAP,
e.g. the ESCAPE statement, to escape the WebSocket content that is
exchanged between client and server. Finally we highly recommend to use
the secure varaint of WebSocket, i.e. wss instead of ws, for the
communication.

For cross-origin-access to an APC application the APC framework also supports


some aspects of the “The Web Origin Concept”, i.e. RFC 6454. In order to allow
the access to APC application from an external server the white list
maintenance via transaction SAPC_CROSS_ORIGIN has to be done
accordingly.

APC Supportability

WIth external breakpoints you can debug the execution of the ON_START,
ON_MESSAGE, ON_CLOSE and ON_ERROR methods similarily to HTTP
handler i.e. by setting breakpoints in the respective methods.

In transaction SAPC you can activate/deactivate the following supportability


tools for a specific APC application:

be initiated:

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 20/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Debugging: choose menu bar the entry “Utilities” -> “Debugging” ->
“Activate Debugging“/Deactivate Debugging“
Runtime Analysis: choose menu bar the entry “Utilities” ->
“Runtime Analysis” -> “Activate“/Deactivate”
Kernel Trace: choose menu bar the entry “Utilities” -> “Trace” ->
“Reset Trace“/”Display Trace“/”Activate Trace“/“Deactivate Trace“

The runtime analysis records which start with the prefix “APC:<application
path>”, e.g. “APC:/sap/bc/apc/sap/ping” for a PING application, can be
monitored in transaction SAT.

Furthermore, transaction SMWS shows the list of active WebSocket


connections and their associated APC application on each application
server.

Conclusion and outlook

As you can see from the lines above, the ABAP Push Channel provides the
infrastructure for WebSocket communication in ABAP. The present
implementation of APC supports only the server side of communication based
on stateless sessions, i.e. stateless APC communication similar to stateless
HTTP communication. A stateful APC communication and also an APC client
library are under development.

The next related blog to ABAP Channels is ABAP Messaging Channel (AMC).
AMC blog describes the eventing framework for messages exchange
between different ABAP sessions based on publish/subscribe channels.

Alert Moderator

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 21/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

57 Comments

Krishna Kishor Kammaje

December 14, 2013 at 2:43 am

Hey Masoud,

Very useful feature. Congrats to your team for building this into ABAP stack. I am
exited by its possibilities.

I am building SAP UI5 applications based on NW Gateway services. One of the very
required feature is pessimistic resource locking. Example: If I am editing a purchase
order in UI5 app, no other user using UI5 app should be able to change it.

This is my thought process after reading your blog.

Within my UI5 application, as soon as someone enters into change mode, I would
create a websocket connection for that client (UI5 library provides an API) and send
the resource id (say PO number). In the server side I would make an entry in a Z
table (with a generated GUID connection ID and PO number) and give back a
success message to the client. If the Z table already has an entry for that PO, then
the server would refuse the lock and push a suitable message. Whenever the user
closes the browser/tab, I suppose that the websocket connection would end, and in
the on_close method, I would remove the entry from the Z table. If the user is
inactive for more than 10 mins, I would end the websocket connection in the client
javascript.

As I understand Z Table would not be required in a stateful websocket, since that


should allow me to make use of SAP Lock objects.

How does this sound?

Please let me know your comments about this approach.

Thanks

Krishna

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 22/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Samson Dass

April 23, 2017 at 5:07 pm

Hi Krishna,

We too have similar requirements for Pessimistic Locking. Please share


your insights of how you were able to achieve this solution. Also find
below some data points for your consideration.

All the objects are Z-Objects so no locking is expected from


anywhere else, apart from UI5 browser.
APC/AMC supported in our current package
What would happen if user simply closes his system or there is a
timeout? Can web sockets address these cases?

I was planning to use your above suggested approach for locking.

Regards,

Samson

Masoud Aghadavoodi Jolfaei Post author

February 20, 2014 at 7:30 pm

Hi Krishna,

your proposal sounds good as far as those lock entities, e.g. purchages orders, are
not accessed by other classical transactions, e.g. from within SAPGUI or RFC, using
ABAP enqueue based locks. In that case the enqueue locks and your custom table
for recording of locks are not anymore in sync and this could lead to side effects, e.g.
accessing the order though the order is already marked as locked in the Z* table .

Best regards,

Masoud

Krishna Kishor Kammaje

February 22, 2014 at 9:26 am

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 23/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Thanks Masoud for your insight.

Surendra Suryawanshi

May 14, 2015 at 10:53 am

Hi Masoud,

Thanks for this blog.

I have also implement same web socket in gateway service. When I


am calling from browser it’s calling Accept method then immediately
it’s calling close method.

how I will handle close method . it should call on only when user
explicitly call close or browser close

Thank.

Shadab Shafiq

March 1, 2014 at 3:22 pm

HI Masoud,

I was trying your example. The part of send/receive works perfectly. But now I
wanted to experiment further based on what you have written about “exchange of
messages between either user sessions“. I first tried to run two instances of same
application and in parallel browser windows and was trying to send message hoping
it should also be received in the other window. But this does not work. I also ceated a
simple html page using the websocket URL just created, but this also works in its
own context it only listens and transmits its own message.

Would the class need to be enhanced further. I tried this on Basis 740 SP-Level
0000.

Warm Regards

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 24/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Shadab Shafiq

Masoud Aghadavoodi Jolfaei Post author

March 2, 2014 at 5:16 pm

Hi Shadab,
this blog is one of the up-coming 3-4 articles around ABAP Channel capabilities. As I
mentioned in the introduction:

The ABAP channels supports the following use-cases:
1. 1. ABAP Push Channel (APC): The WebSocket integration in ABAP.
2. 2. ABAP Messaging Channel (AMC): Eventing framework for messages
exchange between different ABAP sessions based on publish/subscribe
channels.
3. 3. Collaboration scenario: Using APC and AMC to push messages from
ABAP sessions to WebSocket clients by binding publish/subscribe channels
to the WebSocket connection.

In this article we focus on the WebSocket framework in ABAP called ABAP Push
Channel.

Well I am writing at the moment a blog about ABAP Messaging Channel (AMC) and
additionally I will spend time for the collaboration article which will contain the
information you are looking for. But in the mean time you can have a look into one of
my example in the system. Just execute the APC test application “http(s)://<host>:
<port>/sap/bc/apc_test/ping” in Chrome/Firefox browser, preferably in several
browser windows. Before executing the URL you have to activate the paths
“/sap/bc/apc_test/ping” and “/sap/bc/apc/sap/ping” in the transaction SICF. The
proposed URL executes the APC application “PING” (look into the html source
code) which itself take use of AMC application APC_SIMPLE_TEST to exchange of
messages between different WebSocket connections. You may debug the
ON_START and ON_MESSAGE methods of the APC application “PING” during
execution of the URL.

Best regards,
Masoud

Shadab Shafiq

March 3, 2014 at 8:05 am

Hi Masoud,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 25/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Thanks.

Please update this article with followup link to your new


articles. Really looking forward to it.

Warm Regards

Shadab

Vikas Lamba

June 8, 2014 at 2:37 pm

Hi Masoud,

Excellent blog. Thanks for sharing.

I was trying what you did and have a question now. I see that all the test client
examples are using a Web Dynpro application which is of course hosted in the same
NW server and have no security issue communicating.

I tried to write a JS page to make a client and then realized that JS WS API does not
provide any way to pass authorization information to server. So I was getting HTTP
401 instead of a WS upgrade.

Can you share some light on how can I use a JS client to open a WS connection with
ABAP and does it need any additional configurations on server to enable this. I Have
NW 7.4 SP06 installed.

Cheers,

Vikas

Masoud Aghadavoodi Jolfaei Post author

June 8, 2014 at 3:36 pm

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 26/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Hi Vikas,

you can pass the logon data (just for testing) as cgi form parameters,
i.e. sap-client=<client number>&sap-user=<username>&sap-password=
<password>. If the JS WS client page does not reside on the same
ABAP system, then you have to maintain the cross origin access white
list accordingly (refer to cross-origin-access in APC security section).
Each WS access rejection due to cross origin access is reported in
ABAP log, i.e.transaction SM21 on the respective application server.

Alternatively you can create the JS WS client in ABAP system and this
either as a BSP application or as a free style HTTP handler (just have
look into the SICF handler maintained for the path /sap/bc/apc_test/ping
(also have a look to my reply to Shadab).

Best regards,

Masoud

Horst Keller

July 24, 2014 at 4:21 pm

Can you share some light on how can I use a JS client to open a
WS connection with ABAP

In my blog ABAP News for Release 7.40 – WebSocket Communication


with ABAP Channels I show an example, where I drilled down the web
client that communicates with ABAP to the absolute minimum – no BSP,
no WDY, only a slim JS. Maybe that’s what your looking for or is it
already too primitive? B.T.W. if you are on NW 7.4 SP06, you find that
example ready for execution as program DEMO_APC in the ABAP
Example Library (see APC-Example).

Best

Horst

Vikas Lamba

August 3, 2014 at 10:42 am

Hi Horst,
https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 27/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Thanks for the example. I was already able to get this


working.

But just to describe my goal I was trying to use WS


connections to achieve a real time push to browser based
applications on mobile phones (iOS).

I hit a dead end when I realized that iOS terminates all WS


connections originating from a mobile device when the app
goes to background.

Is there any solution that you are aware of for this


problem?

Regards,

Vikas

Masoud Aghadavoodi Jolfaei Post author

August 3, 2014 at 1:50 pm

Hi Vikas,

the only workaround I am aware of is that you


try to establish the WebSocket connection in
WeSocket onclose event again (in order to
overcome an endless loop just limit the
number of trials). This event is processed as
soon as the application gets activated again.
This will help to reload the content through
WebSocket connection.

A real event-driven push can be achieved with


the push platforms, e.g. SAP/Sybase Unwired
Platform (SUP) which also take use of apple
push notification service in case of iOS to
notify/awake the application.

Best regards,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 28/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Masoud

Ming Zhang

March 6, 2017 at 8:13 am

Hi, Vikas

We also run into the similar issue as you.

We are making some web application


deployed in public internet. And it is confused
that how to let the ERP system in internal
network to authenticate the connection from
outside.

Do you use the wss URL like

wss://ldai3ebj.wdf.sap.corp:44315/sap/bc/apc/
sap/zhar_apc_center?sap-client=<client
number>&sap-user=<username>&sap-
password=<password>? Do you encode the
password in BASE64?

And do you make other configuration in ERP


system except the cross-domain config?

Michael Stürmer

June 24, 2014 at 9:51 am

Hi Masoud,

while experimenting, I wanted to do some connection-specific cleanup in the


ON_CLOSE-method and ended up enhancing CL_APC_MANAGER=>DISPATCH to
get to the initial request. Is there any official way to access the initial request from
within ON_CLOSE?

Also, I noticed some WebSocket-related (but unfortunately not released) notes in the
web dispatcher patch documentation. Do you know if/when there’ll be official support
for WebSockets in web dispatcher?
https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 29/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Thanks,

Michael

Masoud Aghadavoodi Jolfaei Post author

June 26, 2014 at 7:35 am

Hi Michael,

ON_CLOSE/ON_ERROR handling of APC has been enhanced with NW 740 SP08 release. In the
740 SP08 release contains ON_CLOSE/ON_ERROR method the ini al request interface
parameter as well. The solu on to establish WebSocket context informa on for a WebSocket
connec on is to iden fy the WebSocket connec on id, which is stable for the whole life me
of the connec on. The connec on is then used as key to temporarily persist the context
informa on on the backend, either by using a (buffered) database table or shared objects
areas. Usually you would establish the context informa on for the WebSocket connec on,
i.e. APC applica on context, either in ON_START or in ON_MESSAGE method. And the
cleanup should take place in ON_CLOSE method.

By the way we do not guarantee that the ON_CLOSE method will be executed under all
circumstances, as there are worst-case scenarios which this hinder us to execute any ABAP
coding.

For the iden fica on of the WebSocket connec on id following steps has to be applied:

1. For NW 740 SP05 release (for correct extended passport (EPP) handling for
WebSocket) please apply the kernel patch level 35, i.e. download from
service.sap.com/swdc => Browse our Download Catalog => Addi onal Components
=> SAP Kernel
2. Use follwoing ABAP coding in ON_START/ON_MESSAGE or ON_CLOSE methods to
retrieve the connec on id out of EPP:

DATA: lv_connec on_id TYPE epp_root_context_id.

TRY.

DATA(lo_epp_global) = cl_epp_global_factory=>get_sec on( ).

lv_connec on_id = lo_epp_global->get_root_context_id_as_uuid( ).

CATCH cx_epp_error INTO DATA(lx_epp_error).

” bad luck/should not happen !!!

ENDTRY.

Web Dispatcher supports WebSocket out of the box without any addi onal configura on
since 7.40 patch level 15 and with 7.41 patch level 0.

Enjoy the ABAP Channels,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 30/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Masoud

Daniel Rothmund

August 8, 2014 at 8:24 am

Hi ,

what are the correct settings to use the APC with an SAP WebDispatcher infront ?

I doesn’t find anything about it at help.sap.com

Regards

Masoud Aghadavoodi Jolfaei Post author

August 8, 2014 at 9:27 am

Hi Daniel,

Web Dispatcher supports WebSocket out of the box without any addi onal configura on
since 7.40 patch level 15 and with 7.41 patch level 0.

Kind regards,

Masoud

Daniel Rothmund

August 8, 2014 at 10:42 am

thx now it works

Sergiu Popa

September 11, 2014 at 6:26 pm

Hi Masoud,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 31/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

First of all thank you for writing this blog! I find it very useful as well as the technology
it relates about.

Now to get to the point of this question, I would like to use APC in some applications,
but I have a few concerns regarding limitations in terms concurrent connections to an
APC. Is there any hard-coded restriction in terms of the number of concurrent
connections to an APC?

Best regards,

Sergiu

Masoud Aghadavoodi Jolfaei Post author

September 12, 2014 at 10:07 am

Hi Sergiu,

the limitation based on the application server/ICM/WebDispatcher


profile parameter configurations. In our lab tests with the respective
server we reached 20000 parallel WebSocket connections, which in
certain cases led to memory issues in backend. The respective profile
parameter for ICM/WebDispatcher are:

rdisp/max_websocket_connections=20000

icm/max_conn=20000

Best regards,

Masoud

SANOOP P S

September 26, 2014 at 4:28 am

Can ABAP Push Channel framework be configured in SAP Netweaver 7.30 ?

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 32/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Masoud Aghadavoodi Jolfaei Post author

September 26, 2014 at 7:09 am

Hi,

this feature is only available in AS ABAP 740 releases.

Best regards,

Masoud

Manish Majumdar

October 24, 2014 at 3:27 pm

Hi Masoud,

Really nice Blogs. I really appreciate the time you have put in to show make it
available for SDn users. I was experimeting a bit around this to get rid of the
notification service used in my WD application. So right now I have a WD application
with a HTMLISLAND and have a JavaScript added into it as a Mime Object. I am
creating a Websocket object within my JS function. What I am trying to do is to pass
a value from my actual WD application to the JS function and from JS function I am
trying to pass on the value to the APC~ON_START method. The first part seems to
be easy enough. But I am finding it difficult to pass any value to the ON_START
method. I did checked the Websocket API but I didnt find anything useful for my
purpose.

I would really appreciate if you could put some inputs here.

Regards,

Manish

Masoud Aghadavoodi Jolfaei Post author

October 24, 2014 at 4:10 pm

Hi Manish,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 33/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

you can pass any name-value pairs as part of the WebSocket URL (and
query string) to the APC application, such as
wss://host:port/sap/bc/apc/sap/<myapplication>?
name1=value1&name2=value2. In the APC application <myapplication>
in ON_START or ON_MESSAGE the parameters can be accessed via
context interface IF_APC_WS_CONTEXT and as follow:

METHOD if_apc_ws_extension~on_start.

DATA: lo_binding TYPE REF TO if_apc_ws_binding_manager.

DATA: lo_request TYPE REF TO if_apc_ws_initial_request.

DATA: lx_apc_error TYPE REF TO cx_apc_error.

DATA: lt_fields TYPE tihttpnvp.

DATA: lv_value TYPE string.

DATA:

TRY.

lo_binding = i_context->get_binding_manager( ).

lo_request = i_context->get_initial_request( ).

“determine cgi parameters aka form fields

lo_request->get_form_fields( CHANGING c_fields = lt_fields ).

lv_value = lo_request->get_form_field( ‘name1’ ).

CATCH cx_apc_error INTO lx_apc_error.

data(lv_message) = lx_apc_error->get_text( ).

MESSAGE lv_message TYPE ‘E’.

ENDTRY.

ENDMETHOD.

Just check out in your development system the ON_START &


ON:MESSAGE methods of the APC application ECHO in the SAPC
transaction as example

Cheers,

Masoud
https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 34/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Klaus Keller

October 29, 2014 at 2:18 pm

Hi Manish,

To pass values from Web Dynpro to the HTMLIsland (JavaScript), you’ll


need to add a script call. See the HTMLIsland Developer Guideline for
examples on how to do this: http://scn.sap.com/docs/DOC-34098

Regards,

Klaus

Erwin Van Lysebetten

December 5, 2014 at 12:59 pm

Hello,

I have created mu APC just as described in this document.

However when I want to ‘Test’ my APC from Tx SE80, I get the error ‘Function not yet
implemented’

Any ideas what can be the problem ?

Regards,

Erwin

Masoud Aghadavoodi Jolfaei Post author

December 8, 2014 at 8:44 am

Hi Erwin,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 35/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

we couldn’t reproduce the issue in different ABAP Application Server


support packages (SP) >= SP5. If you still observe the issue and not
able to identify the reason please create a CSN ticket for the component
BC-MID-AC and provide the affected system release (ABAP Application
Server support package ??).

Best regards,

Masoud

Erwin Van Lysebetten

December 8, 2014 at 9:21 am

Hello,

Our system is currently SP2

Do we need SP5 before we can use the Abap Push


Channel ?

Because I was able to create the pushchannel fine.

He generated the class and service.

The service I needed to activate manually in SICF

Best regards,

Erwin

Masoud Aghadavoodi Jolfaei Post author

December 8, 2014 at 10:23 am

Hi Erwin,

we have released the “basic functionality” for


the ABAP Channels with SP5. I personally
recommend – if/as soon as possible – to use
at least SP8. As with the SP8 we have
established additional capabilities for the
ABAP Push Channel (see the CSN note
2105389).

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 36/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Best regards,

Masoud

santosh pasupunuri

January 30, 2015 at 9:35 am

Thank you. this really helped..

siva anand balamurugan

May 14, 2015 at 6:18 am

Hi Masoud Aghadavoodi Jolfaei,

Thanks for Sharing The Knowledge. and i have one Doubt in my Development.

is it Posible To Pass any parameter from Back end and Retrieve it in WD Componet??

If it so, how to Achieve it??

Pls Help me.

Thanks in Advance.

Masoud Aghadavoodi Jolfaei Post author

May 16, 2015 at 1:31 pm

Hi Siva anand,

I do not understand the (end to end) use case. If you like to push
messages/parameters from an ABAP session to another one (WD
component), wheres the target session is a stateful session (here Web
Dynpro session), in this case the ABAP Messaging Channels provide
the necessary infrastructure. Alternatively using the ABAP Channels
collaboration scenario you can push messages/parameters from an

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 37/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

ABAP session to your Web Dynpro UI (HTML island) running in browser


and additionally forward it to your Web Dynpro session/component.

I also recommend to you to place the Web Dynpro related subjects in


the Web Dynpro discussion room.

Best regards,

Masoud

Nitesh Jain

May 16, 2015 at 6:36 am

Hi Masoud,

Thanks for the wonderful blog series.

I built a UI5 application using websockets and I integrated this application into our
SAP Enterprise Portal. When the UI5 application is executed from the portal the
websocket connection with the backend was getting established successfully. We
tried this from multiple PCs and it worked.

Next we modified the application, redeployed it in the backend and re-run the
application from the portal and am facing the following issues:

a. The websocket connection is NOT getting established and I am getting the error
‘Error during websocket handshake: unexpected response code: 403’.

b. Then i tried executing the application from another PC and in this case the
websocket connection is getting established however the modifications made to the
application are not getting reflected.

Then I tried executing the UI5 application directly from the browser and in this case it
worked correctly.

Would appreciate you help in trying to resolve the issues I am getting when
executing the UI5 application from the portal.

Server versions: Portal: SAP EP 7.4, Backend ECC – ECC6 EHP7 SP06

regards

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 38/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Nitesh

Masoud Aghadavoodi Jolfaei Post author

May 16, 2015 at 1:44 pm

Hi Nitesh,

the response code 403 is usually processed because of a cross origin


access issue (see also the section APC Security of my blog). You will
find in the system log of the corresponding ABAP application server, i.e.
in the transaction SM21, further information to the APC issues. I also
recommend to read the SAP note “2123214 – Error handling for ABAP
Channels using SYSLOG entries” any apply the necessary cross-origin
configuration in the affected system.

Best regards,

Masoud

Kevin Zhang

March 3, 2016 at 2:24 pm

Hi Masoud,

Thanks for your contribution. It really helps. Right now I’m developing an UI5
application with ABAP push channel and the APC works fine when test with
WebDynpro WDR_TEST_APC. But I’m stuck when I try to integrate it with UI5. Here is

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 39/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

my JS code

And I configured the proxy in neo-app.json so that it can redirect request.

“path”: “/sap/bc/apc”,

“target”: {

“type”: “destination”,

“name”: “ER9CLNT001”,

“entryPath”: “/sap/bc/apc”

},

“description”: “ER9 client 001”

But the app ends with an error when running in Chrome.

WebSocket connection to ‘wss://webidetesting3973187-


ori.dispatcher.neo.ondemand.com/sap/bc/apc/sap/zqchart_ws’ failed: HTTP
Authentication failed; no valid credentials available.

And the error changed to Firefox can’t establish a connection to the server at
wss://webidetesting3973187-
ori.dispatcher.neo.ondemand.com/sap/bc/apc/sap/zqchart_ws. when running
in Firefox. Do you have any idea about this issue?

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 40/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Best Regards,

Kevin Zhang

Masoud Aghadavoodi Jolfaei Post author

March 15, 2016 at 11:59 am

Hi Kevin,

I assume you are using WebIDE to develop your UI5/Fiori application in


HCP. If so up to now the cloud connector and Helium and its destination
service (in HCP) does not support any WebSocket communication.
Here you have to setup the connection directly to the ABAP backend
system.

Cheers,

Masoud

Kenneth Moore

March 3, 2016 at 7:12 pm

Hello Masoud,

When I test the Push Channel it does not connect. I push the connect button, but
nothing happens and there is no message. Any ideas?

Thanks,

Kenneth

Masoud Aghadavoodi Jolfaei Post author

March 15, 2016 at 12:01 pm

Hi Kenneth,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 41/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

in Chrome browser you usually find in the developer tools (F12) ->
Network -> WS log entries regarding the connection setup issues.

Cheers,

Masoud

Kenneth Moore

March 15, 2016 at 12:35 pm

Hi Masoud,

There are no log entries.

Masoud Aghadavoodi Jolfaei Post author

March 22, 2016 at 7:54 am

Hi Kenneth,

this is very strange. This means somehow that the


browser has problems to process the WS(S)
command. Here you have to analyze/debug the
JavaScript page in Chrome.

Cheers,

Masoud

Daniel Rothmund

May 17, 2016 at 3:12 pm

Hello Masoud,

ist it possible to have fixed user for a wss connection ?

I tried to add a service user to sicf but I get an 403 from icm.

Regards

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 42/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Masoud Aghadavoodi Jolfaei Post author

May 17, 2016 at 4:00 pm

Hi Daniel,

sure, in that case you have to choose in the respective (external) SICF
service and in the tab “Logon Data” as “Procedure” the option “Required
with Logon Data”. By the way the response code 403 arises (I assume)
since the cross origin policy check of APC failes. Here you have to apply
the SAP note “2123214 – Error handling for ABAP Channels using SYSLOG
entries” .

Cheers

Masoud

Daniel Rothmund

May 18, 2016 at 5:15 am

Thx Masoud ,

the problem was the cross origin policy !

And also thanks for the hint with the note. I did not know
“RS_AC_READ_SYSLOG”.

BR

Daniel

Paul Hardy

June 24, 2016 at 7:35 am

Dear All,

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 43/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

In the above comments I have seen several people attempting to add code to a UI5
application in order to initiate a web socket connection and then send a message
from a UI5 application to SAP.

As this works with the test tool in transaction SAPC it must be possible, but no-one
here at least seems to be able to get this to work.

Has anyone in fact managed to write some code in any part of a UI5 application – be
it XML or JS – that manages to establish a connection and then send a message
from the UI5 front end to the SAP back end?

Cheersy Cheers

Paul

Masoud Aghadavoodi Jolfaei Post author

June 24, 2016 at 8:43 am

Hi Paul,

I have recently released a new blog called ABAP Channels Examples.


One of my intention for this blog was to provide several “simple use
cases” for the ABAP Channels developer, including the involved ABAP
and UI coding in the system. So I recommend to you to look at the
Sohbat Slider example which from UI perspective consists of a single
BSP/Fiori (/sap/bc/bsp/sap/sohbat_slider) application.

Cheers,

Masoud

Dren Selimi

October 10, 2016 at 1:41 pm

Hello Masoud,

I am having trouble receiving a message from javascript in the method


ON_MESSAGE, for example, using the code on javascript that you provided above I
can connect to the WebSocket and I can see that if I use a break-point in the
ON_START method in SAP, but the part for ” ws.send(“hello);” ” won’t trigger
https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 44/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

ON_MESSAGE, is that what should happen, or I have got it wrong, I that is what
should happen why doesn’t happen, where do you think is my problem ?

Thanks, Dren

Masoud Aghadavoodi Jolfaei Post author

March 14, 2017 at 10:22 am

Hi Dren,

sorry for the late response. Please have a look into the FAQ – ABAP
Channels.and also note 2353453.

Cheers,

Masoud

Kyle Bitson

July 26, 2017 at 5:50 am

Hi Masoud,

I’m getting a 501 (Not Implemented) error when trying to connect to the WS. What
could be causing this, and how could I go about debugging?

Thanks,
Kyle

Masoud Aghadavoodi Jolfaei Post author

January 6, 2018 at 10:47 am

Hi Kyle,

sorry for late response. I assume there is something wrong with the
creation of you application. Just refer to the FAQ – ABAP Channels, and
the related question “My APC WebSocket connection to the ABAP

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 45/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

application server does not work. Are there known pitfalls? What are the
first steps for troubleshooting?”.

Good luck!

Masoud

Serdar Simsekler

August 1, 2017 at 9:14 am

Hello Masoud

Thanks for the blog series. Can I ask how we can have the ABAP side send
messages directly to the e.g. UI5 application through the defined APC without AMC?

So, a running ABAP session decides to send a message to any/all frontend


applications hooked on the defined APC, i.e. established connection to the APC
service, and just sends it without an incoming message from the frontend
applications.

Thanks

Serdar

Masoud Aghadavoodi Jolfaei Post author

January 9, 2018 at 1:58 pm

Hi Serdar,

sorry for the late response. From ABAP Server release >= 7.50 we have
established the concept of system-wide access or attach handle to be
able to push data from a session to an existing WebSocket connection.
For this please refer to teh documentation and examples available here.

Cheers,

Masoud

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 46/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

manish sethia

January 21, 2018 at 11:44 am

Hello Masoud,

If I call a BAPI inside the method on_message and that BAPI internally calls a
function module which raises an error message then the session ends abruptly. In
normal report programs or classes, that is not the case and standalone BAPI is also
executed successfully.

Is it normal behavior in case of APC?

Thanks,

Manish

Masoud Aghadavoodi Jolfaei Post author

January 21, 2018 at 12:39 pm

Hi Manish,

if you are using an APC stateless application, then this behavior should
not happen, abstractly speaking. It could be that the BAPI runtime
checks some session type specific context information which are not
available in an APC session. That is, if you run a BAPI from withing a
SAPGUI and thus SAPGUI session in SE38 or SE24 in this case the
SAPGUI session has GUI (interaction) capability which is not given in
an APC session. What is the error text of the raised message ? I would
propose to debug both situation, i.e. good and bad case and check what
causes the error.

Cheers,

Masoud

manish sethia

January 21, 2018 at 1:57 pm

Hello Masoud,

Thanks for the reply.

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 47/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

I am trying to use ‘BAPI_PR_CREATE’ to create purchase


requisition. I suspect that it is the same as you suggested.

In the above screenshot, it raises an error at line 33 and


session ends here itself abruptly.

When I call the same BAPI via a report program, the error
is still raised but program continues.

Do you have any idea how this can be avoided?

Thanks,

Manish

Masoud Aghadavoodi Jolfaei Post author

January 21, 2018 at 2:15 pm

Hi Manish,

the E/A/X message handling in ABAP is


context dependent, i.e. E message handling
in SAPGUI ia SE38, is different then in a
Batch Input or an RFC or APC session. For a
detail analysis of the reported issue you have
to open/create a customer message@SAP for
the responsible component, e.g.
purchase requisition. A workaround, which
might help, without knowing the end to end
scenario, is the execution of the BAPI not
locally in APC session but as a synchronous
RFC out of APC session via CALL
FUNCTION ‘BAPI_PR_CREATE’
DESTINATION ‘NONE’.

Good luck !

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 48/49
4/16/2018 ABAP Channels Part 1: WebSocket Communication Using ABAP Push Channels | SAP Blogs

Masoud

manish sethia

January 22, 2018 at 8:43 am

Dear Masoud,

Thanks for your help. I tried with


the suggested approach and it
worked like a charm. I’ll raise an
SAP note for the message part in
APC.

Thanks again for your quick


inputs.

Regards,

Manish

Add Comment

Share & Follow


Privacy Terms of Use Legal Disclosure Copyright Trademark Sitemap Newsletter

https://blogs.sap.com/2013/11/18/websocket-communication-using-abap-push-channels/ 49/49

You might also like