使用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
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:
(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.
Switch 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.
Here 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.
(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.
(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.
The actual send of message is done by the send method of this instance:
(4) Redefine ON_START method of the APC handler:
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:
(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,
And paste the following HTML source code to it and activate:
<html ng-app="nameApp">
<head>
<meta charset="utf-8">
<title>Jerry's One Order Trace tool using ABAP Channels</title>
<script src="https://i042416.github.io/FioriODataTestTool2014/WebContent/angular/angular.js"></script>
<script>
var nameApp = angular.module('nameApp', []);
nameApp.controller('NameCtrl', function ($scope){
function getCurrentTime(){
return new Date().toLocaleString();
}
(function init(){
$scope.Ionames = ['Jerry's One order log tool'];
var startTime = 'Trace Start Time:' + getCurrentTime();
$scope.Ionames.push(startTime);
var that = $scope;
var sUrl = "wss://<host>:44300/sap/bc/apc/sap/zorder_log_apc";
var ws = new WebSocket(sUrl);
var onMessage = function(evt){
this.Ionames.push(getCurrentTime( ) + ':' + evt.data);
this.$apply()
};
ws.onmessage = onMessage.bind($scope);
})();
});
</script>
</head>
<body ng-controller="NameCtrl">
<ul>
<li ng-repeat="nameF in Ionames">{{nameF}}</li>
</ul>
</body>
</html>
You only need to use your own APC application url when creating Web socket instance.
- 关于EF Code First模式不同建模方式对建表产生的影响
- C# 命名空间和程序集
- C# new关键字和对象类型转换(双括号、is操作符、as操作符)
- 防止小程序多次点击跳转解决方案
- 详述 SQL 中的 distinct 和 row_number() over() 的区别及用法
- Web API系列之三 基本功能实现
- 微信小程序的省市选择组件 citySelector分享
- 详述 Java 语言中的 String、StringBuffer 和 StringBuilder 的使用方法及区别
- Class与Style绑定
- 机器学习并不难
- android的RadioGroup讲解
- asp.net MVC 应用程序的生命周期
- 091031 T PowerShell Solution
- Rafy 框架 - 通用查询条件(CommonQueryCriteria)
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法