使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率-阿里云开发者社区

开发者社区> 开发者小助手-bz4> 正文

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率

简介: 使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率
+关注继续查看

There are already many nice blogs introducing nice features provided by ABAP channels in community, for example ABAP Channels Examples.


In that blog some demo examples are explained. After going through those impressive tutorials and demos, have you ever thought about building some useful stuff for your daily work by leverage this powerful feature in ABAP?


As ABAPers we use various trace / monitor tools in our daily work, such as SAT and ST05. And in CRM, all business transactions are managed by so called One Order framework. This framework uses function module CRM_ORDER_MAINTAIN to create, update and delete the document.


Just look at this long list of importing parameters



image.png



As an CRM application developer I have to frequently check what data has been put into these importing parameters during my development and trouble shooting life. I am so lazy that sometimes for minor issue I am reluctant to open ABAP Debugger. Instead I use the trace tool: One order trace tool CRMD_TRACE_SET.


This trace tool still has some drawback: when I perform the operation under trace mode, it is impossible for me to review the trace result in the real time. In order to see the trace result, I have to terminate the trace and then review the result in SAPGUI.


Is there any more convenient way to see the trace data in real time? Yes, it is time now to practice using ABAP Channel.


I have built another trace tool on my own. Let’s first see what feature it can support:


(1) Open the trace monitor in browser, which is a BSP application:



image.png


image.png(2) Go to your application to be traced and perform the operation as usual.

In my example, I create a new service order, and maintain fields like Description, External Reference, Priority, Pricing Date and Currency.



image.pngSwitch to my monitor application, all trace data are displayed in the real time


Since now all trace data are displayed directly in browser, it is much easier for me to search some data I am interested using text search than searching something in SAPGUI.



image.png


image.pngHere below is the step by step how to build this tool.


(1) tcode SAPC, create a new APC application, in my example my APC application name: ZORDER_LOG_APC.

Click button “Generate Class and Service” to generate handler class and ICF node automatically. You can refer to my setting below.


image.png(2) tcode SAMC, create an AMC application ZORDERLOG.


Maintain the automatically generate class from step 1 into Authorization Program column.

So far all modelling task are done.



image.png

image.png(3) Implement class CL_CRM_ORDER_LOGGER, which will be responsible to send the logged data to a web socket.


In the class_constructor, I get a message producer instance by passing the AMC application id and channel id which are created in step2.


image.png

image.pngThe actual send of message is done by the send method of this instance:image.png(4) Redefine ON_START method of the APC handler:image.png

In this method we just bind this APC application with AMC application we created in step 2.METHOD if_apc_wsp_extension~on_start.

   DATA: lo_request TYPE REF TO if_apc_ws_initial_request.

   DATA: lo_binding TYPE REF TO if_apc_ws_binding_manager.

   DATA: lx_error   TYPE REF TO cx_apc_error.

   DATA: lv_message TYPE string.

   TRY.

       lo_request = i_context->get_initial_request( ).

       lo_binding = i_context->get_binding_manager( ).

       lo_binding->bind_amc_message_consumer( i_application_id = 'ZORDERLOG'

                                              i_channel_id     = '/order_log' ).

     CATCH cx_apc_error INTO lx_error.

       lv_message = lx_error->get_text( ).

       MESSAGE lv_message TYPE 'E'.

   ENDTRY.

 ENDMETHOD.For method ON_MESSAGE, we can just keep it as empty.


(5) I create an enhancement on function module CRM_ORDER_MAINTAIN to inject my logger API there:



image.png

image.pngimage.png(6) In this last step, build an BSP application where a websocket is created to listen to the message sent from ABAP.


Create an BSP application with one page index.htm,


image.png

