If you’re using SAP Hybris Commerce with an SAP ECC back-end you’ll need to download several customizing settings from SAP to Hybris, such as currencies, languages, units of measure, plants and material groups. To do this SAP provides ABAP report ZDOWNLOAD_CUSTOMIZING_AS_IMPEX which generates an ImpEx file which you can import into Hybris.
In addition, you may need some additional data such as sales organizations, offices and groups, product hierarchies or even data that you have defined in Z-tables in ECC. To get this data in Hybris you have probably written an ImpEx file or extended ZDOWNLOAD_CUSTOMIZING_AS_IMPEX with your own logic.
Usually these customizing settings don’t change very frequently, but if they do and Hybris Commerce is out of sync with ECC, this causes issues like not being able to synchronize customers or products. To prevent or solve this you should regularly, for example daily, do this and as they are manual steps, this becomes somewhat labor intensive.
So wouldn’t it be great if we can do this on a daily basis and without any manual steps? In this blog I describe how to do this in 4 steps.
1. Back-end object
Customizing is not much more than just a set of tables. Therefore, we make use of function module RFC_READ_TABLE which is RFC enabled and returns the contents of the specified table.
We create class TableSyncBackendERP which extends BackendBusinessObjectBaseJCo. In this class we create method downloadTable() which calls this function module. Its import parameters are the table name and a list of fields we want to retrieve. The contents of the table are returned as a SAPTableData type which we define like this:
The complete source of the downloadTable() method is as follows:
As you can see downloadTable() loops over the rows and calls processRow() which returns a HashMap with the requested field names and values.
Instead of hardcoding all tables and fields to download we decided to do this via configuration. Also, we need to know to which types and attributes they need to be mapped in Hybris.
We hold the configuration in two different types. MasterDataSyncField defines the SAP ECC tables and fields and the mappings to the attributes in Hybris. In addition, we can define a filter as a regular expression, for example to retrieve only non-empty values, descriptions in English or specific sales offices. Finally, to be able to process it correctly in Hybris, we need to know a few extra things such as whether it’s a key, language, or localized field.
The complete item definition is as follows:
The second item type is MasterDataSyncConfig which has a one to many relationship with MasterDataSyncField. Here we define the Hybris item type that corresponds to the SAP customizing table, the sequence of processing and whether it’s an insert or update step. We can use this to first only create items using one table in ECC and in a second step use another table to fill the attributes. With this we can for example create only sales offices assigned to a sales organization as defined in table TVKBZ and then update the description, but not create new ones, using table TVKBT.
We define MasterDataSyncConfig as:
We import the following ImpEx to configure the download of plants (warehouses), sales offices, groups, districts and brands:
We can now create a service DefaultTableSyncService which has method syncTablesForType() which takes the Hybris item type (e.g. Warehouse) as input parameter, reads the configuration, downloads the customizing data from SAP ECC and uploads it to Hybris as defined below.
Not surprisingly in downloadTables() we call the back-end service downloadTable() that we defined in TableSyncBackendERP.
In importTable() we loop over the records from the downloaded SAP table and for each record we do the following. First, we check the values against our defined filter. Second, we determine if we need to create a new item or update an existing one and if this is allowed in this step according to our configuration. And finally, we set the values and save the item model.
The last step we need to do is define and schedule a CronJob that calls the syncTablesForType() method in DefaultTableSyncService. Because we can provide the item type in this call we are able to also differentiate and schedule the download of certain objects on a daily basis and others more frequently.
Our experience with this solution is very positive. The synchronization of data between SAP ECC and Hybris Commerce is less prone to issues which saves a lot of time in monitoring and issue solving. In addition, changes in customizing in SAP ECC now do not require any activity from the Hybris team as they are processed automatically. I'm sure you'll get the same results!