segunda-feira, 7 de junho de 2021

Business Events in S/4HANA On Premise System: Triggering Custom Change Pointers and Custom Event on Custom Table – Part 1

 While working on S/4HANA On Premise system; you will often come across requirements where custom functionality is required on data changes whether its triggering an Outbound Interface /  Sending approval mail etc. . On high level, you can build solution using either of below listed approach

I thought to pen down the use cases and steps to enable the Custom events for both the scenarios in my Blog series as this might help people working on similar requirements. We have used S/4HANA 2020 FPS01 for the use cases. I will be covering below topics in Business Events series.

  1. Enable Change Pointer and Custom Event for Custom Table
  2. Trigger , Trace and Debug Custom Event
  3. Event Mesh: Enabling for Custom Events
  4. Event Mesh: Enabling Topic for Custom Events

To start with in this Blog we will discuss how to trigger Change Pointers and Custom Events for a Custom table in S/4HANA On Premise System .While searching for this requirement; I could find some good blogs explaining SCDO Configuration using Update FM to trigger events . But now since events are class based; I thought to cover the detailed steps in this Blog post. These Custom Events we will later use for Event Mesh set up too.

Let’s take a scenario of Custom table where we need to track the changes in one field of table like Quantity. In case Quantity is Changed; it should be updated in Change Pointers CDHDR and CDPOS and custom event should be raised to pass the Custom table data either to middleware /Event Mesh Queue.

  • In Data Element of Quantity field, check the checkbox for Change Document

  • In Transaction SCDO, Create Change Document Object for this case giving table name and make a note of the class that gets generated ZCL_ZMATERIAL_CHDO

  • You can find the details of generated Objects; by checking on generated Information.
  • For Testing, you can directly execute the method WRITE of class ZCL_ZMATERIAL_CHDO or you can write custom program to call this to generate Change pointers for our Quantity field. Example when I directly executed the method from the class ; it generated the changenumber.

  • SAP has given sample code in the generated class that can be used in your Custom Report ; you just need to COPY+PASTE the code from the generated custom class. Below is the sample code generated for my class

*”  uncomment the needed parts
*”  change names if needed

*”  Start of default parameter part
* DATA: objectid                TYPE cdhdr-objectid,
*       tcode                   TYPE cdhdr-tcode,
*       planned_change_number   TYPE cdhdr-planchngnr,
*       utime                   TYPE cdhdr-utime,
*       udate                   TYPE cdhdr-udate,
*       username                TYPE cdhdr-username,
*       cdoc_planned_or_real    TYPE cdhdr-change_ind,
*       cdoc_upd_object         TYPE cdhdr-change_ind VALUE ‘U’,
*       cdoc_no_change_pointers TYPE cdhdr-change_ind.
* DATA: cdchangenumber          TYPE cdhdr-changenr.
*”  End of default parameter part

*” Begin of dynamic DATA part for class ZCL_ZMATERIAL_CHDO
*”   table with the NEW content of: ZMATERIAL_CHG
* DATA XZMATERIAL_CHG TYPE ZCL_ZMATERIAL_CHDO=>TT_ZMATERIAL_CHG.
*”   table with the OLD content of: ZMATERIAL_CHG
* DATA YZMATERIAL_CHG TYPE ZCL_ZMATERIAL_CHDO=>TT_ZMATERIAL_CHG.
*”   change indicator for table: ZMATERIAL_CHG
* DATA UPD_ZMATERIAL_CHG TYPE IF_CHDO_OBJECT_TOOLS_REL=>TY_CDCHNGINDH.

*”     Change Number of Document
* DATA CHANGENUMBER TYPE IF_CHDO_OBJECT_TOOLS_REL=>TY_CDCHANGENR.

*” End of dynamic DATA part for class ZCL_ZMATERIAL_CHDO

*”  Begin of method call part
*”  define needed DATA for error handling
* DATA err_ref TYPE REF TO cx_chdo_write_error.
* DATA err_action TYPE string.

*    TRY.
*        CALL METHOD ZCL_ZMATERIAL_CHDO=>write
*          EXPORTING
*            objectid                = objectid
*            tcode                   = tcode
*            utime                   = utime
*            udate                   = udate
*            username                = username
*            planned_change_number   = planned_change_number
*            object_change_indicator = cdoc_upd_object
*            planned_or_real_changes = cdoc_planned_or_real
*            no_change_pointers      = cdoc_no_change_pointers
*”  End of default method call part