image.pngAnd paste the following HTML source code to it and activate:

 

   

   Jerry's One Order Trace tool using ABAP Channels

   

   </div><div data-lake-id="9e3a862462ca3c215701ebd53ac2f68d">      var nameApp = angular.module('nameApp', []);</div><div data-lake-id="10fceec95fe68cd0162a09ff5ed0ea1d">      nameApp.controller('NameCtrl', function ($scope){</div><div data-lake-id="9c50e87ce29f4a0892322bf5b6773e41">      function getCurrentTime(){</div><div data-lake-id="785a01c0a750d2e0cc776319261a4157">         return new Date().toLocaleString();</div><div data-lake-id="79d2bf08577ab5793511b3bbd73be05b">      }</div><div data-lake-id="000c9c698106c0514cb6c3cd4c18dbe6">      (function init(){</div><div data-lake-id="a8514dfe18df9c3f0e652f2359f58a69">        $scope.Ionames = ['Jerry\'s One order log tool'];</div><div data-lake-id="a9af006a21d46b13d6c587cdd6704b1e">        var startTime = 'Trace Start Time:' + getCurrentTime();</div><div data-lake-id="a8912390dbb3f3e60721287e78b4ef7c">        $scope.Ionames.push(startTime);</div><div data-lake-id="ffe368eeb3098413a81b795712dfca12">        var that = $scope;</div><div data-lake-id="a1d45b86e15f3d8bdca47e7a1997b564">        var sUrl = "wss://<host>:44300/sap/bc/apc/sap/zorder_log_apc";</div><div data-lake-id="6a6af6046d3026c53a2d4a03b1376f88">        var ws = new WebSocket(sUrl);</div><div data-lake-id="8dc4c30d72917f3b976c95b402625b8b">        var onMessage = function(evt){</div><div data-lake-id="aca650ba7cdb8d19d652888cd64b82ba">            this.Ionames.push(getCurrentTime( ) + ':' + evt.data);</div><div data-lake-id="3a8ca7aec4bb806fac10f5ce8d64a42e">            this.$apply()</div><div data-lake-id="cff27b1c25e12be22029ce022108698a">        };</div><div data-lake-id="a0a2826d1e36628f9b4618793a54a491">        ws.onmessage = onMessage.bind($scope);</div><div data-lake-id="8acf21659273b6d1b1d6fa2f376b4f9c">      })();</div><div data-lake-id="10264c024dc5381894e7a13166974a79">      });</div><div data-lake-id="ffa251db7bb31e98ecd2320576e519ee">    

 

 

   

         

  • {{nameF}}
  •    

     

    You only need to use your own APC application url when creating Web socket instance.



    image.png

    版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

    相关文章
    阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
    如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
    9380 0
    使用简单的Java代码在SAP C4C里创建销售订单
    需要创建的销售订单的明细通过硬编码指定: 比如销售订单的描述为Jerry Test 2019-1-23 16:05PM 执行之后,看到Status Code 201,说明创建成功: 到UI上能看到成功创建的销售订单: 实现代码: package odata; import java.
    1043 0
    阿里云服务器如何登录?阿里云服务器的三种登录方法
    购买阿里云ECS云服务器后如何登录?场景不同,大概有三种登录方式:
    2913 0
    使用简单的Java代码在SAP C4C里创建销售订单
    使用简单的Java代码在SAP C4C里创建销售订单
    6 0
    阿里云服务器端口号设置
    阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
    10797 0
    使用OpenApi弹性释放和设置云服务器ECS释放
    云服务器ECS的一个重要特性就是按需创建资源。您可以在业务高峰期按需弹性的自定义规则进行资源创建,在完成业务计算的时候释放资源。本篇将提供几个Tips帮助您更加容易和自动化的完成云服务器的释放和弹性设置。
    12010 0
    SAP S/4HANA使用ABAP获得生产订单的状态
    SAP S/4HANA使用ABAP获得生产订单的状态
    15 0
    阿里云ECS云服务器初始化设置教程方法
    阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
    11484 0
    阿里云ECS云服务器初始化设置教程方法
    阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
    6871 0
    2315
    文章
    0
    问答
    来源圈子
    更多
    + 订阅
    文章排行榜
    最热
    最新
    相关电子书
    更多
    《2021云上架构与运维峰会演讲合集》
    立即下载
    《零基础CSS入门教程》
    立即下载
    《零基础HTML入门教程》
    立即下载