Defining a BRFplus Application

Objectives

After completing this lesson, you will be able to:
  • Create a BRFplus application and assign a function
  • Understand Data objects in BRFplus
  • Unit test your application
  • Integrate your BRFplus function into a business process

BRFplus Application

Functional Mode

In Functional Mode, the typical process flow is as follows:

  1. Application Creation: Begin by creating an application.
  2. Function Creation: Next, create a function.
  3. Data Object Creation: Set up data objects used in the application.
  4. Expression Creation: Create a top expression and assign it to the function.
  5. Context and Result Assignment: Assign data objects to both the context and result of the function.
  6. Object Activation: Activate all relevant objects.
  7. Simulation Run: Simulate the function as a unit test.
  8. Integration: Finally, integrate the BRFplus application and function with your business process application.

Event Mode

In Event Mode, the typical process flow is as follows:

  1. Application Creation: Begin by creating an application.
  2. Function Creation: Next, create a function.
  3. Data Object Creation: Set up data objects used in the application.
  4. Context and Result Assignment: Assign data objects to both the context and result of the function.
  5. Ruleset(s) Creation: Create ruleset(s) for the function.
  6. Rule Creation: Create rule within the ruleset.
  7. Expression and Action Creation: Create the expression and/or action and assign to the rule.
  8. Object Activation: Activate all relevant objects.
  9. Simulation Run: Simulate the function as a unit test.
  10. Integration: Finally, integrate the BRFplus application and function with your business process application.

To be able to successfully run a Function in Event Mode, you need to:

  1. Set the Function Mode to Event Mode.
  2. Assign Ruleset(s) to the Function, which contains the rules that will run on the data.
  3. Set up Function Context - Signature for passing the data to and from BRFplus
  4. Set the Result, as needed.

    Note

    You can set the Result to "Actions" for BRFplus in Event Mode. BRFplus in Event Mode can perform actions in the system, such as posting documents, managing master data, creating tax, or filing obligations, correspondence requests, workflows, and so on. Therefore, in this scenario it is not expected that Functions running in Event Mode return any particular values to the calling program.

Function Context and Result Data Object

Context and Result serve as the interface in BRFplus, facilitating data exchange between calling programs/business processes and BRFplus Functions.

  • Input Parameters: Input parameters are assigned within the Context section.
  • Output Parameters: Output parameters are assigned within the Result Data Object.

Data objects within Context and Result can take the form of Elements, Structures, or Tables.

  • Element Data Objects: These can be of types such as Text, Number, Boolean, Quantity, Amount, and Timepoint.
  • Structure and Table Data Objects: These follow the same principles as classical ABAP.

Attributes defined in the Context serve as input values for processing by a Function or an Expression. The Context can comprise one or multiple elements, structures, or tables, each accessed by its name.

In contrast, a Function or Expression can have only one Result Data Object. However, if a business rule needs to return multiple values simultaneously, this can be achieved by assigning a structure or table as the Result Data Object.

The Context data of a function can be utilized by all sub-expressions belonging to the function's top expression. Input parameters of the expressions are populated either with the function's context or with the results of other expressions.

Function Features and Capabilities

On the Function level, you have access to the following:

  • Simulation

    Built-in simulation allows rule modelers to test the correctness of BRFplus functions in a controlled environment.

  • Debugger

    Analyze the function execution in detail, using debugger functionality.

  • Traces

    Trace the input and output of each rule, in sequence of execution within the function.

  • Generate - RFC module or Web Service

    Generates function code suitable for remote/API calls - service-oriented environments.

  • Create Code Template

    Generate ABAP code for calling the function from external sources (ABAP).

  • Advanced Checks

    Semantic check Rulesets assigned to the function, unversioned objects and inactive objects.

Note

A Function is the rule interface in BRFplus, and acts as a link between the application code and the BRFplus code. A function carries a context and a result. It imports the context from the calling application and returns a result after processing.

Features

  • Mode of Operation: A function can be designed for one of the following modes of operation:
    • Functional Mode: In Functional Mode, function execution starts with the assigned top expression. From this top expression, the processing may run through any number of nested sub-expressions until a result is returned.
    • Event Mode: In Event Mode, the function is associated with a list of rulesets that are executed according to their execution priority and their position in the list.
  • Signature: The function signature consists of two parts:
    • Context: The context is a container for data objects that you can assign as import parameters for the function. You choose the context data objects of a function according to the requirements of the calling application by which the BRFplus function is invoked.
    • Result: The result data object returns a result value that has been calculated by the expressions of which the function consists. Note that for functions in Event Mode, the result data object is automatically set to the predefined Actions table where the actions are recorded that have been triggered by the assigned rulesets.
  • Code Generation: BRFplus provides a built-in code generation facility used to compile source code for many rule constructs in a function as possible.
  • Simulation: You can simulate the function processing to test the function's behavior in a sandbox environment. Here, you can get an in-depth insight into the system status for every single step the system takes during function processing.
  • Trace: In BRFplus, you can request the system to create a trace log in order to keep track of all the events that may arise during function execution. The trace information is stored in the system and can be reviewed at any point in time.
  • Web Services: BRFplus supports the generation of web services for a function. This enables you to integrate the rule execution power of a BRFplus function into a service-oriented software environment.

Creation of an Application

The BRFplus application acts as a container for objects related to a specific set of rules.

