使用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

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第1张图片

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.

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第2张图片

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.

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第3张图片

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.

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第4张图片

(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.

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第5张图片

(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.

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第6张图片

The actual send of message is done by the send method of this instance:

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第7张图片

(4) Redefine ON_START method of the APC handler:

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第8张图片

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:

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第9张图片

(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,

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第10张图片

And paste the following HTML source code to it and activate:


  
    
    Jerry's One Order Trace tool using ABAP Channels
    
    
  
  
    
  • {{nameF}}

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

使用ABAP Channel实现一个订单跟踪工具,提高日常工作效率_第11张图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":

你可能感兴趣的:(abap,erp,crm,sap,saprfc)