1 How to Automate Rate Updates in a Decision Table in DSM Applies to: SAP Decision Service Management 1.0 (or BRFPlus on SAP NetWeaver 7.02 or above) Summary When using business rules to provide more flexible, adaptable, and provable replacements for traditional Z tables, Decision Tables provide an easy way to hold periodic rates that change over time. Typically these rates are updated annually, e.g. indexed by an inflation factor. The DSM / BRFPlus API provide a convenient way to update rates automatically, avoiding data entry errors and minimizing work for rule owners. We demonstrate how to update a Decision Table holding such rates using the DSM / BRFPlus API. Author: Jocelyn Dart Company: SAP Australia Created on: 25 June 2015 Author Bio Jocelyn Dart is a Platinum Consultant has worked for SAP Australia for over 20 years and worked with over 70 organizations in both the Public and Private Sectors. For the last 3 years she been helping customers implement business rules, and has presented at conferences and run workshops on SAP Decision Service Management and BRFPlus. *** Special thanks is given to Christian Lechner for his gracious assistance in developing the ABAP coding in this example.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
1
How to Automate Rate Updates in a Decision Table in DSM Applies to: SAP Decision Service Management 1.0 (or BRFPlus on SAP NetWeaver 7.02 or above)
Summary
When using business rules to provide more flexible, adaptable, and provable replacements for traditional Z
tables, Decision Tables provide an easy way to hold periodic rates that change over time. Typically these
rates are updated annually, e.g. indexed by an inflation factor. The DSM / BRFPlus API provide a
convenient way to update rates automatically, avoiding data entry errors and minimizing work for rule
owners. We demonstrate how to update a Decision Table holding such rates using the DSM / BRFPlus API.
Author: Jocelyn Dart Company: SAP Australia Created on: 25 June 2015
Author Bio
Jocelyn Dart is a Platinum Consultant has worked for SAP Australia for over 20 years and
worked with over 70 organizations in both the Public and Private Sectors. For the last 3 years
she been helping customers implement business rules, and has presented at conferences and
run workshops on SAP Decision Service Management and BRFPlus.
*** Special thanks is given to Christian Lechner for his gracious assistance in developing the ABAP
Authorize the Executing User of the Batch Program .................................................................................................... 6
Create a Program to execute the DSM API .................................................................................................... 6 Set up the Batch Program variables including the Inflation Factor as a Parameter ..................................................... 6
Access the Decision Table Expression ........................................................................................................................ 8
Get the Properties of the Decision Table ..................................................................................................................... 8
Find the existing row that holds the rate to be inflated ................................................................................................. 8
Read the existing Legislation Period and Rate ............................................................................................................ 9
Calculate the new Legislation Period and Rate .......................................................................................................... 10
Build the new row ....................................................................................................................................................... 10
Lock the Decision Table ............................................................................................................................................. 11
Insert the row in the Decision Table ........................................................................................................................... 11
Activate, Save and Unlock the Decision Table ........................................................................................................... 11
Trigger Deployment of the Decision Table to the Managed System .......................................................................... 12
Testing the Program ......................................................................................................................................... 15
Taking the technique further ............................................................................................................................. 15
Related Content ................................................................................................................................................ 16
Pre-Requisites SAP Decision Service Management 1.0, or BRFPlus on SAP NetWeaver 7.02 or above
o Note: This example was originally worked on a SAP Decision Service Management 1.0 SP01 (SAP NetWeaver 7.40 SP04) system. However the same principles can be used on earlier BRFPlus releases, although some code adjustments may possibly be needed on earlier releases.
Some ABAP development skills
A Rules Application created in the Business Rules (BRFPlus) workbench of SAP Decision Service Management containing:
o A Decision Table with 2 columns:
Condition column holding the Calculation Date (e.g. applicable date of legislation date) to which the rate applies
Action column holding the rate value, e.g. an Amount
For simplicity, the general approach is shown using a simple decision table of 2 columns – date and amount that are to be updated by an annual inflation factor. However it is easy to extend the technique to cover decision tables with additional columns containing other expressions and rule references, but this will not be shown in this document.
Note In the example, for simplicity the inflation factor will be passed as a parameter, and a simple -
multiplication of rate x inflation factor will be used to inflate the rate.
However it is easy (and often preferable) to extend the example to read the inflation factor from a
second decision table, and event to call an additional rule to apply the inflation factor to the rate (e.g.
where explicit rounding rules need to be applied).
Automate Rate Updates of a Decision Table A common practice in many countries is to index rates and other allowances annually to an inflation factor.
If your business rules require you to apply the rate, e.g. to calculate the expected tax you will pay, it’s useful to hold these in decision tables as part of your business rules.
While it’s possible to include an expression in a decision table column to calculate rate x inflation factor dynamically, it’s convenient to apply such inflation factors once and annually via a batch program, for the following reasons:
The decision tables holds the effective dates and rate amounts in their natural and most visible formats, and can be easily reviewed by rule owners and other stakeholders
Changes to the decision table are applied once, annually, rather than each time the table is evaluated, which is better for overall system performance
Changes can be applied automatically, which minimizes the risk of incorrect calculations
The batch update can be scheduled once the annual inflation factor is announced, as inflation factors are often provided by external government agencies
In a DSM system, any related rule functions that use the Decision Table as an expression can also be automatically deployed to the local system(s) as part of the automated batch program.
An example of such a rate is Canada’s Tradeperson’s Tools Allowance:
We will use this rate to demonstrate how to automate updates of a decision table in DSM and BRFPlus.
The only significant difference between DSM and BRFPlus in this example, is:
In DSM we have a final step to deploy the decision table from the central Decision Service Management system where the rules are maintained, to one or more local systems(s) where the rules are executed
Whereas in BRFPlus the changes are applied to the local system immediately, but deployment to any other system must wait until the next IT transport cycle.
The central to local deployment is at the heart of good rules governance in DSM, and permits rules to be deployed rapidly in business timeframes rather than constrained IT timeframes, and deployed wherever the rule is used across the system landscape.
We provide a little background on the Tradesperson’s Tools Allowance to set the scene:
The following chart compares the indexed amounts for the 2015 and 2014 tax years. It reflects an indexation increase of 1.7% for 2015.
2015 2014
Tradesperson’s tools deduction:
Threshold amount relating to cost of eligible tools
1,146 Canadian Dollars, i.e. 1,127 * 1.017
1,127 Canadian Dollars
Canada uses two different tax years for individuals and business, one is a simple calendar year, the other runs from 1
st April to 30
th March of the following year. For the purposes of this example, as many countries
have non-calendar fiscal years, we will use the business tax year.
The steps included in this document show how to create a ABAP program that updates a Decision Table using the DSM / BRFPlus API. The following assumptions are made in the interests of simplicity:
The Decision Table that holds the rate already exists in DSM
The inflation rate will be provided as a parameter to the program
The rate can be inflated by simple multiplication, i.e. new rate = current rate x inflation factor
Rates are updated annually, i.e. new calculation date range = current date range + 1 year
Note The overarching decision service (i.e. BRFPlus function) which uses the Decision Table is not shown and is not
relevant to this technique.
Preparation
Create the Decision Table Tradesperson’s Tools Allowance
Target Decision Table for the updates is Tradesperson’s Tools Allowance
The table has a single condition column Legislation Period of type Timepoint (Date)
The table has a single result column Allowance Amount of type Amount (including Currency)
Create at least one row in the table with the existing allowance amount.
This is the rate that will be inflated by the program.
For our demonstration we’ve entered several of the previous year’s rates to give a better idea of what the content of such a table might look like over time.
5
Figure 1 – Tradeperson’s Tools Allowance decision table with prior year’s value BEFORE update program is run
Optionally: Use the Decision Table as part of a Rules Function
We’ve include a couple of example rule functions that use the decision table so that we can show how handle the deployment. The function context, rulesets and rules themselves are not relevant to this demonstration so we won’t show those.
You don’t need to create these to execute the demo.
Figure 2 - Rules Application hierarchy showing Functions and Rulesets that use the Decision Table
Gather Technical IDs
In preparation for automating decision table updates, gather the technical IDs (i.e. the Globally Unique ID also known as the GUID) from the General section of:
1. The Decision Table
o In the example: Tradesperson’s Tool Allowances
6
Authorize the Executing User of the Batch Program
Ensure the batch user id that will be used at runtime to execute the rate update program has sufficient
authorization (authorization object FDT_OBJECT) to read and update the decision table.
For example, if the rate updates are to be executed via a batch job or web service, a technical user may be
used to execute the rate updates, and that technical user must have sufficient authorization to the rule
objects.
Create a Program to execute the DSM API
To run this example, you’ll need to create an executable program in transaction SE38 on the SAP
NetWeaver (ABAP) platform where you access the DSM or BRFPlus Workbench.
Set up the Batch Program variables including the Inflation Factor as a Parameter
In the example we give the program a parameter P_FACTOR to hold the inflation factor to be applied.
We’ve included all the types, data variables and field-symbols needed.
Note One of the reasons we need field-symbols is that DSM / BRFPlus use a lot of generic and dynamic
referencing so that rule expressions such as Decision Tables can manage whatever data format or
expression reference you require.
If your ABAP is a little rusty hang in there… and maybe buddy up with someone with more recent
knowledge. Or post your questions in the ABAP forum on the SAP Community Network.
It can be useful to grab the name and text description of the table so your batch program can provide a running log of what’s happening as it executes.
Each cell of the new row needs to be filled with the correct values and using the correct format.
The condition column is filled with the legislation period range to which rate the applies.
The result column is filled with the rate amount and currency.
* Ok now we have everything we need to build the new row
DATA(lt_new_row) =
VALUE ts_row_data(
( row_no = 1
ts_cell_data = VALUE #(
"Condition column - Legislation Period
( col_no = lv_date_colno
ts_range = VALUE #(
( sign = 'I'
option = 'BT'
r_low_value = REF #( ls_new_start_date )
r_high_value = REF #( ls_new_end_date ) ) ) )
" Result column - Rate Amount & Currency
( col_no = lv_result_colno
r_value = REF #( ls_new_rate ) ) ) ) ).
11
Lock the Decision Table
The hard part is over. All we need to do now is apply the updates.
As we are going to edit the decision table, we first need to make sure we lock the decision table to prevent anyone else from trying to change it at the same time.
* Lock the table - we do this as late as possible
* so we aren't blocking others unnecessarily
lo_decisiontable->if_fdt_transaction~enqueue( ).
Insert the row in the Decision Table
As we mentioned earlier, the most recent rate should always be at the top of the table. So we just need to insert it as a new row 1. The existing row will automatically become row 2, and any other rows will be pushed down without any additional coding needed in our batch program.
* Put the new row in the table as the 1st row
* as this is now the newest latest and greatest rate
lo_decisiontable->insert_rows(
EXPORTING
iv_row_no = 1
its_row_data = lt_new_row ).
Activate, Save and Unlock the Decision Table
Activating and saving the decision table applies the updates.
Unlocking the decision table allows others to access it again.
* Activate the Decision Table
lo_decisiontable->if_fdt_transaction~activate( ).
* Save the Decision Table – if everything was ok
lo_decisiontable->if_fdt_transaction~save( ).
* Finally unlock the Decision Table
lo_decisiontable->if_fdt_transaction~dequeue( ).
At this stage the decision table has been updated in the Business Rules Workbench.
Notice that a new 1st row has been added and the existing rows have all been pushed down.
12
Figure 3 - Updated Decision Table with new row 1 holding the next legislation period and inflated rate
Note If you are only using BRFPlus, and don’t yet have DSM, then this is the end of the program. To deploy
your changes to other systems, you’ll need to set up a transport change request as usual.
Trigger Deployment of the Decision Table to the Managed System
While the decision table is now activated, in a DSM landscape, it won’t be available by calling applications until it is deployed to the local system in which the calling application is executed.
We need to find affected functions, and redeploy them to their appropriate local system(s).
We’ve kept it simple here and passed in the RFC Destination of the desired local system as a parameter.
First we need to work out which rule functions need to be redeployed. This involves reading up the where-used list hierarchy until we reach a ruleset; then we find the function associated with the ruleset.
Once we find the function we get ready to deploy it. It’s a good idea to fill in the deployment comments explaining what caused the deployment.
* Find any functions in which the decision table is used
WHILE lt_usage IS NOT INITIAL.
UNASSIGN <fs_usage>.
ASSIGN lt_usage[ 1 ] TO <fs_usage>.
CHECK <fs_usage> IS ASSIGNED.
IF <fs_usage>-object_type = if_fdt_constants=>gc_object_type_ruleset.
* The ruleset is the top of the where-used list ...
* ... so find the function associated with the ruleset
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP SE. The information contained herein may be changed without prior notice.
Some software products marketed by SAP SE and its distributors contain proprietary software components of other software vendors. National product specifications may vary.
These materials are provided by SAP SE and its affiliated companies (“SAP SE Group”) for informational purposes only, without representation or warranty of any kind, and SAP SE Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP SE Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
SAP SE and other SAP SE products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP SE in Germany and other countries.
Please see http://www.sap.com/corporate-en/legal/copyright/index.epx#trademark for additional trademark information and notices.