A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

Time:2022-5-6

One advantage of programmers different from other posts is that we can make full use of our programming language to automate some trivial and repetitive daily work through code, so as to save more time to invest in work with higher technical content and improve work efficiency.

This paper introduces an example of work automation realized by ABAP programming language in the actual project work of the author.

Client polling vs web socket API

ABAP channel is a new event driven front and rear communication technology released by NetWeaver 740. The underlying implementation is based on Web socket and TCP socket

The so-called web socket is a technology that opens a two-way interactive communication session between the user’s browser and the server. Using the application programming interface based on Web socket, we can send messages to the server and receive event driven responses without polling the server for replies.

CRM consultants who have worked in SAP CRM call center must be deeply impressed by the polling mechanism of this product. Due to the limitations of technology at that time, whenever an event occurs in the ABAP background, there is no way to notify the foreground webclient UI interface. In order to display the latest data, the front desk has to periodically initiate polling to the ABAP background at a fixed time interval.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

This polling behavior can be easily observed by using the chrome developer tool: the following figure shows that the CRM call center sends an HTTP request to the background every 1 second for polling.

In 2014, NetWeaver 740 released the ABAP channel technology based on the underlying web socket protocol, so the CRM call center also adopted this technology to replace the previous clumsy and inefficient polling solution.

ABAP practitioners often need to use various tracking and performance monitoring tools when doing projects, the most typical of which are ST05 and Sat. the author really believes that these tools are very useful to ABAP developers.

However, at present, all these tools in NetWeaver have one limitation: developers must manually open the tracking mode of the tool and run the application in this mode. After the operation, either turn off the tracking mode manually or automatically by the tool. In other words, none of these tools can provide the information developers need in real time when the application is running.

I participated in the reconstruction and prototype development of the migration of the original CRM one order framework to S / 4hana in Germany.

After the prototype is developed, it has to be tested. I have to perform a series of operations on the new s4crm UI like the old CRM before, and then observe whether the input parameters passed into the API and the output parameters returned by the API are correct.

At first, I set breakpoints in the API and then check them in the ABAP debugger. Soon I found that such efficiency is very low: CRM development consultants know, like CRM_ ORDER_ Maintain / read API has a large number of input and output parameters. In the ABAP debugger, you have to select one and double-click to see it. After reading it, you have to go back and double-click to see another one. If you want to check all the parameters of the API, you need to click the mouse more than 100 times in total.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

What I can’t stand most is this repetitive physical work. Is there any way for NetWeaver to be like the cloudfoundry programming environment of SAP cloud platformcf logs app nameAfter the command, the log generated by the running application will be printed on the browser? have Use ABAP channel

So I started to develop a tool. Let’s see how to use this tool: a BSP application can be accessed in the browser:

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

Then switch directly to the one order application and operate as usual. For example, to create a new service order, maintain the following fields:

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

[external link image transfer failed. The source station may have anti-theft chain mechanism. It is recommended to save the image and upload it directly (img-vxpadurg-164786482811)(https://upload-images.jianshu…)]

Then switch back to the tool I made. The input and output parameters of the one order API have been displayed in the browser in real time. There is no need to carry out cumbersome click operations in the debugger.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

Because it is displayed through the browser, I can also directly use Ctrl + F to search according to keywords, which can’t be done in sapgui.

Here are the detailed development steps of this tool.

  1. Transaction code SAPC, create a new APC (ABAP push channel) application zorder_ LOG_ For APC, the connection type should be websocket.

Click the buttonGenerate Class and ServiceAutomatically generate processing classes and ICF nodes.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

  1. The transaction code SAMC creates a new AMC (ABAP message channel) application named zorderlog.

Maintain the name of ABAP class automatically generated by APC application in the first step under authorization program. The purpose of this step is to specify the name of ABAP processing class for data sending and receiving through websocket in ABAP channel scenario. Channel ID / order_ Write it down.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

  1. From the above figure, I know that I have specified ABAP class CL_ CRM_ ORDER_ Logger is used to send the log generated by the application calling one order API to the web socket. Therefore, this class needs to be programmed in this step.

In the static constructor, pass the AMC ID and channel ID created in step 2 into the producer’s constructor. Indeed, the ABAP channel scenario is a typical producer / consumer model. Messages produced in the ABAP background are sent to the browser through the web socket, which is consumed by the latter.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

The message is sent through the send method below.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

  1. Redefine the on of the processing class automatically generated by APC application in the first step_ Start method:

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

In this method, the APC application created in the first step and the AMC application created in the second step are bound.

  1. To API CRM_ ORDER_ Maintain creates an enhancement to my CL_ CRM_ ORDER_ Logger is injected. In this way, each time the API is called, it will automatically log and send it to the browser through the web socket.

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

The above five steps are the implementation of ABAP channel producer. The following is the development of consumers, that is, web applications running in browsers.

Create a BSP application in index Htm maintain the following code:

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

Line 17 declares the web socket URL for front and back communication:

A small tool based on Web socket developed by ABAP can improve the daily work efficiency of programmers

In this way, the development of Web socket consumers has been completed.

summary

Firstly, this paper introduces the inefficient solution that the browser grabs the response from the server by polling in the traditional call center, which leads to the application scenario of Web socket technology. Then it introduces the pain point that the traditional ABAP performance analysis tool needs to explicitly turn on and off trace mode, and puts forward a new analysis tool based on Web socket technology, which can greatly improve the daily work efficiency of programmers.