*” Begin of dynamic part for method call
*”   table with the NEW content of: ZMATERIAL_CHG
*   XZMATERIAL_CHG = XZMATERIAL_CHG
*”   table with the OLD content of: ZMATERIAL_CHG
*   YZMATERIAL_CHG = YZMATERIAL_CHG
*”   change indicator for table: ZMATERIAL_CHG
*   UPD_ZMATERIAL_CHG = UPD_ZMATERIAL_CHG

*”     Change Number of Document
*           IMPORTING
*             changenumber            = cdchangenumber.
*      CATCH cx_chdo_write_error INTO err_ref.
*”        MESSAGE err_ref TYPE ‘A’.
*”   error information could be determined with default GET_TEXT, GET_LONGTEXT, GET_SOURCE_POSITION methds

*    ENDTRY.
*” End of dynamic part for method call

  • You can add this sample code in your Custom Report to Create change pointers. This can be added after INSERT/UPDATE on custom table so that once table is updated; change pointer can be triggered.
  • Once the Change Pointer is created; you can raise the Event for the same Object Key using below Code :

DATA: container_table TYPE TABLE OF swcont.
DATA: objkey TYPE sweinstcou-objkey.
DATA: event_container TYPE REF TO if_swf_ifs_parameter_container,
event           TYPE REF TO if_swf_evt_event.
“Set Container and Raise the event ‘CHANGED’

event_container = cl_swf_evt_event=>get_event_container(
im_objcateg  = cl_swf_evt_event=>mc_objcateg_cl
im_objtype   = ‘ZCL_EVENT_CUSTOMTABLE’
im_event     = ‘CHANGED’ ).
CHECK event_container IS BOUND.

CONCATENATE sy-mandt p_matnr p_werks INTO objkey.”Create Object Key
event = cl_swf_evt_event=>get_instance(
im_objcateg         = cl_swf_evt_event=>mc_objcateg_cl
im_objtype          = ‘ZCL_EVENT_CUSTOMTABLE’
im_event            = ‘CHANGED’
im_objkey           = objkey
im_event_container  = event_container ).
IF event IS BOUND.
TRY .
event->raise( ).
CATCH cx_swf_evt_invalid_objtype cx_swf_evt_invalid_event.
RETURN.
ENDTRY.
COMMIT WORK.
ENDIF.

This code will trigger the CHANGED event of the Custom Class and functionality written inside CHANGED event will get triggered.

In this blog post, we have covered how to create change pointers on Custom table and trigger Custom Event. Detailed steps on how to create Custom Event class and events is covered in the subsequent Blog post: Part 2.

Regards
Taranam

Source: https://blogs.sap.com/2021/05/31/business-events-in-s-4hana-on-premise-system-triggering-custom-change-pointers-and-custom-event-on-custom-table-part-1/

In SAP S/4HANA You can create Change History Report in less than 15 minutes. I mean any Change History Documents

 Introduction

One of the greatest Success story of SAP is the Audit Trace it has using SAP Standard Change History Object. It is used anywhere everywhere for the following

To Track whether the Company is making the best Deal
Cost Cutting on changes that is being made caught in Change History.
Automation or RPA usage for regular changes so that Human works on Important stuff
Find Process Design through history
Find place where Training is Required.

Solution

In SAP ECC as an ABAPER we always had to built a Report Joining the change History table and other tables as it was created as a Pool/Cluster table hence it could not be used in ABAP Query(SQVI)

Below is the Error message which you get when you try to add CDPOS as a Table join in SQVI

Highlight section shows CDPO is a Pool table in SAP ECC

Below is the ABAP Query Joining Codition

Below is the Selection Screen

Below is the Layout for the ABAP Query

Below is the Layout for the ABAP Query continued

Now we Execute the Report to Find the Change History on Payment Block Field(ZLSPR) and Table is BSEG

Wala here is the Output.

I am not sure about the Change Document Object. Lets check BUPA*(aka Business Partner/Vendor/Customer/Employee)

We get all the Output

Now I want check who is Changing Price in the Purchase order. If it is less great if it is more WHY 🙂

Below is the Output.

Also check the blog to generate an ABAP Report from ABAP Query

https://blogs.sap.com/2020/07/28/how-to-write-a-report-directly-in-production-and-share-it-with-use-of-sqvi/

 

Conclusion

This can be used only in SAP S/4 HANA and not SAP ECC

 

Below is the Video version

 

 Source: https://blogs.sap.com/2020/08/15/in-sap-s-4-hana-you-can-create-change-history-report-in-less-than-15-minutes.-i-mean-any-change-history-documents/

S/4HANA Business Partner Replication

 

Introduction and Scenario

You have set up your business partner scenario in your S/4HANA system? Now you want to send your S/4HANA business partners to another S/4HANA system?

