How to add new RAP Events to the Data Modeler

How to add new RAP Events to the Data Modeler

How to Add New RAP Events

to the One Connect Data Modeler

 

Overview

One Connect for SAP supports real-time event-driven data transmission through SAP RAP (ABAP RESTful Application Programming Model) Business Events. By subscribing to RAP behavior events such as Created, Changed, or Approved, One Connect can automatically trigger data extraction whenever a business document is created or modified in S/4HANA.

This guide walks through the end-to-end process of adding a new RAP event to One Connect, using the Purchase Order process as an example. The same pattern applies to any RAP-enabled business object.

 

Step

Description

Key Activity

1

Identify the RAP Behavior

Search BDEF in ADT (Eclipse)

2

Create the Event Handler Class

ABAP class with Local Types

3

Implement the Event Logic

Local class inheriting cl_abap_behavior_event_handler

4

Register the Event in One Connect

Table ZONTA_OC_EVENTS via SM30

Prerequisites

Before you begin, ensure the following are in place:

       SAP S/4HANA system with RAP Business Events support (release 2022 or later)

       ABAP Development Tools (ADT) in Eclipse installed and connected to your SAP system

       One Connect for SAP installed and configured with an active Smart Gateway

       Authorization to create ABAP classes and maintain custom tables

       Familiarity with the RAP Behavior Definition (BDEF) concept

 

Step 1: Identify the RAP Behavior Definition

Search for the behavior in ADT and confirm it exposes events for your business process

 

1.1 Search for the Behavior Definition in ADT

Open ABAP Development Tools (ADT) in Eclipse and use the ABAP Object Search to locate the behavior definition for your business process.

Configure the search with the following parameters:

 

Field

Value

Object Name Pattern

*PurchaseOrder*

Property Filter

type:bdef

 

Figure 1: ABAP Object Search in ADT filtered for behavior definitions matching *PurchaseOrder*.

1.2 Review the Search Results

The search returns all matching behavior definitions. For the Purchase Order process, select R_PurchaseOrderTP — the root behavior for the Purchase Order Transactional Processing object.

 

Figure 2: Search results showing 7 behavior definitions. Select R_PurchaseOrderTP from package RAP_MM_PUR_PO.

1.3 Verify Available Events

Open the behavior definition and inspect the root node in the outline. Expand _PurchaseOrderTP to see the available events. In this example, the following events are available:

 

Event Name

Triggers When

Approved

A purchase order is approved

Changed

A purchase order is modified

Created

A new purchase order is created

ItemBlocked

A line item is blocked

ItemChanged

A line item is modified

ItemDeleted

A line item is deleted

ItemUnblocked

A line item is unblocked

 

Figure 3: The R_PurchaseOrderTP behavior definition in ADT showing the available events in the outline tree (left) and the BDEF source code (right).

 

Note

If the behavior definition does not expose any events, RAP event-based integration is not available for that business object. Consider using alternative One Connect triggers such as Change Documents or BTE events.

 


 

Step 2: Create the Event Handler Class

Create an ABAP class bound to the RAP behavior events

 

2.1 Create the Global Class

In ADT, create a new ABAP class. The class must be declared as PUBLIC ABSTRACT FINAL and bound to the behavior using the FOR EVENTS OF clause.

Example class name:

 

Property

Value

Class Name

ZONCL_MM_PO_RAPEVENTS_HANDLER

Behavior Reference

R_PurchaseOrderTP

 

Global Class Definition

 

CLASS zoncl_mm_po_rapevents_handler DEFINITION

  PUBLIC ABSTRACT FINAL

  FOR EVENTS OF r_purchaseordertp.

 

  PUBLIC SECTION.

  PROTECTED SECTION.

  PRIVATE SECTION.

ENDCLASS.

 

CLASS zoncl_mm_po_rapevents_handler IMPLEMENTATION.

ENDCLASS.

 

2.2 Switch to Local Types

After creating the global class, navigate to the Local Types tab at the bottom of the ADT editor. This is where the actual event handling logic is implemented.

Figure 4: The global class in ADT. Click the Local Types tab (highlighted) to implement the event handler logic.

 


 

Step 3: Implement the Event Logic

Define the local event handler class and implement the One Connect data transmission call

 

3.1 Identify the Behavior Alias

Before writing the handler code, check the alias defined in the behavior definition. The alias is used to reference the entity in event method signatures.

 

Figure 5: The BDEF defines R_PurchaseOrderTP with alias PurchaseOrder — use this alias in the event method signature.

 

Info

The alias (e.g., PurchaseOrder) is used in the FOR ENTITY EVENT clause, while the full behavior name (e.g., R_PURCHASEORDERTP) is used for the gc_typeid_bo constant.

 

3.2 Local Class Definition

In the Local Types tab, define a local class that inherits from cl_abap_behavior_event_handler. Declare methods for each RAP event you want to handle:

 

*"* use this source file for the definition and implementation of

*"* local helper classes, interface definitions and type declarations

 

CLASS lcl_he_event DEFINITION INHERITING FROM cl_abap_behavior_event_handler.

  PRIVATE SECTION.

    METHODS on_created FOR ENTITY EVENT

      created FOR purchaseorder~created.

 

    METHODS on_change FOR ENTITY EVENT

      change FOR purchaseorder~changed.

 

    METHODS on_approved FOR ENTITY EVENT

      approved FOR purchaseorder~Approved.

 

    "Methods to add messages to the business application log

    METHODS log RETURNING VALUE(log) TYPE REF TO if_xco_cp_bal_log.

    METHODS add_message IMPORTING log     TYPE REF TO if_xco_cp_bal_log

                                 message TYPE string.

 

    CONSTANTS: gc_typeid_bo     TYPE sibflporb-typeid VALUE 'R_PURCHASEORDERTP',

               gc_catid_bo      TYPE sibflporb-catid  VALUE 'CL',

               gc_event_create  TYPE sibfevent VALUE 'CREATE',

               gc_event_change  TYPE sibfevent VALUE 'CHANGE',

               gc_event_approved TYPE sibfevent VALUE 'APPROVED',

               gc_event_delete  TYPE sibfevent VALUE 'DELETE'.

 

    DATA: go_log            TYPE REF TO if_xco_cp_bal_log,

          go_json_automatic TYPE REF TO zoncl_fetch_data. "zoncl_fetch_data_v2

 

