The ABAP push channel (APC) is the ABAP implementation of websockets. It’s goal is to enable the ABAP stack to send push messages to registered web clients.
This blog will answer the following questions:
- How to setup an ABAP push channel?
- How to implement the ABAP push channel?
- How to test the ABAP push channel?
- Where to find more background and examples on ABAP push channel?
Setting up an ABAP push channel
To setup an ABAP push channel go to transaction SE80 and right click, select create / connectivity / ABAP push channel notification.
Now press the Generate Class and Service button. The classes and services will now be generated as placeholders. Save your work.
If you try to activate the service at this point in time you get this error message:
The reason is that we didn’t implement two methods of the new class yet: the ON_START and ON_MESSAGE.
Implementing the actual APC class
To do this, we go to SE24 and lookup the generated class and we select the ON_START method:
Press the redefine button to redefine the method.
Use this code in the method:
TRY. * send the message on WebSocket connection DATA(lo_message) = i_message_manager->create_message( ). lo_message->set_text( |ON_START has been successfully executed !| ). i_message_manager->send( lo_message ). CATCH cx_apc_error INTO DATA(lx_apc_error). MESSAGE lx_apc_error->get_text( ) TYPE 'E'. ENDTRY.
This basically confirms the push channel registration.
Now redefine the ON_MESSAGE method:
TRY. * create the message object DATA(lo_message) = i_message_manager->create_message( ). * send message lo_message->set_text( |Hello World !| ). i_message_manager->send( lo_message ). CATCH cx_apc_error INTO DATA(lx_apc_error). MESSAGE lx_apc_error->get_text( ) TYPE 'E'. ENDTRY.
It simply pushes the message: ‘Hello World’.
Save and generate the class in SE24.
Now we can go back to the SE80 ABAP push channel we have created and activate it as well. You can run the consistency check to see all is fine:
Testing the ABAP push channel
Now you can test the ABAP push channel by hitting the test button in the SE80 screen of the ABAP push channel. The test service will launch an ABAP webdynpro screen.
If the ABAP webdynpro screen does not launch, activate in SCIF transaction the following 2 nodes: WDR_TEST_APC and WDR_TEST_APC_WSP.
As an alternative to SE80 you can also use transaction SAPC:
Excellent blogs on ABAP push channels are: