Ansicht
Dokumentation

ABENAPC_ABEXA - APC ABEXA

ABENAPC_ABEXA - APC ABEXA

General Material Data   TXBHW - Original Tax Base Amount in Local Currency  
This documentation is copyright by SAP AG.
SAP E-Book

- AS ABAP as WebSocket Server

This example demonstrates ABAP push channels in AS ABAP as a WebSocket server.

Source Code

Execute

Description

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

  • Is a stateful service used when the subprotocol PCP is used?

The Web page is provided by an ICF HTTP service whose URL is constructed in the program for the current . If the standard browser called 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 makes 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 of the AS ABAP. This file provides the client-side framework for using this protocol. This API is not needed if PCP is not used. If the PCP protocol is used, it is possible to access both a stateless ABAP channel and a stateful ABAP channel.
  • The ABAP push channel DEMO_APC, DEMO_APC_PCP, or DEMO_APC_PCP_STATEFUL from the package SABAPDEMOS in the current AS ABAP, where the latter two support the Push Channel Protocol (PCP) and the latter is stateful. 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. 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 AMC. The APC handler class CL_APC_WSP_EXT_DEMO_APC_PCP_ST demonstrates a stateful service by simply calling the identically named methods of an object of the class CL_APC_WSP_EXT_DEMO_APC_PCP. The AMC used here is /demo_text or /demo_pcp from the executable examples for AMC. 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. CL_APC_WSP_EXT_DEMO_APC_PCP demonstrates the stateful service by raising a counter whose value stays the same in stateless services, but changes in the stateful service.

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

Note

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






Addresses (Business Address Services)   RFUMSV00 - Advance Return for Tax on Sales/Purchases  
This documentation is copyright by SAP AG.

Length: 6013 Date: 20240425 Time: 070353     sap01-206 ( 121 ms )