ENDCLASS.

 

Figure 6: Complete local class definition in the Local Types tab showing event methods, constants, and data declarations.

 

3.3 Method Implementation (on_created)

Implement each event method. The example below shows the on_created method, which is triggered when a new Purchase Order is created:

 

METHOD on_created.

  DATA:

    lt_attr_names TYPE swfdnamtab,

    ls_sender     TYPE sibflporb,

    lv_event      TYPE sibfevent.

 

  " If not configured in One Connect, return

  IF zoncl_rapevent_factory=>rap_event_entities( gc_typeid_bo ) EQ abap_false.

    RETURN.

  ENDIF.

 

  go_log = log( ).

 

  LOOP AT created ASSIGNING FIELD-SYMBOL(<fs_created>).

    add_message(

      log     = go_log

      message = |Key: "{ <fs_created>-purchaseorder }" / PO Event CREATED handled RAP EVENT|

    ).

 

    go_json_automatic = NEW #( ).

 

    ls_sender-typeid = gc_typeid_bo.

    ls_sender-catid  = gc_catid_bo.

    ls_sender-instid = <fs_created>-purchaseorder.

    lv_event = gc_event_create.

 

    go_json_automatic->send_event_automatic(

      is_sender = ls_sender

      i_event   = lv_event

    ).

  ENDLOOP.

ENDMETHOD.

 

Tip

The constants gc_typeid_bo and gc_event_create map to the values stored in table ZONTA_OC_EVENTS. The factory method zoncl_rapevent_factory=>rap_event_entities checks whether the event is registered before processing, providing a safe guard against unregistered objects.

 


 

Step 4: Register the Event in One Connect

Add the RAP event to the One Connect events configuration table

 

The final step is to register the event in the One Connect configuration so the system recognizes the RAP behavior object and processes it.

4.1 Open Table Maintenance

Run transaction SM30 and enter table ZONTA_OC_EVENTS (Events for One Connect). Click Display or Edit to open the maintenance view.

Figure 7: Transaction SM30 with table ZONTA_OC_EVENTS — the Events for One Connect configuration table.

4.2 Add the Event Entry

Create a new entry with the RAP behavior object name and a descriptive Object Type:

 

Field

Value

Change doc. Object

R_PURCHASEREQUISITIONTP

Object Type

PURCHASE REQUISITION RAP

 

Figure 8: Events for One Connect table showing the registered RAP event entry.

 

Important

The value in the Change doc. Object field must exactly match the gc_typeid_bo constant defined in your event handler class (e.g., R_PURCHASEORDERTP). A mismatch will cause the factory check to fail and the event will not be processed.

 

Troubleshooting

 

Symptom

Possible Cause

Resolution

Event handler not triggered on document save

Class not properly bound to behavior via FOR EVENTS OF

Verify the global class definition includes FOR EVENTS OF r_purchaseordertp

Factory check returns abap_false

Event not registered in ZONTA_OC_EVENTS

Add the correct entry in SM30 with the exact gc_typeid_bo value

No events visible in BDEF outline

Business object does not expose RAP events

Confirm the BO supports events (S/4HANA 2022+); consider Change Documents or BTE as alternatives

Data not arriving in target platform

Smart Gateway unreachable or RFC destination misconfigured

Test the RFC destination in SM59; verify the Smart Gateway is running

Alias mismatch in method signature

Using full BDEF name instead of alias in FOR clause

Check the BDEF for the alias keyword (e.g., alias PurchaseOrder) and use it in the method declaration

 



    • Related Articles

    • Sending Z Tables via SAP Data Modeler and Custom Z Program - For ABAP RAP

      Manual: Sending Z Tables via SAP Data Modeler and Custom Z Program In the SAP Data Modeler, create an “ANY” Entity including the desired Z tables. Ensure the Domain is set to ANY. Inside the entity, select the desired columns to send in the Column ...
    • SAP Data Modeler - Entity Creation and Main Customizing

      Introduction This document provides a step-by-step guide for creating and configuring an entity within Onibex's SAP Modeler using transaction ZONT_ONECM. An entity in the Data Modeler is defined as a set of standard SAP tables and their key fields, ...
    • Onibex SAP Data Modeler - Functionalities

      Introduction The following table outlines key functionalities offered by the SAP Data Modeler, highlighting features designed to enhance data extraction, customization, and integration within SAP environments. No Function Description 1 Direct Data ...
    • SAP MM Module - BOR and RAP Events

      MM Module - BOR and RAP Events by Entity in SAP Entity CDS View Tables Change Doc Object BOR Event RAP Event Actions Consumption Data KONH KONP MSEG CL_MMIM_MATDOC_EVENT CRE Contract EINKBELEG CL_MM_PUR_WF_OBJECT_CTR R_PURCHASECONTRACTTP CRE, UPD, ...
    • Sending Z Tables via SAP Data Modeler and Custom Z Program - For Classic ABAP

      Manual: Sending Z Tables via SAP Data Modeler and Custom Z Program In the SAP Data Modeler, create an “ANY” Entity including the desired Z tables. Ensure the Domain is set to ANY. Inside the entity, select the desired columns to send in the Column ...