SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

Guide to Getting Started with SAP Cloud Platform Business Rules integration to S/4HANA

In this blog, I will explain on how can integrate SAP Cloud Platform business rules with your SAP S/4HANA on-premise applications. It is not step-to-guide for modelling transactional rules. If you are completely new to business rules.

As prerequisite you need to have:

  • On-premise SAP S/4HANA of 1809 or above release
  • Register the ERM Gateway Service in S/4HANA system

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

Note: For ease of understanding for my readers who are familiar with S/4HANA, I have chosen the famous SFLIGHT demo scenario. All the screenshots are based on the business rules showcase project that was build to convey the integration of S/4HANA to SAP Cloud Platform Business Rules.

… let’s get started

1. Setup Cloud Connector

As a default guideline, SAP Cloud Connector application need to be installed and configured for secure connection between cloud applications and on-premise systems.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

2. Configure Destination in SAP Cloud Platform

  • Create destination in SAP Cloud Platform to connect to S/4HANA on-premise system.
  • Test the connection. If the cloud connector is setup correctly and URL, username and password is correct then the connection will be successful.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

3. Create system settings via Configure Systems

System configuration is needed to tell business rules on which backend system resources you are going to model rules. It contains (a) Destination that you have configured to connect to the backend system and (b) Context path which is the relative URL of an internal API that is used to access platform resources. Context path is fixed for each platform type. For example: In this case as we are using SAP S/4HANA system, the context path is as shown in screenshot.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

4. Setup System information in Project properties

By default the system selected in rules project is SAP Cloud Platform. In this case, you need to change the system to one configured via Configure Systems. As you do this, you let the business rules know that you will be modelling rules on the resources of this system.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

5. Define or Import the Data Object

  • You can either import the ABAP CDS views from Import –> Managed Systems option or you can create the data objects

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

  • Define the Annotation for the attribute of the data object.

For S/4HANA on-premise deployment option, the annotation chosen must be ABAP CDS and then provide details of the backend column of the respective CDS view. By this, you provide a mapping between the cloud data object and the backend ABAP CDS view.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

  • Next, define the Annotation for the data object.

For S/4HANA on-premise deployment option, the annotation must be ABAP CDS and then provide the name of the backend CDS view.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

6. Reference in Vocabulary of Rule Service

Till now you were able to set vocabulary of rule either as Input or Result but with the new release you will see one additional usage type: Reference. When you define any data object as Reference in rule service then you inform the rules engine that this data object would not be supplied explicitly during the rule execution instead rule engine has to directly query the associated CDS view in the given backend S/4HANA system.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

7. Annotation in Rule Service

Annotation is a mandatory property in rule service also. For SAP S/4HANA deployment, the annotation-type chosen must be ABAP On HANA as shown in the screenshot

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

8. Model your business rules

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

9. Create ruleset to combine the rules with similar output

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

10. Deploy the rule-service directly from SAP Cloud Platform to S/4HANA on-premise

With S/4HANA on-premise 1809 release, there is a new deployment option available. This new option gives you the flexibility to directly deploy your business rules modelled in cloud into your selected S/4HANA on-premise – with just one click.

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

11. Consuming business rules in S/4HANA application

Once the deployment is successful, you execute the rules via default BRFPlus function:

cl_fdt_brs_processor=>get_instance( EXPORTING iv_function_id = pv_id )

where pv_id is rule service ID.

  • The sample program.

*&———————————————————————*
*& Report ZVR_FLIGHTS_DEMO_SCENARIO
*&———————————————————————*
*&
*&———————————————————————*
REPORT ZVR_FLIGHTS_DEMO_SCENARIO.

TYPES : BEGIN OF ts_customer,
city TYPE c LENGTH 25,
country TYPE c LENGTH 3,
custtype TYPE c LENGTH 1,
discount TYPE c LENGTH 3,
email TYPE c LENGTH 40,
form TYPE c LENGTH 15,
id TYPE c LENGTH 8,
langu TYPE c LENGTH 1,
name TYPE c LENGTH 25,
postbox TYPE c LENGTH 10,
postcode TYPE c LENGTH 10,
region TYPE c LENGTH 3,
street TYPE c LENGTH 30,
telephone TYPE c LENGTH 30,
webuser TYPE c LENGTH 25,
END OF ts_customer.

TYPES : BEGIN OF ts_booking,
agencynum TYPE c LENGTH 8,
bookid TYPE c LENGTH 8,
cancelled TYPE c LENGTH 1,
carrid TYPE c LENGTH 3,
class TYPE c LENGTH 1,
connid TYPE c LENGTH 4,
counter TYPE c LENGTH 8,
customid TYPE c LENGTH 8,
custtype TYPE c LENGTH 1,
fldate TYPE d,
forcurkey TYPE c LENGTH 5,
invoice TYPE c LENGTH 1,
loccurkey TYPE c LENGTH 5,
order_date TYPE d,
passbirth TYPE d,
passform TYPE c LENGTH 15,
passname TYPE c LENGTH 25,
reserved TYPE c LENGTH 1,
smoker TYPE c LENGTH 1,
wunit TYPE c LENGTH 3,
END OF ts_booking.

DATA : lr_data TYPE REF TO data,
lt_name_value TYPE cl_fdt_brs_processor=>t_name_value,
ls_name_value LIKE LINE OF lt_name_value,
ls_cust TYPE ts_customer,
ls_book TYPE ts_booking.

FIELD-SYMBOLS <la_any> TYPE ANY TABLE.

TYPES : ty_carrid TYPE c LENGTH 3,
ty_connid TYPE c LENGTH 4.

SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE TEXT-t01.
PARAMETERS: pv_id TYPE fdt_uuid LOWER CASE,
pv_rad1 RADIOBUTTON GROUP rad USER-COMMAND frad1 DEFAULT ‘X’,
pv_rad2 RADIOBUTTON GROUP rad,
pv_rad3 RADIOBUTTON GROUP rad.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE TEXT-t02.

PARAMETERS: p_carrid TYPE ty_carrid MODIF ID g1,
p_connid TYPE ty_connid MODIF ID g1.

SELECTION-SCREEN END OF BLOCK b2.

SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE TEXT-t03.

PARAMETERS : p_ctype TYPE c LENGTH 1 MODIF ID g2,
p_region TYPE c LENGTH 3 MODIF ID g2,
p_custid TYPE c LENGTH 8 MODIF ID g2.

SELECTION-SCREEN END OF BLOCK b3.

SELECTION-SCREEN BEGIN OF BLOCK b4 WITH FRAME TITLE TEXT-t05.
PARAMETERS : p_ctype2 TYPE c LENGTH 1 MODIF ID g3,
p_bclass TYPE c LENGTH 1 MODIF ID g3,
p_fldate TYPE datum MODIF ID g3.
SELECTION-SCREEN END OF BLOCK b4.

AT SELECTION-SCREEN OUTPUT.

IF pv_rad1 = ‘X’.
LOOP AT SCREEN.
IF screen-group1 = ‘G1’.
screen-active = ‘1’.
ELSEIF screen-group1 = ‘G2’ OR screen-group1 = ‘G3’.
screen-active = ‘0’.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

ELSEIF pv_rad2 = ‘X’.
LOOP AT SCREEN.
IF screen-group1 = ‘G2’.
screen-active = ‘1’.
ELSEIF screen-group1 = ‘G1’ OR screen-group1 = ‘G3’.
screen-active = ‘0’.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

ELSEIF pv_rad3 = ‘X’.
LOOP AT SCREEN.
IF screen-group1 = ‘G3’.
screen-active = ‘1’.
ELSEIF screen-group1 = ‘G1’ OR screen-group1 = ‘G2’.
screen-active = ‘0’.
ENDIF.
MODIFY SCREEN.
ENDLOOP.

ENDIF.

START-OF-SELECTION.

DATA(lo_dsm) = cl_fdt_brs_processor=>get_instance( EXPORTING iv_function_id = pv_id ).

lo_dsm->get_data_object_reference( EXPORTING iv_data_object = ‘_V_RESULT’
IMPORTING er_data = lr_data ).

ASSIGN lr_data->* TO <la_any>.

IF pv_rad1 EQ ‘X’.

DATA : lv_carrid TYPE ty_carrid,
lv_connid TYPE ty_connid.

lv_carrid = p_carrid.
lv_connid = p_connid.

ls_name_value-name = ‘P_CARRID’.
GET REFERENCE OF lv_carrid INTO ls_name_value-value.
APPEND ls_name_value TO lt_name_value.

ls_name_value-name = ‘P_CONNID’.
GET REFERENCE OF lv_connid INTO ls_name_value-value.
APPEND ls_name_value TO lt_name_value.

“Invoke
TRY.
lo_dsm->process( IMPORTING ea_result = <la_any>
CHANGING ct_name_value = lt_name_value ).
CATCH cx_fdt_input INTO DATA(lx_ip).
WRITE : lx_ip->if_message~get_text( ).
CATCH cx_fdt_processing INTO DATA(lx_process).
WRITE : lx_process->if_message~get_text( ).
ENDTRY.

DELETE ADJACENT DUPLICATES FROM <la_any>.

“Display
IF <la_any> IS NOT INITIAL.
cl_demo_output=>display( <la_any> ).
ENDIF.

ELSEIF pv_rad2 EQ ‘X’.
ls_cust-custtype = p_ctype.
ls_cust-region = p_region.
ls_cust-id = p_custid.

ls_name_value-name = ‘CUSTOMER’.
GET REFERENCE OF ls_cust INTO ls_name_value-value.
APPEND ls_name_value TO lt_name_value.

“Invoke
TRY.
lo_dsm->process( IMPORTING ea_result = <la_any>
CHANGING ct_name_value = lt_name_value ).
CATCH cx_fdt_input INTO lx_ip.
WRITE : lx_ip->if_message~get_text( ).
CATCH cx_fdt_processing INTO lx_process.
WRITE : lx_process->if_message~get_text( ).
ENDTRY.

DELETE ADJACENT DUPLICATES FROM <la_any>.

“Display
IF <la_any> IS NOT INITIAL.
cl_demo_output=>display( <la_any> ).
ENDIF.

ELSEIF pv_rad3 EQ ‘X’.

ls_cust-custtype = p_ctype2.
ls_book-class = p_bclass.
ls_book-fldate = p_fldate.

ls_name_value-name = ‘CUSTOMER’.
GET REFERENCE OF ls_cust INTO ls_name_value-value.
APPEND ls_name_value TO lt_name_value.

ls_name_value-name = ‘BOOKING’.
GET REFERENCE OF ls_book INTO ls_name_value-value.
APPEND ls_name_value TO lt_name_value.

“Invoke
TRY.
lo_dsm->process( IMPORTING ea_result = <la_any>
CHANGING ct_name_value = lt_name_value ).
CATCH cx_fdt_input INTO lx_ip.
WRITE : lx_ip->if_message~get_text( ).
CATCH cx_fdt_processing INTO lx_process.
WRITE : lx_process->if_message~get_text( ).
ENDTRY.

DELETE ADJACENT DUPLICATES FROM <la_any>.

“Display
IF <la_any> IS NOT INITIAL.
cl_demo_output=>display( <la_any> ).
ENDIF.

ENDIF.

  • On executing the program above, the screen will look like:

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

You choose among the available rule services, enter the rule service ID and provide the required input values to execute the rule.

  • You can get the rule service ID from the manage rules application URL (after you navigate into the specific rule service) as shown:

https://<hostname>/index.html#//Projects(24f1225e55fe4e248fdf0f62da0fe3e7,000001)/RuleServices(0b629cf05b6e4a1aae42e5701ef4b81d,000001)/view/RuleServiceDetails

Note: You can also get the rule service ID from the ID column (as shown in the screenshot) that you can select/filter from the settings

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

  • You will get to know the Input from the rule service definition

SAP Cloud Platform Business Rules, SAP S/4HANA, SAP Cloud Platform

If you are already working with SAP Cloud Platform Business Rules then it is easy to switch across environment with few configuration steps. Direct deployment to the backend system is the beauty here. If you are new to cloud and looking for rich and unified experience for modelling business rules based on ABAP vocabulary, then you are right place.

Leave a Reply

Your email address will not be published. Required fields are marked *