Skip to content

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

APC, AS ABAP as Attached Client

This example demonstrates the AS ABAP as an attached client for a detached client.

Other versions: 7.31 | 7.40 | 7.54

Source Code

REPORT demo_apc_attach_client.

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 ).
    DATA amc TYPE abap_bool VALUE ' '.
    cl_demo_input=>add_field( EXPORTING as_checkbox = 'X'
                              CHANGING field  = amc ).
    DATA close TYPE abap_bool VALUE ' '.
    cl_demo_input=>add_field( EXPORTING as_checkbox = 'X'
                              CHANGING field  = close ).
    cl_demo_input=>request( ).

    TRY.
        "Attached client
        DATA(client_attach) =
          cl_apc_wsp_client_conn_manager=>attach( attach_handle ).
        DATA(message_manager) =
          CAST if_apc_wsp_message_manager_pcp(
            client_attach->get_message_manager( ) ).
        DATA(message) = CAST if_ac_message_type_pcp(
          message_manager->create_message( ) ).
        TRY.
            IF amc = abap_true.
              message->set_field( i_name = 'amc' i_value = 'x' ).
            ENDIF.
            message->set_field(
              i_name = 'detached_client' i_value = 'x' ).
            message->set_text( msg ).
          CATCH cx_ac_message_type_pcp_error INTO DATA(pcp_error).
            cl_demo_output=>display( pcp_error->get_text( ) ).
            LEAVE PROGRAM.
        ENDTRY.
        message_manager->send( message ).
        IF close  = abap_true.
          client_attach->close(
            i_reason = 'Application closed connection!' ).
        ENDIF.
      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 connection handle as input, as provided in the output of the executable detached client example. The connection handle is used to create and employ an attached client object precisely as described in the detached client example. The connection handle can be reused indefinitely until the connection is closed using the method CLOSE. If the connection is not closed by mistake, this can be done later in the transaction SMWS.