使用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>      var nameApp = angular.module('nameApp', []);</div><div>      nameApp.controller('NameCtrl', function ($scope){</div><div>      function getCurrentTime(){</div><div>         return new Date().toLocaleString();</div><div>      }</div><div>      (function init(){</div><div>        $scope.Ionames = ['Jerry\'s One order log tool'];</div><div>        var startTime = 'Trace Start Time:' + getCurrentTime();</div><div>        $scope.Ionames.push(startTime);</div><div>        var that = $scope;</div><div>        var sUrl = "wss://<host>:44300/sap/bc/apc/sap/zorder_log_apc";</div><div>        var ws = new WebSocket(sUrl);</div><div>        var onMessage = function(evt){</div><div>            this.Ionames.push(getCurrentTime( ) + ':' + evt.data);</div><div>            this.$apply()</div><div>        };</div><div>        ws.onmessage = onMessage.bind($scope);</div><div>      })();</div><div>      });</div><div>    

 

 

 

       

  • {{nameF}}
  •  

     

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



    image.png

    相关文章
    |
    2月前
    |
    BI
    工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示
    工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示
    工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示
    |
    2月前
    |
    数据库
    ABAP 泛型编程实战 - 分享一个数据库表内容的拷贝工具试读版
    ABAP 泛型编程实战 - 分享一个数据库表内容的拷贝工具试读版
    |
    2月前
    |
    JSON 数据格式
    第三方系统或者工具通过 HTTP 请求发送给 ABAP 系统的数据,应该如何解析试读版
    第三方系统或者工具通过 HTTP 请求发送给 ABAP 系统的数据,应该如何解析试读版
    |
    2月前
    |
    BI 网络安全
    如何使用 ABAPGit 在 SAP ABAP 系统安装 abap2xlsx 工具试读版
    如何使用 ABAPGit 在 SAP ABAP 系统安装 abap2xlsx 工具试读版
    解答 ABAP FM IBAPI_ALM_ORDER_RELEASE 在释放订单之前的状态检查问题
    解答 ABAP FM IBAPI_ALM_ORDER_RELEASE 在释放订单之前的状态检查问题
    解答 ABAP FM IBAPI_ALM_ORDER_RELEASE 在释放订单之前的状态检查问题
    |
    2月前
    |
    BI
    工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示试读版
    工具分享 - 将一个 ABAP Function Group 内所有 Function Module 按照代码行数从高到低排序并显示试读版
    |
    2月前
    |
    Linux
    一个能够在 ABAP 服务器执行 linux 命令的小工具
    一个能够在 ABAP 服务器执行 linux 命令的小工具
    |
    2月前
    |
    搜索推荐 机器人 数据建模
    使用 ChatGPT Store 里的工具给 ABAP 制作 Logo,效果一般
    使用 ChatGPT Store 里的工具给 ABAP 制作 Logo,效果一般
    |
    9月前
    |
    XML 存储 中间件
    根据指定关键字搜索指定时间范围内的 SAP CRM 中间件 BDOC 的 ABAP 小工具分享
    根据指定关键字搜索指定时间范围内的 SAP CRM 中间件 BDOC 的 ABAP 小工具分享
    |
    9月前
    |
    存储 BI 开发者
    SAP ABAP Dump Analysis(ST22) 工具的使用和背景介绍试读版
    SAP ABAP Dump Analysis(ST22) 工具的使用和背景介绍试读版