Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Data Interfaces and Communication Interfaces →  ABAP Channels →  APC - ABAP Push Channels 

APC, WebSocket Communication

This example demonstrates WebSocket communication using ABAP push channels.

Other versions: 7.31 | 7.40 | 7.54

Source Code

    IF url IS INITIAL.
    DATA amc TYPE abap_bool VALUE 'X'.
    cl_demo_input=>add_field( EXPORTING as_checkbox = 'X'
                              CHANGING field  = amc ).
    DATA pcp TYPE abap_bool VALUE ' '.
    cl_demo_input=>add_field( EXPORTING as_checkbox = 'X'
                              CHANGING field  = pcp ).
    cl_demo_input=>request( ).
    amc = to_upper( amc ).
      |<html>| &&
      |<body>| &&
      |<a href="{ COND string( WHEN pcp IS INITIAL THEN url
                               ELSE url && `_pcp` )
        }?sap-client={ sy-mandt
        }&sap-language={ cl_i18n_languages=>sap1_to_sap2( sy-langu )
        }{ COND string( WHEN amc = abap_true
             THEN `&amc=x`
             ELSE `` )
        }" target="_blank">| &&
        |Open demo web page with standard browser</a>

| &&
      |If your browser does not support WebSocket, | &&
      |copy the URL to another browser.| &&
      |</body>| &&
      |</html>| ).


This example demonstrates bidirectional communication between a browser that supports the WebSocket protocol and AS ABAP. The example program above has the task of displaying a Web page that communicates with an APC in the current AS ABAP. It is possible to specify the following:

The Web page is provided by an ICF HTTP service whose URL is constructed in the program for the current application server. If the standard browser does not support communication using the WebSocket protocol, the URL must be opened using a suitable browser instead.

The communication partners are:

  • The Web pages generated in the HTTP request handler CL_HTTP_EXT_APC_DEMO or CL_HTTP_EXT_APC_PCP_DEMO. One Web page makes it possible to open a WebSocket object without Push Channel Protocol (PCP) support and the other Web page make it possible to open a WebSocket object with the support of this protocol. Both Web pages make it possible to send messages using the object and to close the object. These tasks are performed by a JavaScript function implemented in the Web page. If PCP is used, a JavaScript file sap-pcp-websocket.js is included from the Mime repository in AS ABAP. This file provides the client-side framework for using this protocol.
  • The ABAP push channel DEMO_APC or DEMO_APC_PCP from the package SABAPDEMOS in the current AS ABAP (with the latter supporting the Push Channel Protocol (PCP)). The URL of the service assigned to the push channel is used in the JavaScript function of the associated Web page to open the WebSocket communication of this Web page. The form field amc is passed further. The APC handler classes CL_APC_WS_EXT_DEMO_APC and CL_APC_WSP_EXT_DEMO_APC_PCP implement the methods ON_START and ON_MESSAGE of the interface IF_APC_WSP_EXTENSION for communication with and without a connection to an ABAP messaging channel. The AMC used here is /demo_text or /demo_pcp from the AMC examples. When a message is received, the method ON_MESSAGE creates a new message with information about the received message and sends it. If PCP is not used, a text message is sent. In the version for PCP, this protocol is used.

If the ABAP push channel is opened using the form field amc=x, communication takes place using AMC. Every Web page bound to the push channel receives every message sent using AMC. In the example, this means that the message sent by ON_MESSAGE is not just received by the Web page that sent a message. Furthermore, the Web pages bound to the push channel receive messages sent, for example, using the program DEMO_SEND_AMC from the example Sending AMC Messages. Conversely, the program DEMO_RECEIVE_AMC receives the messages sent from the Web pages from the example Receiving AMC Messages.


  • Before this example can work, the protocols WEBSOCKET and WEBSOCKETS must be specified as active services in the Services function in the transaction SMICM.

  • The program DEMO_APC_PING_PONG calls Web pages and an ABAP program that use APC and AMC to play ping pong.