Introduction
There are many different options to use for initial loads. One such options are events through an event broker like SAP Event Mesh or SAP Integration Suite, advanced event mesh. S/4HANA provides multiple different ways to produce such events. This blog will cover how initial loads can be done using RAP business events.
Concept
While S/4HANA provides many different standard business events out of the box, using them for initial loads is not advisable. The reason for this is that there can be a multitude of local event handlers that react to those standard events and produce unwanted side effects. To prevent these side effects dedicated initial load events should be used. That means that first a custom event has to be created and secondly an ABAP program has to be created that collects all of the required data and triggers each event.
Creating the custom event
To create a custom event the following blog can be referenced: RAP Business Events with Advanced Event Mesh [2]: Creating custom business events
Depending on the requirements the payload of the event can be adjusted within the abstract entity.
For this blog I’m using the following:
BO Data definition
@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘BO for BP init load’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity Z_INITLOAD_Event_BP as select from I_BusinessPartner
{
key BusinessPartner
}
BO Behaviour definition
managed with unmanaged save implementation in class zbp_initload_event_bp unique;
strict ( 2 );
define behavior for Z_INITLOAD_Event_BP //alias <alias_name>
lock master
authorization master ( instance )
//etag master <field_name>
{
event BPCreatedInitLoad parameter Z_INITLOAD_EVENT_BP_PAYLOAD;
}
Payload:
@EndUserText.label: ‘Payload for BP init load’
define abstract entity Z_INITLOAD_EVENT_BP_PAYLOAD
{
BusinessPartnerCategory : abap.char(1);
AuthorizationGroup : abap.char(4);
BusinessPartnerUUID : abap.raw(16);
PersonNumber : abap.char(10);
}
Global Class:
CLASS zbp_initload_event_bp DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF z_initload_event_bp.
TYPES tt_events TYPE TABLE FOR EVENT z_initload_event_bp~BPCreatedInitLoad.
PUBLIC SECTION.
CLASS-METHODS raise_initload_create
IMPORTING it_events TYPE tt_events.
ENDCLASS.
CLASS zbp_initload_event_bp IMPLEMENTATION.
METHOD raise_initload_create.
lcl_event_handler=>on_InitLoad_Create( it_events ).
ENDMETHOD.
ENDCLASS.
Local Class:
CLASS lcl_event_handler DEFINITION FRIENDS zbp_initload_event_bp.
PUBLIC SECTION.
CLASS-METHODS on_InitLoad_Create IMPORTING it_events TYPE zbp_initload_event_bp=>tt_events.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_InitLoad_Create.
RAISE ENTITY EVENT z_initload_event_bp~BPCreatedInitLoad FROM it_events.
ENDMETHOD.
ENDCLASS.
Event Binding:
Trigger Program
For triggering events there is no Out-of-the-Box feature with RAP Events. Therefor we need a trigger program that can be run by the user and creates all of the events.
To trigger the initial load events you have to load the data of the event and then trigger the event with it. I’m using an ABAP Class for that.
So let’s create that class. I named mine Z_INITIAL_LOAD_BP.
Next lets add the code:
CLASS zcl_initload_bp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_initload_bp IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
SELECT
FROM I_BusinessPartner
FIELDS BusinessPartner, BusinessPartnerCategory, BusinessPartnerUUID, PersonNumber
INTO TABLE @DATA(t_bupa).
DATA counter TYPE i VALUE 0.
LOOP AT t_bupa ASSIGNING FIELD-SYMBOL(<s_bupa>).
DATA(et_events) = VALUE zbp_initload_event_bp=>tt_events(
(
BusinessPartner = <s_bupa>-BusinessPartner
BusinessPartnerCategory = <s_bupa>-BusinessPartnerCategory
BusinessPartnerUUID = <s_bupa>-BusinessPartnerUUID
PersonNumber = <s_bupa>-PersonNumber
)
).
zbp_initload_event_bp=>raise_initload_create( it_events = et_events ).
counter = counter + 1.
ENDLOOP.
out->write( ‘Initial load successfull!’).
out->write( counter && ‘ Events were created’ ).
commit work.
ENDMETHOD.
ENDCLASS.
This code loads the data, loops trough the table and triggers an event for each business partner. Since it is just plain ABAP coding additional logic can be introduced for example for filtering objects following certain conditions.
You can then execute this code directly from eclipse.
IntroductionThere are many different options to use for initial loads. One such options are events through an event broker like SAP Event Mesh or SAP Integration Suite, advanced event mesh. S/4HANA provides multiple different ways to produce such events. This blog will cover how initial loads can be done using RAP business events.ConceptWhile S/4HANA provides many different standard business events out of the box, using them for initial loads is not advisable. The reason for this is that there can be a multitude of local event handlers that react to those standard events and produce unwanted side effects. To prevent these side effects dedicated initial load events should be used. That means that first a custom event has to be created and secondly an ABAP program has to be created that collects all of the required data and triggers each event.Creating the custom eventTo create a custom event the following blog can be referenced: RAP Business Events with Advanced Event Mesh [2]: Creating custom business events Depending on the requirements the payload of the event can be adjusted within the abstract entity.For this blog I’m using the following:BO Data definition@AbapCatalog.viewEnhancementCategory: [#NONE]
@AccessControl.authorizationCheck: #NOT_REQUIRED
@EndUserText.label: ‘BO for BP init load’
@Metadata.ignorePropagatedAnnotations: true
@ObjectModel.usageType:{
serviceQuality: #X,
sizeCategory: #S,
dataClass: #MIXED
}
define root view entity Z_INITLOAD_Event_BP as select from I_BusinessPartner
{
key BusinessPartner
}BO Behaviour definitionmanaged with unmanaged save implementation in class zbp_initload_event_bp unique;
strict ( 2 );
define behavior for Z_INITLOAD_Event_BP //alias <alias_name>
lock master
authorization master ( instance )
//etag master <field_name>
{
event BPCreatedInitLoad parameter Z_INITLOAD_EVENT_BP_PAYLOAD;
} Payload:@EndUserText.label: ‘Payload for BP init load’
define abstract entity Z_INITLOAD_EVENT_BP_PAYLOAD
{
BusinessPartnerCategory : abap.char(1);
AuthorizationGroup : abap.char(4);
BusinessPartnerUUID : abap.raw(16);
PersonNumber : abap.char(10);
}Global Class:CLASS zbp_initload_event_bp DEFINITION PUBLIC ABSTRACT FINAL FOR BEHAVIOR OF z_initload_event_bp.
TYPES tt_events TYPE TABLE FOR EVENT z_initload_event_bp~BPCreatedInitLoad.
PUBLIC SECTION.
CLASS-METHODS raise_initload_create
IMPORTING it_events TYPE tt_events.
ENDCLASS.
CLASS zbp_initload_event_bp IMPLEMENTATION.
METHOD raise_initload_create.
lcl_event_handler=>on_InitLoad_Create( it_events ).
ENDMETHOD.
ENDCLASS.Local Class:CLASS lcl_event_handler DEFINITION FRIENDS zbp_initload_event_bp.
PUBLIC SECTION.
CLASS-METHODS on_InitLoad_Create IMPORTING it_events TYPE zbp_initload_event_bp=>tt_events.
ENDCLASS.
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_InitLoad_Create.
RAISE ENTITY EVENT z_initload_event_bp~BPCreatedInitLoad FROM it_events.
ENDMETHOD.
ENDCLASS.Event Binding: Trigger ProgramFor triggering events there is no Out-of-the-Box feature with RAP Events. Therefor we need a trigger program that can be run by the user and creates all of the events.To trigger the initial load events you have to load the data of the event and then trigger the event with it. I’m using an ABAP Class for that.So let’s create that class. I named mine Z_INITIAL_LOAD_BP.Next lets add the code:CLASS zcl_initload_bp DEFINITION
PUBLIC
FINAL
CREATE PUBLIC .
PUBLIC SECTION.
INTERFACES if_oo_adt_classrun.
PROTECTED SECTION.
PRIVATE SECTION.
ENDCLASS.
CLASS zcl_initload_bp IMPLEMENTATION.
METHOD if_oo_adt_classrun~main.
SELECT
FROM I_BusinessPartner
FIELDS BusinessPartner, BusinessPartnerCategory, BusinessPartnerUUID, PersonNumber
INTO TABLE @DATA(t_bupa).
DATA counter TYPE i VALUE 0.
LOOP AT t_bupa ASSIGNING FIELD-SYMBOL(<s_bupa>).
DATA(et_events) = VALUE zbp_initload_event_bp=>tt_events(
(
BusinessPartner = <s_bupa>-BusinessPartner
BusinessPartnerCategory = <s_bupa>-BusinessPartnerCategory
BusinessPartnerUUID = <s_bupa>-BusinessPartnerUUID
PersonNumber = <s_bupa>-PersonNumber
)
).
zbp_initload_event_bp=>raise_initload_create( it_events = et_events ).
counter = counter + 1.
ENDLOOP.
out->write( ‘Initial load successfull!’).
out->write( counter && ‘ Events were created’ ).
commit work.
ENDMETHOD.
ENDCLASS.This code loads the data, loops trough the table and triggers an event for each business partner. Since it is just plain ABAP coding additional logic can be introduced for example for filtering objects following certain conditions.You can then execute this code directly from eclipse. Read More Technology Blogs by SAP articles
#SAP
#SAPTechnologyblog