Steps

  1. Open the Workbench and click the Create Application button.

  2. Name your application, give it a description and based on what you need, create either a Local or a Transportable object.

    During its creation, developers must make crucial decisions based on the intended purpose of the BRFplus application. It's important to note that once the application storage types are made, they cannot be altered.

    Moreover, to cater to various organizational needs and scenarios, you may consider creating Local BRFplus applications. These are particularly useful for demonstrations, proof of concept, and local testing before full project implementation. Typically, these applications are not intended for transport to other environments.

    Here are the available storage type options:

    • Customizing:
      • Customizing objects enable you to create or modify your system environment.
      • Metadata for customizing objects is always stored in client-dependent tables with a delivery class of C.
      • Customizing objects exclusively reference system objects.
    • Master Data:
      • Master data objects are client-dependent by default and cannot be transported.
      • Metadata for master data objects is stored in client-dependent tables with a delivery class of A.
      • Master data objects can reference both system and customizing objects.
    • System:
      • Objects designated as system objects should remain unchanged.
      • Metadata for system objects is stored in client-independent tables with a delivery class of S.
      • To transport system object metadata, a workbench transport is required.
      • All system object database table names conclude with 'S'.
      • System objects do not reference customizing or master data objects. However, customizing and master data objects can reference system objects.
  3. Select your newly created application, switch to the Contained Objects tab, select Function and click Create.

    To create a BRFplus function, you can either click the Create Object button in the Contained Object tab of the application or right-click on the application in the navigation panel and choose Create → Function from the context menu.

    Note

    Alternatively, right-click on your Application in the Navigation panel, and choose Create → Function from the context menu.

    You can create many objects this way, including Data objects, Rulesets, Rules, and various Expressions.

    Once you've established the BRFplus function shell, you shall add the context and result as function input and output. Then create BRFplus ruleset and rules, defining business rule logic using expressions and/or actions. Finally activate the BRFplus functions.

    Your function is created and set with defaults to enable you to run it in business processes, such as in Tax and Revenue Management:

    • Set to Event mode
    • Result set to ACTIONS

    Next steps:

    • Create data objects and assign to Context
    • Activate your objects
    • Bind additional Context from your ISR scenario
    • Create Rulesets and design rules

Data Objects

Data Object Usage and Availability in BRFplus

Data objects available to the BRFplus application are visible in the Navigation panel, under the Data Object node. Here, you will find all objects available to the application. However, not every object can always be used by every expression in BRFplus.

Based on where data objects are assigned in the hierarchy in BRFplus, they are made available to the specified level, and all the levels below:

  • Function Context data objects are available to all Rulesets assigned to the Function
  • Data objects outside of the Function context must be assigned to the Ruleset directly, before they can be used in expressions.

Navigate the available Data objects within your BRFplus application using the left-side Navigation panel. These objects reside under the Data Object node, categorized into sub-nodes as Elements, Structures, and Tables based on their data type. Every object you create in BRFplus will be displayed in this section. Additionally, any object integrated into a Function's Context or Result will automatically appear here by default.

The following demonstrates the concepts mentioned in the previous slide. Note the Data objects in the Function context, and the object assigned directly in the Ruleset variables.

When correctly defined and assigned, all objects are available to Rules' execution.

Using Data Objects in BRFplus

To utilize Data objects in your rules and expressions, you must define them either in the function context or in the variables section of the ruleset where rules are created and executed. This concept resembles ABAP, where variables need to be defined in the appropriate interface sections of methods and function modules, or within DATA statements in ABAP code before they can be used.

Additional Considerations

It's crucial to note that if a data object is not correctly assigned, the BRFplus engine will return errors upon activation when attempting to use it in a rule or expression. Two common errors that BRFplus developers often encounter are due to missing assignments in the Ruleset context or double assignment of the same object in both the Function and Ruleset context. During activation, the BRFplus engine conducts checks and may generate one of the following messages:

  • Data object XYZ is missing in the Ruleset context, or
  • Data object XYZ is not unique within the Function context.

Application Testing

The simulation tool is utilized for testing BRFplus functions, expressions, or actions. It can be accessed in two ways:

  1. Through the menu via Tools → Simulation.
  2. By clicking the Simulation Button for the specific function, expression, or action.

By default, the tool simulates the last active version of the object, but other versions can be selected using the Date/Time option or the latest inactive version.

Initializing Context Values

You can define context values to initialize the function or expression. These values can be directly entered or imported from an Excel file. Additionally, the data entered on the input screen can be exported to an Excel file.

Simulation Result

The simulation can be run in two modes, each yielding different level of detail of the results:

  1. Show Only Result
  2. Show Result of Intermediate Processing Steps

Interpretation vs. Code Generation

BRFplus simulations can be executed in two modes: interpretation and code generation. The interpretation mode provides more detailed processing steps in the results compared to the code generation mode. Typically, during an application process, only the code generation mode is executed.

Business Process Integration

In the ABAP environment, you can invoke a BRFplus function with ease. Sample code can be generated by clicking the Create Code Template button within the BRFplus function. This code includes the following steps.

  1. Declare Data Variables: Begin by declaring the data variables used in the BRFplus function.
  2. Set Context: Set the function's context with the necessary values.
  3. Get Function Instance: Retrieve the function instance using the object GUID. In real integration scenarios, this step typically involves reading the BRFplus function from configuration to cater to different business scenarios.
  4. Call and Retrieve: Finally, call the function and retrieve the result.

In the context of TRM as one example, the event P330 triggers the execution of a configured BRFplus function during form processing.