Skip to content

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

APC, System-Wide Access

This example demonstrates access to any ABAP channel using a connection handle.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_apc_access_connection.

CLASS apc_demo DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS main.
ENDCLASS.

CLASS apc_demo IMPLEMENTATION.
  METHOD main.
    DATA attach_handle TYPE string VALUE ' '.
    cl_demo_input=>add_field( CHANGING field  = attach_handle ).
    DATA(msg) = `Hello APC!`.
    cl_demo_input=>add_field( CHANGING field = msg ).
    cl_demo_input=>request( ).

    TRY.
        DATA(access_object) =
          cl_apc_wsp_client_conn_manager=>attach( attach_handle ).
        DATA(message_manager) =
          CAST if_apc_wsp_message_manager(
            access_object->get_message_manager( ) ).
        DATA(message) = CAST if_apc_wsp_message(
          message_manager->create_message( ) ).
        message->set_text( msg ).
        message_manager->send( message ).
      CATCH cx_apc_error INTO DATA(apc_error).
        cl_demo_output=>display( apc_error->get_text( ) ).
        LEAVE PROGRAM.
    ENDTRY.
  ENDMETHOD.
ENDCLASS.

START-OF-SELECTION.
  apc_demo=>main( ).

Description

The program expects a valid connection handle for a WebSocket connection as its input, creates an access objects for this handle, and uses it to send a simple text message.

An APC connection from the executable example AS ABAP as WebSocket Server publishes its connection handle as follows:

  • Create a WebSocket server without PCP.
  • Open the connection on the Web page.
  • Send the text message "get handle".

This message is identified in the method ON_MESSAGE of the APC handler class CL_APC_WS_EXT_DEMO_APC and the connection handle is fetched and sent. The Web page displays it in a form that can be copied. If the connection handle is passed to the program above while the connection is open, the message sent by the program is received and displayed by the Web page.