ABAP CHANNELS DEMOS

ABAP CHANNELS DEMOS
ABAP Channels in Developer Edition AS ABAP 7.5
December 2015
Olga Dolinskaja / SAP SE
ABAP Channels in Developer Edition AS ABAP 7.5
TABLE of Contents
TABLE of Contents .............................................................................................................................................. 2
A.INTRODUCTION ................................................................................................................................................... 3
GENERAL INFORMATION .................................................................................................................................... 3
MOTIVATION ...................................................................................................................................................... 3
B. DEMO ABAP PUSH CHANNEL (APC) ................................................................................................................... 4
INTRODUCTION .................................................................................................................................................. 4
DEMO ................................................................................................................................................................. 4
SUMMARY ........................................................................................................................................................ 11
C. DEMO ABAP MESSAGING CHANNEL (AMC) .................................................................................................... 12
INTRODUCTION ................................................................................................................................................ 12
DEMO ............................................................................................................................................................... 12
SUMMARY ........................................................................................................................................................ 15
D. DEMO COLLABORATION USING ABAP CHANNELS .......................................................................................... 16
INTRODUCTION ................................................................................................................................................ 16
DEMO ............................................................................................................................................................... 16
SUMMARY ........................................................................................................................................................ 19
2
ABAP Channels in Developer Edition AS ABAP 7.5
A.INTRODUCTION
General information
Welcome to the ABAP Channels demos in the Developer Edition of AS ABAP 7.5. In this document
you will find descriptions about how to use:
B. Demo ABAP Push Channel (APC)
C. Demo ABAP Messaging Channel (AMC)
D. Demo collaboration using ABAP Channels
Before you start, here is some technical information on the prerequisites, demo packages, etc. that
you will use:
Integrated Development
Environment (IDE)
ABAP Development Tools
Eclipse Mars 1(4.5.1)
ABAP Development Tools 2.51
UI Development Kit for HTML5
SAPUI5 ABAP Repository Team
Provider
ABAP System
UI Development Kit for HTML5 1.32
ABAP Client
001
ABAP Username
DEVELOPER
ABAP Channels Demo Package
DEMO_CHANNELS
SAPUI5 application
ZAPC_CHAT
SAPUI5 ABAP Repository Team Provider 1.32
A4H
Motivation
Most ABAP applications use polling techniques to achieve an event-driven communication. For
pushing an event from an ABAP backend to a browser based user agent like SAPUI5, Web Dynpro
ABAP, Business Server Pages (BSP) or WebGUI, the polling in multi-seconds interval is frequently
used. This is a quite system resource consuming technique. The ABAP Channels technology targets
to replace such inefficient eventing based on polling techniques through Web Sockets (ABAP Push
Channel) and publish/subscribe mechanism (ABAP Messaging Channel).
Now, enjoy the demos!
3
ABAP Channels in Developer Edition AS ABAP 7.5
B. DEMO ABAP PUSH CHANNEL (APC)
Introduction
Immediate access on UI to the frequently changing business information and data in ABAP backend
will support timely business insights, decision making and productivity.
The examples for this can be for instance bringing the irregularly and often changing product
information and sale conditions to browser UI (SAPUI5, Web Dynpro ABAP, BSP) as soon as data
change takes place in the ABAP backend, pushing short-lived financial data relevant for trades to the
browser UI, statistics, process information (sales figures in different areas, financial statistics,
manufacturing process status). In all these cases the data presentation on UI (charts, diagrams, text
and numbers) must be updated immediately accordingly to the modified data in the ABAP backend.
In such situations in order to present the latest up-to-date information from the ABAP backend in realtime on the browser based UI most ABAP applications used polling techniques with multi-seconds
intervals or refresh button periodically to get newest updates to UI. These approaches are quite
resource consuming result in insufficient performance and poor user experience. The availability of
real-time data in ABAP backend is unpredictable and it is unnecessary effort to make requests and
open and close HTTP connections.
The ABAP Push Channel (APC) technology replaces such inefficient polling approach through Web
Sockets. ABAP Push Channel is bi-directional message based communication channel representing
the Web Socket integration in ABAP, allowing e.g.to push notification to the UI as soon as data
change in ABAP backend happens. This is a sign for a user to request the changed data from ABAP
backend and update UI.
For introduction to ABAP Channels please refer to
http://scn.sap.com/community/abap/connectivity/blog/2014/11/27/introduction-to-abap-channels
More detailed information about how to use ABAP Push Channel:
http://scn.sap.com/community/abap/connectivity/blog/2013/11/18/websocket-communication-usingabap-push-channels
Video Tutorials: http://scn.sap.com/community/abap/blog/2015/03/09/how-to-implement-and-use-abapchannels--video-tutorials
Demo
In this demo you can investigate simple SAPUI5 application (Chat program) which uses ABAP Push
Channel as Web Socket communication with ABAP backend system. It works as following. You put
any text into the text field and press the arrow button. The text is sent to the ABAP backend system
over the ABAP Push Channel (Web Socket). The ABAP System enriches the text with date, time and
user and sends it back. The UI displays the text below the text field.
4
ABAP Channels in Developer Edition AS ABAP 7.5
In this demo you can see how
 ABAP Push Channel (APC) is implemented
 ABAP Push Channel is used in the SAPUI5 application