This blog provides you the steps for a basic scenario: sending your business partner master data from one S/4HANA on premise system to another with some snapshots. Being a member of the business partner team of the S/4HANA RIG, I want to share this with you.

Let´s assume business partners (BP’s) like this BP customer:

Which technology should you use for the replication? Web services or IDocs?

The answer is clearly given in note 2417298 – Integration of Business Partner with Customer and Supplier Roles: the web service technology of Enterprise Service Oriented Architecture (SOA) is to be used, if the system has business partners. The IDocs DEBMAS and CREMAS are not recommended for data integration between S/4HANA systems. For business partner replication, the web service technology is also used by S/4HANA Master Data Governance (MDG) and SAP Cloud Platform Master Data for Business Partner. Additonally, there are odata services for business partner master data available, but their usage is not scope of this blog.

Detailed reference information about the business partner web service definitions with all fields can be found here.

So, what set up steps needs to be done? Don´t get confused, when MDG is mentioned in linked documentation sometimes. It´s, because technically it´s part of S/4HANA, but you don´t need to set up the complete MDG for this.

There are two major steps:

  1. SOA manager basics on sender and receiver
    First you need to do the basic configuration in the SOAMANAGER (SOA Manager) transaction. It starts the SOA Manager web application. I will describe the steps below. For your reference, here´s also the link to help.sap.com.
  2. Configuration in Data Replication Framework (DRF)
    The Data Replication Framework enables you to replicate data from a source system to target systems. I will describe how to configure it for this sceanrio below. For your reference, here´s also the link to help.sap.com.

Configuring SOA Manager for Business Partner

Before you set up the data replication framework (DRF), you need to configure the SOA Manager accordingly in receiver and provider system.

Preparation

Do these steps as preparation in both receiver and provider system;

  1. Get administrative authorizations for the SOA manager in S/4HANA: SAP_BC_WEBSERVICE_ADMIN_TEC and authorization for transactions SU01, SUIM, PFCG.
  2. Create a special service user in transaction SU01 with authorization role SAP_BC_WEBSERVICE_ADMIN_TEC.
  3. Activate special business functions from SOA and business partner.
    Run this activity in the customizing: SAP Customizing Implementation Guide > Activate Business Functions. Active business function FND_SOA_REUSE_1.
  4. Activate point-to-point communication for enterprise services
    Run this activity in the customizing: SAP Customizing Implementation Guide > Cross-Application Components > Processes and Tools for Enterprise Applications > Enterprise Services > Point-to-Point Enablement for Asynchronous Enterprise Services > Activate Support for Point2Point Communication.
  5. Connect to the system landscape directory or implement a BAdI for local system ID determination as described in the IMG doucmentation here: Cross-Application Components > Processes and Tools for Enterprise Applications > Master Data Governance > General Settings > Data Replication > Define Custom Settings for Data Replication > Define Technical Settings > BAdI: Determination of Local System Name
  6. Configure the web service runtime as described in note 1043195 – Configuration of Web service runtime
  7. Activate the error and conflict handler (optional, recommended) in IMG Cross-Application Components > General Application Functions > Error and Conflict Handler > Activate Error and Conflict Handler.

CONFIGURE the SOA MANAGER

