ABAP Keyword Documentation → ABAP − Reference → Data Interfaces and Communication Interfaces → ADF - ABAP Daemon Framework → Examples for ABAP Daemons
ADF, Mini ABAP Daemon
This example demonstrates a mini ABAP Daemon.
Other versions:
7.31 | 7.40 | 7.54
Source Code
TRY.
DATA(pcp) = cl_ac_message_type_pcp=>create( ).
pcp->set_text( `Hello Daemon!` ).
CATCH cx_ac_message_type_pcp_error INTO DATA(pcp_exc).
cl_demo_output=>display( pcp_exc->get_text( ) ).
RETURN.
ENDTRY.
TRY.
cl_abap_daemon_client_manager=>start(
EXPORTING
i_class_name = 'CL_DEMO_ABAP_MINI_DAEMON'
i_name = 'DemoMiniDaemon'
IMPORTING
e_instance_id = DATA(instance_id) ).
cl_abap_daemon_client_manager=>attach(
i_instance_id = instance_id )->send( pcp ).
cl_abap_daemon_client_manager=>stop(
i_instance_id = instance_id ).
CATCH cx_abap_daemon_error INTO DATA(daemon_exc).
cl_demo_output=>display( daemon_exc->get_text( ) ).
RETURN.
ENDTRY.
DATA msg TYPE string.
DATA(subrc) = 4.
WHILE subrc = 4.
IMPORT msg = msg FROM SHARED MEMORY demo_indx_blob(dm)
ID 'DemoMiniDaemon'.
subrc = sy-subrc.
ENDWHILE.
ASSERT msg = `Hello Daemon!`.
cl_demo_output=>display( 'Daemon has received the message' ).
Description
The class CL_DEMO_ABAP_MINI_DAEMON used by the program above demonstrates a mini ABAP Daemon class. It implements only the following methods of the interface IF_ABAP_DAEMON_EXTENSION:
- ON_ACCEPT
TRY.
IF i_context_base->get_start_caller_info(
)-program = 'DEMO_ABAP_MINI_DAEMON'.
e_setup_mode = co_setup_mode-accept.
ENDIF.
CATCH cx_abap_daemon_error.
RETURN.
ENDTRY.
ENDMETHOD.
- ON_MESSAGE
TRY.
DATA(msg) = i_message->get_text( ).
CATCH cx_ac_message_type_pcp_error.
RETURN.
ENDTRY.
EXPORT msg = msg TO SHARED MEMORY demo_indx_blob(dm)
ID 'DemoMiniDaemon'.
ENDMETHOD.
The program DEMO_ABAP_MINI_DAEMON uses ABAP Daemon Manager to do the following:
- Start a daemon based on the class CL_DEMO_ABAP_MINI_DAEMON.
- Send a PCP message using a temporary ABAP Daemon handle.
- Stop the daemon immediately (not a typical step).
It then checks whether the daemon wrote the message to the shared memory.