Explanation
Screenshot
1. Start Eclipse, your Integrated
Development Environment
(IDE).
2. Switch to the ABAP perspective
by clicking the Open
Perspective button or using the
Menu Window > Open
Perspective > Other.
3. Create ABAP Project (using
connection data to your ABAP
backend system of the AS
ABAP Developer Edition. File >
New > ABAP Project… and
follow then the suggested
wizard steps.
4. Add DEMO_CHANNELS as
favorite package to your project
(Favorite Packages > Add a
Package)
5
ABAP Channels in Developer Edition AS ABAP 7.5
5. Now create SAPUI5 project for
the UI application. File > New >
Other > SAPUI5 Application
Development > Application
Project and click Next button
6. Enter as project name
ZAPC_CHAT and click Next
button
6
ABAP Channels in Developer Edition AS ABAP 7.5
7. Enter as View name Chat,
choose XML as development
paradigm and click Next button.
On the last wizard screen print
Finish button.
You have created the empty
SAPUI5 project ZAPC_CHAT.
8. Now retrieve the UI application
sources from the SAPUI5
ABAP Repository. In the
Project Explorer mark your
ZAPC_CHAT SAPUI5 Project
and select in the context menu
Team > Share Project.
9. Choose SAPUI5 ABAP
Repository from the list and
click Next button.
7
ABAP Channels in Developer Edition AS ABAP 7.5
10. Select your system connection
using Browse button, click Next
button
Enter your logon data, click
Next button
Select the ZAPC_CHAT BSP
application from the SAPUI5
ABAP Repository and click
Finish button
11. Now retrieve the sources of the
ZAPC_CHAT application from
the SAPUI5 ABAP Repository
using the context menu Team >
Retrieve.
8
ABAP Channels in Developer Edition AS ABAP 7.5
All resources must be selected.
Click Finish button.
12. Now take a look at the ABAP
Push Channel (APC)
ZAPC_CHAT by double-clicking
it or using SAPC transaction
(shortcut Alt+F8 to run ABAP
application in embedded
SAPGUI in Eclipse, type SAPC).
The associated service
/sap/bc/apc/sap/zapc_ch
at (you can find it in the
transaction SICF) and the
corresponding ABAP Push
Channel application class were
generated by Generate Class
and Service button. The service
gets activated automatically
after generation.
The V10.PCP.SAP.COM value
stays for the SAP’s common
message exchange protocol
PCP to exchange messages in
the PCP format.
13. Open the corresponding ABAP
Push Channel class
ZCL_APC_WSP_EXT_ZAPC_CH
AT in the editor and take a look
at the
IF_APC_WSP_EXT_PCP~ON_M
ESSAGE method. The relevant
code lines are on the
screenshot.
The importing parameter of this
method i_message represents
the message which is delivered
through APC. First, the text is
9
ABAP Channels in Developer Edition AS ABAP 7.5
collected from the i_message.
Then the message gets
enriched with author and date
and prepared for the UI display
in the method
prepare_message_for_ui(
). Then the message is sent
back with the
i_message_manager through
APC to the UI.
14. Now examine how the UI part
establishes the WebSocket
connection. In the Project
Explorer navigate to the
onInit()method of the Chat
controller (Chat.controller.js)
and double click it to open in
the editor window. On the
screenshot you see the source
code line, which establishes the
Web Socket connection.
Remark: In the onInit()
method the Web Socket
connection is established to the
registered service
/sap/bc/apc/sap/zapc_ch
at (ABAP Push Channel) with
SAP’s common message
exchange protocol PCP.
Furthermore the callback
function is registered on Web
Socket events and the UI
model is set. If a message
arrives, its data get parsed,
formatted and added as a new
entry to the UI model. By using
unshift() the newest entry
gets displayed on the top of the
list. The method refresh ()
updates the UI model on the
screen.
10
ABAP Channels in Developer Edition AS ABAP 7.5
15. Run ZAPC_CHAT application:
select index.html and execute it
on the ABAP Server: Run As >
Run on ABAP Server.
16. After entering your user and
password you can use the Chat
program. Type text into the text
field and press the ‘arrow’
button. The text gets displayed
on top of the list below the text
field.
Summary
This demo creates the ABAP Push Channel (Web Socket) using the SAPC transaction and uses it in
the SAPUI5 application (Chat program) to exchange the messages through the ABAP Push Channel
between the SAPUI5 application and the ABAP system.
11
ABAP Channels in Developer Edition AS ABAP 7.5
C. DEMO ABAP MESSAGING CHANNEL (AMC)
Introduction
Event-driven communication between ABAP sessions across the boundaries of ABAP application
servers will streamline the business process workflow, speed up performance and reduce the rate of
consumption of database resources. An ABAP application might need to identify and react to certain
events in the other ABAP session as soon as they occur. Moreover an ABAP application might involve
data processing in order to provide some output to be delivered to another application, running in
another ABAP session and therefore has to send notification. Traditionally to realize such real-time
event-driven behavior ABAP applications often poll periodically for the state information on the
database. Bottleneck problems on the database may occur with numerous active polling from many
ABAP applications simultaneously.
Instead of using periodically polling technique, a publish/subscribe mechanism can be used for prompt
notification which can eliminate unnecessary database load. ABAP Messaging Channel (AMC)
infrastructure replaces the polling through publish/subscribe mechanism and acts as a broker for the
message exchange between different ABAP sessions, which can reside on different ABAP application
servers. After ABAP sessions act as publisher and subscribers respectively, as soon as an ABAP
session publishes notification to AMC, all subscriber ABAP sessions get notified.
For introduction to ABAP Channels please refer to
http://scn.sap.com/community/abap/connectivity/blog/2014/11/27/introduction-to-abap-channels
More detailed information about how to use ABAP Messaging Channel:
http://scn.sap.com/community/abap/connectivity/blog/2014/03/26/abap-channels-part-2-publishsubscribe-messaging-using-abap-messaging-channels
Video Tutorials: http://scn.sap.com/community/abap/blog/2015/03/09/how-to-implement-and-use-abapchannels--video-tutorials
Demo
This demo implements communication with the ABAP Messaging Channel (AMC) between two simple
ABAP programs AMC sender and AMC receiver which are executed in two parallel ABAP
sessions. While the AMC receiver program subscribes to the AMC channel /ping and waits for
incoming messages, the AMC sender program sends messages to the AMC channel /ping and the
AMC receiver program receives them.
12
ABAP Channels in Developer Edition AS ABAP 7.5
After executing the AMC message receiver program it shows sand glass and is in the waiting state.
After executing the AMC sender program, the message ‘Hi there!’ is sent through the AMC channel
/ping and the AMC message receiver receives and displays the message on the UI.
In this demo you can see how
 ABAP Messaging Channel is implemented
 ABAP Messaging Channel is used for the communication between two ABAP sessions
Explanation
Screenshot
1. Switch in the Eclipse to the ABAP
Perspective. Under Connectivity of
the package ZDEMO_CHANNELS
you will find within ABAP
Messaging Channels the AMC
application ZAMC_CHAT. Double
click to open it in the embedded
SAPGUI in Eclipse (or use shortcut
Alt+F8 to run ABAP application in
the SAPGUI, type SAMC).
2. Double click the channel /ping.
The authorized programs to send
and receive messages through the
AMC channel /ping are
ZAMC_SEND_MESSAGE_TEXT and
ZAMC_RECEIVE_MESSAGE_TEXT
Remark: In this demo messages
are exchanged in simple text
format (TEXT) within activity
scope client (Client).
13
ABAP Channels in Developer Edition AS ABAP 7.5
3. In the Source Code Library of the
package ZDEMO_CHANNELS you
will find the ABAP programs:
ZAMC_SEND_MESSAGE_TEXT as
AMC sender and
ZAMC_RECEIVE_MESSAGE_TEXT
as AMC receiver.
4. Open the AMC sender program
ZAMC_SEND_MESSAGE_TEXT in
the editor window and take a look
at its implementation. This
program sends out the message
‘Hi there!’ through the AMC.
First the class factory
cl_amc_channel_manager
creates AMC producer object for
the AMC application ZAMC_CHAT
and AMC channel /ping. Then
the message is published with the
provided interface method send()
to the AMC.
5. Open the AMC receiver program
ZAMC_RECEIVE_MESSAGE_TEXT
in the editor window and take a
look at its implementation. This
program acts as a receiver of the
text message sent with AMC. First
the class factory
cl_amc_channel_manager
creates the AMC receiver object
for the AMC application
ZAMC_CHAT and AMC channel
/ping. Receiving messages can
be started with the provided
interface method
start_message_delivery().
To be able to receive messages
the session has to be in an
“interrupted” state and not busy.
This can be achieved in two ways.
Either explicitly with the new ABAP
statement WAIT FOR MESSAGING
CHANNELS <expression> [UP
TO <time> SECONDS] or
implicitly by using e.g. list
processing (PBO-PAI phases). To
receive a message the callback
object has to be provided which
implements the interface receiver
method
if_amc_message_receiver_t
ext~receive(). After the
message arrives, it gets inserted
into a table of the messages.
14
ABAP Channels in Developer Edition AS ABAP 7.5
6. Run ZAMC_SEND_MESSAGE_TEXT
and
ZAMC_RECEIVE_MESSAGE_TEXT
in two Eclipse editor windows
using context menu Run As >
ABAP Application.
7. Split the editor windows to see
both ABAP sessions in parallel and
execute the programs as
described above in the demo (first
receiver and then sender).
Summary
This demo creates ABAP Messaging Channel using SAMC transaction and uses ABAP Messaging
Channel to implement the message communication between two ABAP sessions. ABAP session must
be in the ‘interrupted’ state to receive the messages. This can be achieved either explicitly by using
ABAP WAIT… statement or implicitly by using e.g. list processing. By the way in ABAP exists a number
of statements which provide an implicit interruption, e.g. Dynpro and List processing (PBO-PAI
phases) or COMMIT WORK, etc. and some statements which provide an explicit interruption, i.e. WAIT.
It depends on the logic of the application which kind of interruption should be used for processing of
events.
15
ABAP Channels in Developer Edition AS ABAP 7.5
D. DEMO COLLABORATION USING ABAP CHANNELS
Introduction
Real-time collaboration scenarios allow multiple users in different locations to communicate instantly
or work on the same business objects simultaneously sharing the same backend resources and even
allowing collaborative real-time editing. In situations when multiple users work with the same data (e.g.
customers or suppliers information) in the browser UI, and one user changes some data records, they
must be updated immediately on all other user UIs.
Applying this to ABAP would mean for example SAPUI5 users in different ABAP sessions which
reside on different ABAP application servers can communicate (send messages) and work together on
the same ABAP data records.
For ABAP collaboration scenarios are ABAP Push and Messaging Channels the best choice. The
publish/subscribe infrastructure of the ABAP Messaging Channels can be used with ABAP Push
Channel to enable Web Socket UI clients to act as subscriber. This allows Web Socket UI clients to
send and receive notifications about data changes.
For introduction to ABAP Channels please refer to
http://scn.sap.com/community/abap/connectivity/blog/2014/11/27/introduction-to-abap-channels
More detailed information about collaboration scenario:
http://scn.sap.com/community/abap/connectivity/blog/2014/04/14/abap-channels-part-3-collaborationscenario-using-abap-messaging-and-abap-push-channels
Video Tutorials: http://scn.sap.com/community/abap/blog/2015/03/09/how-to-implement-and-use-abapchannels--video-tutorials
Demo
In this demo the ABAP Push Channel SAPUI5 application from the first demo is changed to implement
chat between users. The collaboration scenario works as following. One user enters the text into the
field and presses the “arrow” button. The text will be sent to the ABAP backend system through ABAP
Push Channel (Web Socket). For this the ABAP Messaging Channel is bound to the ABAP Push
Channel (Web Socket). ABAP session checks the text for errors, enriches it with date, time and user
and acts as a sender and sends it through the ABAP Messaging Channel to the subscribed ABAP
Push Channels of other users and itself. The text is displayed below the field on all users UIs.
16
ABAP Channels in Developer Edition AS ABAP 7.5
In this demo you can see how
 Another ABAP Messaging Channel (AMC) is implemented in the AMC application
 Collaboration is implemented by binding the AMC to your ABAP Push Channel from the
first demo
Explanation
Screenshot
1. Switch in the Eclipse to the
ABAP Perspective. Under
Connectivity of the package
ZDEMO_CHANNELS you will find
in ABAP Messaging Channels
the AMC application
ZAMC_CHAT. Double click to
open it in the embedded
SAPGUI in Eclipse (or use
shortcut Alt+F8 to run ABAP
application in SAPGUI, type
SAMC).
Double click the channel
/chat. This channel is used
for collaboration. The class
ZCL_APC_WSP_EXT_ZAPC_CH
AT is authorized to send and
receive messages through the
/chat.
Remark: In this demo
messages are exchanged in
the PCP format (SAP Push
Channel Protocol) within
activity scope client
(Client).
2. Now open the corresponding
ABAP Push Channel class
ZCL_APC_WSP_EXT_ZAPC_CH
AT in the editor and follow the
‘ATTENTION’ instructions in its
source code to adapt it for
collaboration by commenting
out and uncommenting the
appropriate source code lines.
Save and Activate the APC
class.
17
ABAP Channels in Developer Edition AS ABAP 7.5
3. Now take a look at the
implementation of the APC
class
ZCL_APC_WSP_EXT_ZAPC_CH
AT. For collaboration not only
on_message() but also
on_start() method needs to
be implemented. Navigate to
the on_start() method (e.g.
using Outline view of Eclipse).
4. The on_start() method is
executed as soon as the Web
Socket connection setup phase
is accomplished successfully. It
is implemented to bind the APC
Web Socket connection to the
AMC application ZAMC_CHAT
and channel /chat. The APC
Web Socket client is then able
to act as a message receiver to
get messages through AMC.
5. Navigate to the
on_message() method (e.g.
using Outline view) .The
on_message()method is
executed when the APC class
receives a message. Here the
same code as in the first demo
is used with the only difference.
The ABAP message channel
manager is used to send the
received messages from APC
Web Socket client to the AMC
application ZAMC_CHAT and
channel /chat. The APC Web
Socket client acts as a
message sender.
18
ABAP Channels in Developer Edition AS ABAP 7.5
6. Run ZAPC_CHAT application:
select index.html and execute it
on the ABAP Server: Run As >
Run on ABAP Server.
7. After entering your user and
password you can use the chat
program. Type text into the text
field and press the “arrow”
button. The text gets displayed
on top of the list below the text
field.
8. Start a browser of your choice
(IE, Firefox, Chrome) and copy
& paste the URL of the SAPUI5
application into its URL field.
Run chat program. Any other
user can logon to it. Whenever
one user enters a message in
one SAPUI5 application and
press the “arrow” button, the
message appears on top of the
list under the text field in both
chat programs of both users.
Summary
This demo implements chat program in ABAP as collaboration scenario using ABAP Push and ABAP
Messaging Channels. For the collaboration scenario the Web Socket (ABAP Push Channel)
connection must be bound to the AMC application and ABAP Messaging Channel in order to forward
the AMC messages to Web Socket client. The APC Web Socket client acts as an AMC receiver after
this binding action. The ABAP message channel manager is used to forward the received messages
from Web Socket (ABAP Push Channel) client via the message sender to the AMC application and
ABAP Messaging Channel. The APC Web Socket client acts as a sender in this case.
19
ABAP Channels in Developer Edition AS ABAP 7.5
© 2015 SAP SE or an SAP affiliate company. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE or an SAP
affiliate company. SAP and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered
trademarks of SAP SE (or an SAP affiliate company) in Germany and other countries.
Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.
20