Do these steps as preparation to configure the SOA Manager in both receiver and provider system;

  1. Create a point-to-point communication profile with same name in provider and receiver.
  2. Configure the client setting.

    Go to Technical Administration > SAP Client Settings in the SOA Manager, provide an organization name and either get the business system from System Landscape Directory (if you use it) or if you have used the BAdI, provide local system ID as defined in the BAdI MDG_IDM_GET_LCL_SYSTEM.
    Then enter the own business system ID. You can get the own business system ID from transaction SLDCHECK and check in the transactions list report the section “Calling function LCR_GET_OWN_BUSINESS_SYSTEM”:

  3. Configure a provider system for the business scenario configuration.

    Create the provider system on the Technical Administration tab of the SOA Manager.
    On the General tab provide the name of the business system ID of the counterpart system, a description and as profile name enter the profile name from Step 1!

    Enter further details on the next step “Enter connection settings for searching web services and credentials to access service metadata like WSDL and WSIL”. Use the primary service registry settings and the WSIL usage. Fill these fields

    • SLD Identifier
      Enter it in this format <client>.SystemName.<XYZ>.SystemNumber.<Installation Number>.SystemHome.<Host>.
      SystemNumber you find under System>Status>SAP System Data>Installation Number and SystemHome under System>Status>Database Data>Host.
    • Access URL for WSIL and Logon Information
      Format: https://<hostname>:<port>/sap/bc/srt/wsil?sap-client=<client>
      Host name and port you get from transaction SMICM (ICM Monitor), Goto > Services
    • User and Password for WSDL and WSIL. You can take the service user you created in the backend system.
    • Create Business Application ID
      Enter an application name, description and the business application ID from the counterpart system. It can be found under SOAMANAGER > Technical Administration > SAP Client Settings in the counterpart system. Press Finish.The Identifiable Business Context Reference (IBC reference) for the counterpart system is generated automatically and can be checked in SOAMANAGER > Service Administration > Identifiable Business Context Reference.
  4. Edit logon data for business scenario
    After the backend users were created already earlier, please create appropriate Logon Data entries within both provider and receiver system locally. This can be done in the SOAMANAGER > Service Administration > Logon Data Management > Maintenance
  5. Assign Logon Data to Provider Identifiable Business Context (IBC) Reference
    Now the just created Logon Data have to be assigned to the IBC References.
    Press Next, assign the logon data and press Finish.
  6. Create Integration Scenario Configuration for Point-to-Point Communication using Service Group.With this, you select the business partner services for the communication. In SOAMANAGER go to Service Administration > Local Integration Scenario Configuration and create an integration scenario configuration.
    Add these Service Definitions:

    • BUSINESSPARTNERSUITEBULKREPLIC
    • BUSINESSPARTNERSUITEBULKREPLI1
    • BUSINESSPARTNERRELATIONSHIPSUI
    • BUSINESSPARTNERRELATIONSHIPSU1


    For all assign the above created profile MDG and press Next.

    Then Select service groups and provider IBC reference by adding service group MDG_BS_SUPPLIERREPLICATEREQ and MDG_BS_SUPPLIERREPLICATECONF.

    To all service groups assign the before created IBC Reference.


    Check the Logon Data Assignment and Press Finish.

    Do not activate the business scenario immediately because first the business scenario in the counterpart system needs to be defined.

    After creation of the integration scenario in the counterpart system, activate the scenario and process pending tasks in both systems.

  7. Set logical port as default
    For setting the logical port, in SOAMANAGER go Service Administration > Web Service ConfigurationSearch Object Type: All and Object Name:BusinessPartnerSUITEBulkReplicateRequest_Out

    Click on the BusinessPartnerSUITEBulkReplicateRequest_Out, select the logical port and press Set Log.Port Default.

Congratulations, you´ve set the SOA Manager! Most of the work is done. Now you only need to configure the Data Replication Framework.

Configuration in Data Replication Framework (DRF)

  1. Define technical settings for business system
    • For settings in the DRF, in transaction DRFIMG, go to Data Replication > Define Custom Settings for Data Replication > Define Technical Settings > Define Technical Settings for Business Systems
    • Create a new entry with the business system as you entered as provider system in SOA Manager under Technical Administration > Provider Systems and a logical system. As Business Object Type add 986 (Business Partner including Relationships) with Output Mode Object-Dependent Default with System Filter checked. As communication channel choose Replication via Services, further values as shown in snapshot.

  2. Define a replication model
    • In transaction DRFIMG, go to Data Replication > Define Custom Settings for Data Replication > Define Replication Model.
    • Create a new Replication Model entry, Assign Outbound Implementation 986_3 Outbound Impl. for BP/REL via Services, Communication Channel Replication via Services and Filter time Filter After Change Analysis. For the new Assignment line as next step create a new assignment line and enter the target business system for the replication model. Log Days can be set optional.
    • Furthermore, set outbound parameters in Assign Outbound Parameter with Outbound Parameter “PACK_SIZE_BULK” for example with value 50 or 100.
    • Save Active your replication model in Data Replication > Define Custom Settings for Data Replication > Define Replication Model.

Starting the Replication

Finally, you can start the replication via transaction DRFOUT. Select the previously created replication model and the respective outbound implementation. You get several options for the replication.

With the button Manual Replication Filter Criteria, you get to the filter screen. On the screen you can enter several filters, after done press Save. Back on the main screen, press Execute, and you trigger the data replication manually.

After e.g. a manual start you get the log:


Further detailed monitoring is possible via transaction SRT_MONI Web Service Utilities: Message Monitor.

Conclusion

This guidance should give a good starting point for business partner replication, especially if you haven´t worked with the SOA Manager and DRF before.

As this is just a starter, I bet there are many questions coming up as you evolve your scenario.

For questions please check these helpful links:

Brought to you by the SAP S/4HANA RIG and Customer Care team.

Source: https://blogs.sap.com/2020/07/02/s-4hana-business-partner-replication/