`
JerryWang_SAP
  • 浏览: 1043541 次
  • 性别: Icon_minigender_1
  • 来自: 成都
文章分类
社区版块
存档分类
最新评论
阅读更多

In tcode SWO1 we can find for example business object BUS1178 has defined several events.

 

 

When you create a new product and save it from WebClient UI, this BOR type will be raised in the following callstack:

 

 

COM_PR_CHBADI_RAISE_WF_EVENT will call SWE_EVENT_CREATE_IN_UPD_TASK in update task.

 

 

In update task execution, BOR event will be raised by SWE_EVENT_CREATE. The guid of created product is available in variable objkey.

 

 

So how to react to this BOR event published by function module SWE_EVENT_CREATE? tcode SWE2, just create a new entry for this BOR event:

 

 

Maintain a function module as event listener:

 

 

As I would like to send a mail to my inbox every time a new product is created, so I implement the following source code:

FUNCTION z_jerry_prod_create_via_event.
*"----------------------------------------------------------------------
*"*"Local Interface:
*"  IMPORTING
*"     VALUE(EVENT) LIKE  SWETYPECOU-EVENT
*"     VALUE(RECTYPE) LIKE  SWETYPECOU-RECTYPE
*"     VALUE(OBJTYPE) LIKE  SWETYPECOU-OBJTYPE
*"     VALUE(OBJKEY) LIKE  SWEINSTCOU-OBJKEY
*"     VALUE(EXCEPTIONS_ALLOWED) LIKE  SWEFLAGS-EXC_OK DEFAULT SPACE
*"  EXPORTING
*"     VALUE(REC_ID) LIKE  SWELOG-RECID
*"  TABLES
*"      EVENT_CONTAINER STRUCTURE  SWCONT
*"  EXCEPTIONS
*"      READ_FAILED
*"      CREATE_FAILED
*"----------------------------------------------------------------------
  DATA: lo_recipient TYPE REF TO cl_cam_address_bcs.

  DATA: lt_body    TYPE bcsy_text,
        lv_prod_id TYPE comm_product-product_id,
        lt_send_to TYPE string_table.

  APPEND 'XXXX@sap.com' TO lt_send_to.
  data(ls_line) = value SOLI( line = `It's important to realize that using the in-development REPL, Project Kulla, is not for the faint of heart. Kulla, aka JShell, isn't part of the JDK 9 preview bundle at the time of writing` ).
  APPEND ls_line TO lt_body.

  SELECT SINGLE product_id INTO lv_prod_id FROM comm_product where product_guid = objkey.
  IF sy-subrc = 0.
     ls_line-line = '*'.
     APPEND ls_line TO lt_body.
     ls_line-line = | Created Product ID: { lv_prod_id }|.
     APPEND ls_line TO lt_body.
  ENDIF.
  TRY.
      DATA(lo_send_request) = cl_bcs=>create_persistent( ).
      DATA: lv_len TYPE so_obj_len VALUE 0.
      LOOP AT lt_body ASSIGNING FIELD-SYMBOL(<line>).
        lv_len = lv_len + strlen( <line> ).
      ENDLOOP.

      DATA(lo_document) = cl_document_bcs=>create_document(
                      i_type    = 'RAW'
                      i_text    = lt_body
                      i_length  = lv_len
                      i_subject = CONV #( 'Java9 is coming!' ) ).

      lo_send_request->set_document( lo_document ).

      DATA(lo_sender) = cl_cam_address_bcs=>create_internet_address( 'XXXX@sap.com' ).
      lo_send_request->set_sender( lo_sender ).

      LOOP AT lt_send_to ASSIGNING FIELD-SYMBOL(<lv_send_to>).
        lo_recipient = cl_cam_address_bcs=>create_internet_address( CONV #( <lv_send_to> ) ).
        lo_send_request->set_send_immediately( i_send_immediately = 'X' ).

        lo_send_request->add_recipient( i_recipient = lo_recipient i_express   = 'X' ).
      ENDLOOP.
      lo_send_request->send( i_with_error_screen = 'X' ).

      COMMIT WORK AND WAIT.

    CATCH cx_bcs INTO DATA(lo_bcs_exception).
      DATA(lv_message) = lo_bcs_exception->get_text( ).
      WRITE:/ lv_message.
      RETURN.
  ENDTRY.

ENDFUNCTION.

After that I create a new product and save it:

 

 

Then I will receive a mail in my inbox immediately:

 

 

How to debug the event listener

If you set a breakpoint within the event listener function module it will never get triggered, as it is called via transaction RFC as default maintained in tcode SWE2. If you write an “ASSERT 1 = 0” in it, you can observe that it is executed with user WF-BATCH which is not a dialog user so you cannot debug directly.

The solution for debug is rather simple, before the event is really raised, set the value of me->m_process_mode to “D” ( debug mode ) in method below:

 

 

After that your listener function module will be executed via normal way instead of tRFC, you can then now directly click F5 to debug into the function module.

 

 

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

0
1
分享到:
评论

相关推荐

    SAP 数据接口文档

    BAPI存储在Business Objects Repository(BOR)中,包含对象类型、接口、键、方法和特征。BAPI接口提供了一种标准化的方式,用于外部系统调用SAP的标准业务功能,但不适合大数据量和网络条件差的情况。BAPI减少了...

    sapjco3.dll sapjco3.jar 版本 7210,1120,28,55042 64位.zip

    RFC接口用于调用SAP系统的函数模块,而BOR接口则用于访问SAP业务对象。 `.dll`文件是Windows下的动态链接库,包含可由其他程序共享的函数和资源,而`.jar`文件是Java的归档文件,它包含了Java类、资源和元数据,...

    SAP_DotNetConnector3

    3. **SAP Business Object Repository(BOR)访问**:提供了对SAP BOR对象的访问,使得.NET应用可以调用SAP的业务对象和方法。 4. **事务处理**:支持在.NET应用中执行SAP系统的事务代码,确保数据的一致性和完整性...

    SAP-BAIP介绍

    SAP-BAIP,全称为SAP Business Application Programming Interface,是SAP系统中用于外部系统与SAP系统间集成和数据交换的重要技术。BAPI基于Remote Function Call (RFC)技术,使得外部应用程序能够访问和操作SAP...

    SAP Web Dynpro40个经典案例

    SAP Web Dynpro 是 SAP ABAP 平台上的一个组件,用于开发富...在实际工作中,结合SAP NetWeaver平台和其他ABAP技术,如BADI、RFC、Business Object Repository (BOR)等,能进一步提升Web Dynpro应用的功能性和灵活性。

    SAP BAPI 技术

    SAP BAPI(Business Application Programming Interfaces)是一种关键的技术,用于实现不同系统间的集成,特别是SAP系统与其他非SAP组件的交互。BAPI基于Remote Function Call (RFC)技术,允许外部应用程序通过标准...

    SAP NetWeaver

    **SAP NetWeaver**是SAP公司推出的企业级服务导向架构(Enterprise Service Architecture, ESA)的核心技术平台,它为企业提供了一个集成的软件基础,用于构建、运行和管理各种业务应用。NetWeaver旨在帮助企业实现...

    Bor开发工具

    Bor开发工具Bor开发工具Bor开发工具Bor开发工具Bor开发工具

    SAP BAPI和RFC接口技术

    * SAP采用Object-oriented技术,逻辑定义了SAP系统的所有功能目标,并且将所有的目标(Objects)和BAPIs存储于企业目标库BOR。 BAPI技术有以下优点: * BAPI是面向对象的设计。 * BAPI提供了基于企业目标技术的...

    sap与oracle 11i的比较!

    2. **集成性**:两者都致力于提供端到端的业务流程集成,但SAP R/3因其强大的Business Object Repository(BOR)和Enterprise Service Bus(ESB)而被认为在这一点上更具优势。 3. **定制化**:Oracle 11i的模块化...

    SAP ABAP编程 创建BAPI教程

    2.BAPIs 实现了BOR中业务对象的方法 3.BAPIs 通过RFC-enable的功能模块实现。 4.用户可以自行开发新的BAPI以满足业务需求。 5.BAPI是sap提供的基于业务对象的函数,它处理的对象是r/3的业务相关business object, ...

    SAP的开发工具ABAP-4学习资料

    SAP的开发还涉及到与业务逻辑相关的模块,如Business Object Repository (BOR)用于创建业务对象,Repository Information System (RIS)用于查看和管理SAP组件,以及ABAP Workbench用于开发和调试ABAP程序。...

    20210617-华西证券-科大讯飞-002230-千亿营收,2Bor2C?.pdf

    20210617-华西证券-科大讯飞-002230-千亿营收,2Bor2C?.pdf

    BOR Engine (BORE)-开源

    2. **事件驱动编程**:由于BORE可能基于JavaScript,所以理解事件监听和处理对于实现交互性至关重要。 3. **数据绑定**:学习如何将动态数据与页面元素绑定,以实现内容的实时更新。 4. **路由管理**:掌握如何配置...

    bor,Day(植树节).doc

    bor,Day(植树节).doc

    Plsgui_toolbox bor matlab

    "Plsgui_toolbox bor matlab" 是一个专为MATLAB设计的GUI工具箱,主要用于执行偏最小二乘法(Partial Least Squares, PLS)分析。这个工具箱为用户提供了友好的图形用户界面,使得非编程背景的科研人员也能方便地...

    BAPI_User_Guide word文档

    Business Object Repository(BOR)是SAP系统中存储BAPI和其他业务对象的地方。开发者可以通过BOR查找可用的BAPI,获取其结构和参数信息,从而方便地进行编程。 八、使用BAPI进行编程 编程BAPI时,有两种主要的...

    RFC BAPI

    4. **BOR Method**:BOR(Business Objects Repository)是SAP R/3系统中存储业务对象定义的地方。BAPI作为BOR中的一个方法,可以通过调用BOR中的相应方法来实现对业务对象的操作。 #### 四、BAPI的应用场景 BAPI...

    BAPI ActiveX Control

    4. **Business Object Repository (BOR)**:BOR是存储所有业务对象定义的地方,文档指导如何浏览BOR以获取所需信息。 5. **BAPI浏览器使用**:BAPI浏览器是SAP系统提供的一个工具,用于查看可用的BAPIs及其参数,...

Global site tag (gtag.js) - Google Analytics