Skip to Content

In early beginning of implementing Neptune Software in the company I work for during POC and playing with possibilities of Neptune Software and SAPUI5 libraries I was asked to implement few boards (big screen TV) for the warehouse which will help people keeping up to date with the work they should do.

In one warehouse, there was multiple screens which was showing in tabular way important information.
Data model which collected all the necessary information for 4 types of boards was bit heavy and took a bit of time to run.
First implementation was with refreshing boards each defined period (60 sec.).
That mean each board was triggering that heavy calculation with the same set of parameters (warehouse number).

It all worked well and users was happy to have such a nice look and feel boards delivered in such a short time possible by Neptune Software and ABAP collector (data model).

After a while we received complains about long time it takes application to refresh data because of heavy logic behind data model.

That’s when my idea came up to try ABAP channels which I checked before but never had chance to use it in productive way.

Bellow you can find step by step creation of simple ABAP Channels required for simple Neptune application which use “push” not “pull” methodology.

You can imagen using that type of programing and ABAP Channels (WebSockets) for any other type of update client from back-end – notification, tiles information, KPI dashboards, graphs etc.

For example, one program run periodically as job collecting data for boards and sending them to registered apps (screens) no matter how many of they are.

Many information about ABAP Channels you can find here:

You can always refer to SAP documentation as well.

Example below is the simplest and with minimum effort to show that it’s working.
Not everything is implemented to the end but to have a clue about it you can re-create that example in your own system.

I assume you are familiar with Neptune Software (/NEPTUNE/DESIGNER etc.) and ABAP (se80, se24 etc).

It’s running on Neptune 4.0 SP02.

ABAP stack: 7.4 SP09.

1. Create ABAP Messaging Channel

Go to transaction SE80.
Name: YAC_NAD_SFLIGHT_AMC

community.neptune-software.com-2a03cf55cd06e47df0396d52d8c69ffff11d8eb4.png
community.neptune-software.com-68b13a2ecf57425ae734c8fba22fba94f11a5470.png

  • Channels with “/sflight”
  • Message Type ID: TEXT
  •  Activity Scope: S – System

2. Create ABAP Pusch Channel
Name: YAC_NAD_SFLIGHT_APC

community.neptune-software.com-2c204bd2abff1c920e20514cfb67abc2b70f824e.png

Generate Class and Service

community.neptune-software.com-37701c688b4343b96d30a1be9d4826c61c3df5c8.png

3. Edit generated class and redefine methods:
– ON_START
TRY.
* * * * bind the WebSocket connection to the AMC channel
DATA(lo_binding) = i_context->get_binding_manager( ).
lo_binding->bind_amc_message_consumer( i_application_id = ‘YAC_NAD_SFLIGHT_AMC’
i_channel_id = ‘/sflight’ ).
CATCH cx_apc_error INTO DATA(lx_apc_error).
DATA(lv_message) = lx_apc_error->get_text( ).
MESSAGE lx_apc_error->get_text( ) TYPE ‘E’.
ENDTRY.

– ON_MESSAGE – leave empty

4. Edit created ABAP messaging channel and add created class to authorized programs

community.neptune-software.com-1f88f35b47854a993f77c793d41088d66341c9a4.png

5. Create class for Neptune application
Name: YAC_CL_NAD_PUSH_SFLIGHT_DEMO
Add interface to class: /NEPTUNE/IF_NAD_SERVER

community.neptune-software.com-c3f9c674498cdef8c25c300df779fc1db1c95d6a.png

6.  Add public attribute to class

community.neptune-software.com-0420acfde0a902ce482e71f956f8072aec858098.png

7. Create Neptune application

Name: YAC_NAD_PUSH_SFLIGHT_DEMO

8. Add created class to Neptune app definition

community.neptune-software.com-5931c2da7118105b23eee972e3c45da4c770ebd7.png

9. Create simple app with sap.m.table to display data
– bind public attribute defined in the class
– create columns with the wizard to display data

community.neptune-software.com-64fceb179697b2c075761d09912956833713ee69.png

10. Add oPageHidden with Init

community.neptune-software.com-e203310ae5ed2f3555a8e4aeb677f0513660c5a0.png

// BeforeDisplay
if (sap.n) {

sap.n.Shell.attachBeforeDisplay(function() {

});

}
// InitLoad
sap.ui.getCore().attachInit(function() {
setTimeout(function() {
initWS(); // init registration to push channel
}, 100);
});

In attachInit we calling defined function in the script added in next step

11. Add Functions script to oPageHidden

community.neptune-software.com-99cbb48ec3cc3adea7159b857ba722b4b7abd33f.png

JavaScript function here register to WebSocket and have defined function when the messaged is pushed by ABAP Channels.
As we defined the ABAP channels to receive simple text we will create later program which will send JSON string to application and here we use it after receiving it to update data model of the table in the Neptune app.

12. Run the app in the browser.
Should look like this.
community.neptune-software.com-b2fe714db345379928c05e8a93495e3251f2b330.png

Run it in 2 separate windows. You can try to run it on different computers etc.

13. Go to transaction SMWS and click second button from the left -> System Wide List

community.neptune-software.com-d605275333e978804a2460450d4023ffb0064c30.png

You can see your app registered on the server.

14. Create program which will send data via push channel to registered applications

community.neptune-software.com-6556cdc91970f15826520679721a6931faee3aed.png

Name: YAC_PUSH_SFLIGHT_DEMO

*&———————————————————————*

*& Report YAC_PUSH_SFLIGHT_DEMO

*&

*&———————————————————————*

*&

*&

*&———————————————————————*

REPORT YAC_PUSH_SFLIGHT_DEMO.

DATA: lo_producer TYPE REF TO if_amc_message_producer_text,

lv_json TYPE string.

DATA: lt_sflight type FLIGHTTAB.

START-OF-SELECTION.

” selecting data

select * from sflight into table lt_sflight.

” serialization of table to JSON

lv_json = /ui2/cl_json=>serialize(

data = lt_sflight

compress = abap_false

pretty_name = /ui2/cl_json=>pretty_mode-none ).

” “TRANSLATE lv_json to UPPER CASE.

TRY.

lo_producer ?= cl_amc_channel_manager=>create_message_producer(

i_application_id = ‘YAC_NAD_SFLIGHT_AMC’

i_channel_id = ‘/sflight’ ).

lo_producer->send( i_message = lv_json ).

CATCH cx_amc_error INTO DATA(lx_amc_error).

RETURN.

ENDTRY.

16. Run program YAC_PUSH_SFLIGHT_DEMO
Watch magic happening -> your table will be update from the backend via web socket (Push channel) in all the clients.

community.neptune-software.com-ed487ff247b46dc398f3c9a276d25b36c57e7a5a.png

To report this post you need to login first.

1 Comment

You must be Logged on to comment or reply to a post.

Leave a Reply