Quantcast
Channel: SAP Business Rules Management
Viewing all 119 articles
Browse latest View live

September 2015: Reader’s Digest for SAP Decision Service Management (DSM) and Business Rule Framework plus (BRFplus)

$
0
0

Time for another edition of my digest blog series for SAP Decision Service Management (DSM) and Business Rule Framework plus (BRFplus). This edition contains enough content for at least two blogs. Obviously, I should have published another edition earlier but I was too busy working on a new book.

 

 

Automating Rate Updates in DSM and BRFplus

A very nice and instructive document provided by SAP Mentor Jocelyn Dart: “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 provides 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.”

 

 

There is a MONSTER in my Pocket!

Paul Hardy wrote a book about ABAP-related topics. The title of the blog is maybe not what you expected from an SAP Press book. At any rate, it also deals with BRFplus. I had the pleasure of supporting him by adding my input and reviewing some parts of the book. I can tell you that the examples in the book are somewhat … hmm, how should I put this, … let’s agree on unexpected.

 

 

BRF+ Theme change

Not much to add about this blog from M Krishna. The title is more than clear. Should you ever come across a new SAP standard theme that you do not like, you learn how to deal with it here.

 

 

How To: DSM-Decision Service Management / BRFplus in BW-IP

Every thought about using NW DSM or BRFplus in BW integrated planning? This is how you do it. Hans Beuter was a former BRFplus developer before he joined the Planning team.

 

 

Expand your toolbox

I talk to Stefan Weisenberger every now and then about rules because of the Mill and Mining industry’s growing need to modernize IT. Business rules seem to be an important factor and especially the integration of the rules approach into the existing products and into variant configuration is a subject that creates quite some interest, also outside of Mill and Mining. Recently, Stefan created two blog posts about this to demonstrate what is possible:


 

Enhancing DSM Service Import and Deployment

“How to use the DSM Deployment Exit to extend the DSM service import and/or deployment process to perform additional activities.” SAP Mentor Jocelyn Dart and BRFplus support team architect Shweta R Shanbhag have worked out a great description of a scenario in which the DSM Deployment Exit is used to import the service administrative data into the managed system, so that the new lean trace can be displayed directly in the managed system.

 

 

Some interesting improvements in BRFplus and SAP DSM

A blog I recently wrote about some of the great work done by the support team: Improved code generation, support of HTML-formatted emails and performance improvements in activating and saving objects.

 

 

Thank you, contributors!

There would be no community without contributors. Time to thank the folks that run the BRFplus community.

 

 

A new book about DSM and BRFplus (in German)

It was a lot of work but as a team of authors I think we managed it well. With pride I blogged about the new book. Writing is all done now and the final polishing will make it shine even more. Benefit from the knowledge of the authors. You won’t find a better source of information – guaranteed!

book.png

 

Ensuring Rule Modeling Guidelines with BRFplus/DSM

Christian Lechner has made a very interesting point in his blog: Can we use the BRFplus application exit to use BRFplus to check BRFplus, e.g. enforcing guidelines on rules design. It may sound a bit complicated on first read but I find this a brilliant thought and in his blog, Christian shows us how to do it. There are many good reasons why his name is on the cover of the new book. This blog is one of them.

 

 

Use of Formal Language as Challenge in the Design Process of Rule Systems

In his blog, SAP mentor Tobias Trapp sheds some light on the process that is often referred to as rule harvesting. As usual he does not stop at the surface and he also gives some good tips. Tobias has proven in countless contributions that he is a thought leader – and not only for the business rules approach. I was happy to work with him on the new book.

 

 

BRFplus - a hidden gem within your SAP system

A very good blog by Anton Karnaukhov. The title says it all.

 

 

Michal’s Tips: AIF 3.0 value mappings integrated with BRFPlus/DSM

SAP Mentor Michal Krawczyk shows how to use business rules in Application Interface Framework (AIF). The blog is short but sweet. It’s as easy as pie to integrate the two.

 

 

BRFplus: a ferramenta que todo profissional SAP deve conhecer

Do you want information about BRFplus in Portuguese? Are you a BRFplus guru who wants to improve your Portuguese language skills? Fábio Pagoti’s blog will help you in either case.

 

 

Creating Decision Table in BRFplus

A simple tutorial with many screenshots by Manish Kumar.

 

 

Prozessautomatisierung mit BRFplus

AOK Systems has used DSM/BRFplus to automate processes and run them in them in background for better scalability and control. Learn more about the solution in the presentation. Unfortunately, it is avaialbe in German only.

Tobias Trapp and Daniel Ridder of AOK Systems (both are also the authors of the new BRFplus book) helped to make this a really appealing solution. Maybe with the help of DSM/BRFplus, we will see AOK Systems go global someday.

 

 

User Access Review - Custom User Agent using BRF+

Madhu Babu shares his experience from a GRC project in which the client's requirement was to send the User Access Review Workflow to the User for review in the first stage and then to the manager for review. As they couldn’t find a solution in the SAP standard, they developed one with BRFplus. And even better, he is sharing his knowledge with the community!

 

 

New classroom training for DSM and BRFplus

We did a major overhaul of the training material that resulted in a new 3-day classroom training. Look for code DSM100. Find out more about it on the training home page. If there is no training planned in or near your area, please do not hesitate to contact SAP. In the past we have given training courses for companies or even set up open training courses. The last time I held a course, we had to find a bigger room to cope with the demand.

 

 

YouTube Tutorials for BRFplus

 

 

I need you …

…to help me find important news about DSM and BRFplus. With the growing number of new projects, there are lots of job postings and other stuff out there. This makes it more and more challenging for me to create this compilation. If you think I’ve left out an article, blog, or document in my digest, please do not hesitate to contact me and I will add it to the next edition.


Understanding DSM and BRFPlus - the Unified Rendering trap for young players

$
0
0

Possibly my shortest blog ever...

 

So you are using DSM or BRFPlus for the first time and you are faithfully following the tutorials and wandering through the various screens... and then strange things start to happen?!

 

Menus disappear as soon as they appear, checkboxes refuse to check on or off, move up/down icons refuse to be grabbed, radio buttons refuse to click, there are strange and peculiar short dumps happen as  you move from one rule object to the next, text boxes are mysteriously resized, all sorts of crazy stuff is happening. WTF?!

 

What you are experiencing is the joy of Unified Rendering.  Because the DSM workbench and BRFPlus workbench are based on the ABAP WebDynpro protocol, they are susceptible to underlying issues with the ABAP WebDynpro protocol itself.

 

Now for the good news... !

 

Nearly always these are problems that have already been solved.  But if you don't do a lot of ABAP WebDynpro development you may not have heard the term Unified Rendering, and thankfully I am not going to attempt to explain it now either (if you are interested try asking someone in the ABAP forum).

 

All you need to know is that it's the Unified Rendering notes for your release and support pack that you need to fix these bizarre behaviours.

 

You can find the Unified Rendering notes in SAP's support site http://support.sap.com/notes  just search for the term Unified Rendering with your release and support pack.

 

How do you know which release and support pack? Logon to your system using SAP Logon and go to the menu option System > Status then use the magnifying glass icon under Component Version to find the component SAP_UI.  It should look something like this- the first number is the release and the second is the support pack.

SAPUI.JPG

These Unified Rendering notes come as a set of anywhere between 2 and 20 notes per release/support pack. In SAP's support site the matching notes will look something like this.

UniifedRnderingNotes.JPG


What you want to do is to apply ALL of the Unified Rendering notes that match your release and support pack.  Just apply them all in the order specified (I before Ia before Ib, II before III, etc.)  - don't do them piecemeal and don't skip any, otherwise who knows which of those weird and wonderful behaviours will remain?


And don't forget... let the Basis/Admin folk know... anytime they patch the SAP_UI component to a new release/support pack level, just grab the Unified Rendering notes for the new release/support pack level and apply them.


This is one time when prevention is definitely infinitely preferable to the cure. Fixing broken rule objects is not something any of us have a lot of time for.

So get your Unified Rendering notes now... and save yourself from the trap of Unified Rendering issues.

Automated business rule scanner for your custom ABAP code

$
0
0

Motivation

 

Process transparency and the flexible adaption of business processes and rules to constantly changing

market requirements are nowadays challenges for companies.

However, in most organizations the business processes and their rules are hard coded into the business

application. Changes to these business rules are realized with the traditional approaches, which are

often very expensive, time consuming and susceptible to errors.

 

Hence, SAP developed adequate tools, like Business Rule Framework Plus (BRF+) and NetWeaver

Decision Management (DSM), which are used to liberate the hard coded business rules out of the

ABAP applications.

2.png

But how to locate Rules?

 

Sometimes it's not obvious to the consultant or even to the IT expert of the company where the

business logic is implemented between hundreds of ABAP reports. On the other hand it isn't safe that all

necessary rules are considered. The knowledge about the rules might be lost but needed know!

 

Therefore, a new check variant for the SAP Code Inspector tool was developed by me. This check variant

may help you detecting Business Rules in your custom ABAP code. Intended for scanning all of your

reports to display the procedures where business logic is expected most.The results are displayed by

ALV Grid.

4.PNG

But hold on! The code scanner isn't a flawless tool giving always a perfect result. At least a minimum of

false positives could be included in the top score. The calibration of the metrics can help to improve the

inspection. The score list is provided by three different aspects:

 

  • Code complexity
  • Versioning
  • Business vocabulary

 

Let's have a closer look how it works!


1. Complexity

Code complexity metrics can be useful because Business Rules often include many conditions. There are

two complexity analyzer:

 

     a)  Weighted decision depth

          It counts conditional statements like IF, ELSEIF and CASE depending on the current nesting

          depth. The deeper the current level the higher the counting. AND, OR, ELSEIF and WHEN

          (OTHERS) are considered.

           wdd.png

     b)  Maximum nesting depth

          Calculates the highest nesting level of the procedure.

          mnl.png

2. Versioning and date

The next metric determine the number of versions and the date of the last source code modification.

Assuming that business rules are subject of regular edits, reports might have to contain a high

versioning number. Furthermore it's possible to unhide trouble making reports.

 

3. Business vocabulary

The last measure tries to detect procedures which include business vocabulary. It compares every token

of a source code with a particular term database. There is a possibility to add your own specific word

pool. Otherwise you can choose between predefined vocabularies I extracted from the SAP term

database. Distinction between nouns, verbs and adjectives in different languages and application

components are provided.

term_database.png

The metric distinguishes three counter:

 

  • Business vocabulary of the development object name and procedure name
  • Business vocabulary found next to branching statements
  • Business vocabulary in the entire procedure

 

Does it always work?

 

Please remember, the new check variant supports only a heuristic method to locate possible business

rules in your system. It depends to your particular case whether the search is successful or not. And at

least a certain amount of interaction is required. Sometimes the tool won't unhide all rules because they

don't match with the three search aspects, especially when it's simple and forgotten rule logic.Check

out this limitations:

  • Complexity is not everything! Out there are also simple Business Rules with only few parameters
  • Versioning metric isn't effective in every case. Maybe the rule didn't change that often. However

        now the time came for a reengineering process

  • The vocabulary comparison lead sometimes to many false positives

 

Interested?

 

You'd like to get a quick insight into your custom code, in order to find essential hotspots for your

business? then please contact me via e-mail (alexander.schmidt01@sap.com) with a description of your

situation. And of course feel free to share your opinion here with me.

Understanding DSM - That's so meta! and the Assigned to Managed System feature

$
0
0

"So I just saw this film about these people making a movie, and the movie they were making was about the film industry..."

"Dude, that's so meta. Stop before my brain explodes."

Urban Dictionary: meta

 

One of my favourite features of Decision Service Management is the neat way it handles metadata references, so that I can create rules for any managed system (i.e. a system whose rules are governed by DSM) referencing data dictionary definitions, database tables, function modules and ABAP classes *without* having to transport those objects into the DSM system itself.  It really is a very cool answer to enabling all sorts of calling applications to integrate with decision services (aka BRFPlus rule functions) without overburdening either the DSM or the managed system.

 

But if you are new to DSM, it does take a minute or two to wrap your head around how metadata works, and how that impacts what you need to do in DSM.

 

Why we need metadata

DSM acts as a central rules build, test and governance environment across multiple managed systems.  Those multiple managed systems could be the DEV, QA and PRD instances of ECC, SRM, CRM, HANA, etc.  With such a broad mix of systems there are always going to be occasions when we need metadata to cope with the differences between systems.  Typical use cases are:

 

1. Different managed systems have different dictionary objects.

E.g. the database table CRMD_ORDERADM_H exists in a CRM system but not in ECC or SRM.

DSM needs to know whether that dictionary object can be used in a rule or not, i.e. will the rule run in CRM or in SRM or in ECC or HANA?

 

2. Different managed systems can have the same dictionary object but that same dictionary object might have a different definition.

E.g. The structure  ZMyTableType might have 5 fields in QAS and PRD, but in DEV it has 7 fields as it is being extended as part of a project.

DSM needs to know whether the structure matches what the rule is expecting - i.e. have the new fields been transported from DEV to QAS yet - before it can deploy the updated rule to the QAS system.

 

3. Different managed systems have different database tables, function modules and ABAP Classes.

If a rule is using a DB Lookup expression to search a database table, or a Procedure Call expression to call a function module or ABAP Class method, then DSM needs to know if the database table, function module, or ABAP Class method exists in the managed system.

 

Now of course DSM could maintain a remote connection to all of the managed systems all of the time, just to make sure everything was in synch.  But that's rather tedious and inconvenient, especially when different systems may need to be down for maintenance at different times.  It's even more annoying for sandpit systems, where the system may be here one day but gone the next. You don't really want to have to go clean up all those rules, especially after a successful proof of concept when you want to retain your rules as much as possible so you can redeploy them to your DEV system to start the productive project.

 

So DSM is smarter than that.  It uses metadata so that:

 

a) It only contacts the managed system at certain points to confirm if the metadata has a match in the managed system.

 

b) It only holds metadata references not the actual metadata itself.

Think of the metadata reference as a kind of copy of the essential details that DSM needs, so that the actual metadata - dictionary objects, function modules, ABAP Classes, etc. - never need to be transported into DSM itself.   The metadata reference means DSM knows enough about them so that the rules build can continue without the managed system having to be available all the time.

 

Baselining metadata: Assignment to Managed System

For DSM to use metadata references, it needs to know that metadata is needed and which system to use as a baseline for metadata references.  In other words it needs to know which system is the source of truth for the correct version of the metadata.  That way if it is deploying the same rule to more than one managed system, such as ECC DEV, ECC QAS, and ECC PRD, it knows which version of the metadata is needed, and can check that the metadata reference DSM has matches the actual metadata in the managed system *before* it deploys the rule function.

 

Usually we want the DEV system to be the baseline, so that we follow the transport sequence between the managed systems themselves.

For example:

  • Say you have a decision service that will be deployed to executed in ECC DEV, ECC QAS, and ECC PRD.
  • We make ECC DEV is the assigned managed system for the decision service.
  • DSM gets the metadata references from the ECC DEV system.
  • Once the actual metadata of the dictionary objects, function modules, ABAP Classes, etc. used by the decision service are transported from ECC DEV to ECC QAS, the decision service can be deployed to ECC QAS.
  • In a similarly way similarly changes are progressed from ECC QAS to ECC PRD.

 

The way we baseline the metadata in DSM is we assign the rule application which holds the rule function to the managed system.  In other words all data objects, rule objects including expressions and rule functions, and even certain exit classes are covered as using the same metadata baseline.

 

Each rule application can be assigned to only one managed system at any one time (more about reassigning later).  Each managed system can be assigned to as many rule applications as needed.

 

Tip: Note just because a rule application is assigned to a managed system, it doesn't mean that every data object needs to use a metadata reference.  Decision services can still use BRFPlus native data types (such as Timepoint, Amount, Text, etc.)  freely.  Assigning the rule application to a managed system just gives us the option to use metadata references where they make sense.

 

And although this is a MUCH bigger topic for another blog another time, it does give you a clue as to one of the reasons for putting different rule functions in different rule applications, i.e. all the rule functions in the same rule application need to baseline metadata against the same managed system.

 

So say you have decided you need to assign the application to managed system.  There are two(2) main times that you normally do this:

  1. When you create a new rules application in DSM
  2. When you import an existing decision service from the managed system (i.e. during migration to DSM)

 

Explaining these options in a little more depth...

 

Option 1: When you create a rules application directly in DSM, you can assign it to a managed system.

You can do this by creating the rules application directly in the Decision Service Manager workbench by selecting the managed system in Edit mode, and then using the New button on the Application tab to create the rules application.  The rules application is then automatically assigned to the managed system.

DS_Metadata3.JPG

 

Option 2: When you perform a service import bringing an existing BRFPlus function or application into DSM, as part of migrating from local BRFPlus to DSM, you can assign it to a managed system.  By assigning the managed system during the service import, any existing metadata references will be interpreted correctly, i.e. checked against the actual metadata of the managed system and not the actual metadata of the DSM system itself.

 

The easiest way to do this is in the Decision Service Manager workbench.  Select the managed system in Edit mode, go to the Service Import tab, start the Search for Active Services, find the service you want to import, and start the import by pressing the icon button in front of the service.

DS_Metadata4.JPG

 

In the pop-up window where you confirm the service that you are importing from the managed system, simply tick the checkbox "Assign application to managed system".

DS_Metadata5.JPG

 

Although these are two main times we assign the managed system, it doesn't matter too much if you change your mind later.  You can reassign the managed system at any time.  The easiest way to do to this is in the DSM Workbench by selecting the managed system in Edit mode and using the Add button on the Application tab.  This is a great option when you are migrating decision services used as part of a proof of concept from a sandpit managed system to the development managed system.  And also when you want your rules developer to create the rules application itself in the BRFPlus workbench of DSM itself, but restrict access to the Decision Service Manager workbench to your DSM administrator, who then assigns the rule application to the appropriate managed system advised by the rules developer.

 

 

Reassigning the managed system

While it is possible to reassign the managed system at any time, and we've found this sometimes confuses people new to DSM.  Sometimes I have found that people misinterpret this option to think that when you redeploy a rule from DEV to QAS you have to reassign the rule from DEV to QAS. That is incorrect.  The assigned managed system remains the baseline for metadata references.  The assigned managed system doesn't in any way restrict your choice of target managed system for deployments.

 

In a typical scenario, DEV is the assigned managed system.  As the actual metadata is transported by the usual CTS (Change and Transport system) from DEV to QAS to PRD, all that's needed is for DSM to deploy to each target system.  The assigned managed system doesn't need to change.

 

DS_Metadata1..JPG

So how does DSM know it's safe to deploy to QAS and PRD? Well that's the smart bit... prior to deploying it validates whether the actual metadata in the target managed system match the metadata references in DSM.

 

For instance, if an Element Data Object references a ABAP Dictionary Data Element, the name, type and length need to match. If the actual metadata doesn't match the metadata references the deployment will stop and give appropriate error messages on the log indicating which metadata references don't match.

 

This avoids decision services being accidentally deployed to the wrong managed system, e.g. avoid a ECC rule being deployed to a SRM system.

And it also avoids decision services being deployed too early (i.e. before the actual metadata itself has been transported) to the right managed system.

 

Validation points for metadata

 

In fact there are several validation points where metadata references can be checked.  The important pre-requisite is that the managed system must be available and connected to DSM at the point of validation.  If the managed system is not available, DSM will give an error indicating this.  You won't lose any data or settings in DSM when this happens. At most you won't be able to update the reference until the managed system comes back online.

 

These are the major milestones where metadata references are checked:

  • On Creation of a data object or expression when choosing the option to set up a binding, e.g.to bind a Data Object to a Dictionary object
    • This creates a single metadata reference
  • On Refresh Binding, by explicitly choosing the Refresh Binding when maintaining a data object
    • This checks a single metadata reference
  • On update of an expression that uses one or more metadata references, such as DB Lookup or Procedure Call
    • For instance if you want to map another parameter in a procedure call, the metadata references will be checked to make sure the metadata references to the signature of the function module or ABAP Class method are up to date. Note that the metadata references are typically only checked when needed, e.g. if all you are doing is changing the mapping of an existing parameter, DSM doesn't need to check the metadata references
  • On Deployment Test in the Decision Service Manager workbench
    • This is a great feature that lets you check all the metadata references related to a decision service or rule application against any managed system at any time, e.g. when someone tells you they think the actual metadata objects have been transported from DEV to QAS, but they aren't sure...
  • On Deployment
    • This happens at the start of deployment, so it is a pre-deployment check of all the metadata references related to the decision service (rule function) being deployed.  If the check fails, the deployment will be stopped.  The rules developer then needs to resolve any issues - e.g. by chasing up the actual metadata transport or refreshing the binding in DSM - before starting a new deployment.

 

The diagram below explains a typical flow of creation of metadata reference through to deployment using a Decision Service ABC with a metadata reference to a data element ZZCUSTOM.  Although this example uses a single metadata reference, a decision service could potentially have many metadata references.

 


DS_Metadata2.JPG

 

 

Special considerations for Common Rules

 

What happens if you want to create common decision services or rules objects that are deployed to multiple target systems? Say you have a set of decision tables with certain rates and factors that you want to share to ECC, CRM, SRM and HANA.  How do you handle metadata references then?

 

There are basically two(2) choices:

  1. Make sure any metadata references are to actual metadata that exists in all of the target managed systems.
  2. Only use native BRFPlus data types, do NOT assign to a managed system, and avoid metadata references altogether

 

Having faced this situation myself on customer sites, my preference is for option 2 - only use native BRFPlus data types in common rules.  While option 1 is possible it's all too easy for rule developers to forget and create an unwanted metadata reference that is a pain to fix up afterwards.

 

What you really don't to have to do is to create a special CTS transport that transports the actual metadata references to all target systems.  It will work - if done properly - but it tends to require advanced CTS configuration, landscape and governance, for what is typically a very small set of exceptions and that generally leads to unnecessary confusion for developers and administrators... and delays in getting your decision services deployed.

 

Viewing metadata references in the BRFPlus workbench (of DSM)

What if, as a rules developer, you don't have access to the Decision Service Manager workbench?  How can you see whether a metadata reference exists or is possible?

 

If you are working in the BRFPlus workbench of DSM, then you can see the Assigned to Managed System icon next to the rule application and against any data object or expression which uses metadata references.  The icon looks like this:

DS_Metadata7.JPG

You should see the icon in the title area of the relevant rule application, data object or expression. For example:

DS_Metadata6.JPG

Once the rule application has been assigned to the managed system, you don't need access to the Decision Service Manager workbench to create metadata references. That's all just normal rules build in the BRFPlus workbench of DSM.

 

One final caution:

The one thing that can break your metadata references is changing the name of the actual metadata that it refers to.  For instance if you have a data element called ZZCUSTOM in your managed system, and you change the name to ZZCUSTOM1 that will break your metadata reference.  Which means you will need to not only Refresh Binding but also will often need to remap any references in your rule objects to that field.  This is even more of a pain when dealing with structures and tables. 

 

The easiest way to avoid these problems is to encourage developers who are creating the actual metadata to use your corporate naming conventions from the beginning - even in sandpit systems.  Then you minimize the number of metadata changes you need to deal with.

 

So I hope this blog clarifies how Assigned to Managed System and metadata references work in DSM.

Enjoy your metadata and if you have any queries about metadata make sure you post a discussion in the Business Rules Management community!

How to Compare two BRFplus Rule Systems?

$
0
0

In this blog I sketch a solution for comparing BRFplus rule systems. I’ll discuss the use case and I would be interested in your feedback. Also I would like to know whether other people are working on the same topic and would like to exchange source code. Maybe this could lead to the first open source project in the area of BRFplus.

 

Use Cases

At first I think that comparison of objects like different rule systems is a value in itself because the concept of equality resp. inequality is one of most profound ones I know in philosophy and mathematics. But there are also more business cases:

  • In larger development projects sometimes rule set are shipped which contain an implementation of decision logic. Often they are shipped as implementation accelerators, used for tests and are altered afterwards.
  • Sometimes people don’t want to change a rule system and copy it instead, do some changes, test it, and ship it after that. Then a comparison is useful.
  • Rule systems are generated/changed using metadata and the BRFplus API. You want to check the results by comparing them.

 

Let us look at the first described scenario. I develop rule systems that have be to compliant to legislation and shipped to different organizations as applications of storage type system. These implementations are mostly stable due to compliance reasons and there one is only allowed to change them minimally and only in certain parts. Usually business experts use my rule systems as template and copy and alter it. Later the comparison is useful to control what has been changed:

  • A revisior or auditor wants to analyze the adaptations.
  • If a have to change my template application (because it contained an error or legislation changed) a comparison after the import is helpful when the copied rule system has to be changed.
  • Sometimes organizations evolved the rule systems in a different way. Now they want to check the difference and perform harmonization or even want to implement a common version.

 

So please let me summarize: comparison of different rule systems can be part of a usual maintenance and evolution process. It becomes necessary if you have a couple of organizations that have rule systems that are quite similar and evolved from the same template of decision logic. But there are other use cases when comparison of decision logic is useful.

 

The Challenge

Comparing two rule systems is difficult. BRFplus has only functions for comparing two rule set versions. The transaction FDT_HELPERS contains a report that checks whether two versions are identical. This is useful if you want to check whether a transport was (successfully) imported into a system. But it is not that useful for our purposes.

 

So we need to develop a solution by ourselves. The challenge is that BRFplus does have an object oriented API but provides no simple textual representation of the rules. But there are more problems: we have to define when two BRFplus artifacts are identical:

  • Are two objects different if their technical name is different? If you allow that the technical can be different – how do you identify corresponding BRFplus entities that you want to compare?
  • Which metadata should be considered or not considered in the comparison? The information which user performed the change and the specific time should not matter for example.
  • Should the flag whether a rule set is active or not active be considered in the comparison? This depends on the use case: when you deliver a rule set assigned to a BRFplus function as template, then it is likely that it is not enabled. In this case, the user copies the rule set, sets it to active and perhaps alters it.

 

This shows the following: the comparison of two BRFplus applications is no trivial task and depends on the scenario i.e. the way that a rule system is copied and changed when working with a template. So I came to the conclusion that it would be useful to have a library with different utility functions.

 

My Approach

After some experiments with the BRFplus API it became clear that this is not the right tool for comparisons. I also learned the especially the structure of the rules is very complex and they are hard to compare. Moreover I decided that a need a flexible toolset that would allow different kinds of comparisons.

 

My solution uses the XML representation of an BRFplus application. This representation is far from being readable. When you look at the structure of an XML document you will see that it contains on different artifacts which can be seen in the picture below. The most important entity is the expression which are grouped as elements FDTNS:EXPRESSION and are identified using IDs. More complex objects like conditions of rules refer to expressions by their IDs.

expr.PNG

So f.e. a rule consists of conditions which are in fact expressions. In the XML representation the ID is stored and the expression with this ID is stored somewhere else in the XML document.

 

If you want to compare two BRFplus entities (f.e. two rules) one approach is to replace each occurrence of its expressions (think of a condition defined by its ID) with the content of the corresponding XML element which is stored in another part of the XML representation. If you do this in recursive way you will “expand” the BRFplus entity to a tree containing all relevant in expressions. This can be done easily using an iteration of the following XSL transformation which can be performed using the CALL TRANSFORMATION command in ABAP:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match=
"FDTNS:RULES/FDTNS:item/FDTNS:RULE_ID |
                      FDTNS:EXPRESSION_ID |
                      FDTNS:CONDITION |
                      /FDTNS:FDT/FDTNS:RULESET/FDTNS:COND_RANGE/FDTNS:PARAMETER_ID">
    <xsl:variable name=
"id" select="string(.)"/>
    <xsl:choose>
      <xsl:when test=
"count(/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id])>0">
        <xsl:copy-of select=
"/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select=
"node() | @*"
/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

 

If you have now a rule that is copied from another rule and both are using the same data elements then you compare them using a simple string compare. But before you have to remove the administration data since timestamps, change user and so will be always different. This can be done using the following transformation:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
    </xsl:template>

  <xsl:template match=
"FDTNS:ADMIN_DATA"/> <!-- Don't copy this element -->

</xsl:transform>


Another important operation for the above mentioned string comparison is the extraction. This can be performed also in XML. Here I show how to extract a certain rule in a rule set using XSLT:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:param name=
"POSITION"/>
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"/">
    <xsl:copy-of

select="/FDTNS:RULESET/FDTNS:RULES/FDTNS:item[string(FDTNS:POSITION)=string($POSITION)]"/>
  </xsl:template>
</xsl:transform>

 

Using those transformations you can “expand” two applications, remove administration data, extract parts and compare them using string comparison.

And this is what I implemented and tested successfully.

 

Summary

I discussed some use cases for rule system comparison and described the main ideas of my implementation. Now I have following questions for the BRFplus community:

  • Is someone working on the same problem?
  • Are there other approaches?
  • If someone is working on the same approach, is there interest in sharing the source? Maybe we could start an Open Source project by combining our source code.

Root Cause Analysis of Rule System Execution – One Step forward towards to Intelligent Decision Making

$
0
0

In this small blog entry I will introduce a research project if mine. I will introduce a use case, a model without using too much mathematics and will explain my next steps. I always appreciate comments, further suggestions and I hope to connect with other people from academia and business, who are working on the same problem.

 

The Need for Root Cause Analysis

We are using BRFplus to check business objects like insurance claims in automated processes. Sometimes those insurance claims are very complex – think of special care for example. The rule systems are quite huge and can be implemented in BRFplus using decision tables having some hundred rows.

 

The result of the rule set execution is a set of conspicuous features that have to be controlled by officials in a workflow based task management. This can be complex if the result of BRFplus execution consists of dozens of tasks. And in many cases it is possible that the execution of one task leads to a recalculation of the business objects which closes other tasks.

 

To optimize the working process of an official it is necessary to find the root cause and create and prioritize the tasks. But root cause analysis can be useful in dialog processes as well: the complex complex result of rule system execution can be presented in a way that the SAP user who works on that insurance case can understand easily what the problem is. This speeds up the whole work process and can also increase the service quality of an insurance company.

Please note that looking for root causes is different from rule system trace. I don’t want to show how a rule system execution was performed – I want to explain the behavior.

 

Abductive Reasoning

As I explained above we are looking for root cause. Sometimes a simple set of facts (represented my master or application data) can explain dozens of suspicious features: one special insurance policy is missing, some medical treatments are restricted to the age of the insurant and so on.

Finding explanations is a task for logical abduction – which was introduced by the philosopher and mathematician Peirce. Those methods can be applied in systems but also medical diagnosis. So this is what Dr. House is doing in his show.

Download.jpg

I don’t want to go into detail into the topic but you should be aware of the following:

  • Explanation is usually more complex then proving.
  • Often we are looking for “simple” solutions. This is challenging since it is hard to define simplicity. And you can also question this approach: sometime the “simple” explanation is not correct what you can see in the show of Dr. House from time to time J
  • The concept of simplicity leads to non-monotonic logic which is different compared to first order logic that we use in the foundations of set theory and so (modern) mathematics.

 

My little Contribution

When working with decision tables I found the standard approach of mathematical logic no very effective. As a consequence I tried to find out how a business object like an insurance claim has to be altered that many conspicuous features vanish.

This is not very difficult and leads to well understood combinatorial problems like set covering. Nevertheless I decided it to write it down in terms of mathematical logic although other formulations like Boolean functions are possible, too.

 

If you are interested you can read a draft version here. But please be warned, it is only a draft and I tested the approach with random data. I already got valuable feedback from SAP Mentor colleague Peter Langner which still has to be included. He also mentioned the concept of information flows which I have to

read and understand.

 

Next Steps

At the moment I am thinking of a BRFplus implementation of my approach. I think I will have to try out whether BRFplus API and or execution trace are sufficient for it. But I would also like to have the feedback from scientists who are experts in this area – I only consider myself as a beginner. May be we could also write a paper. In the past I worked together with one colleague from SAP UK who is also researcher at the University of Belfast. It contains a mathematical model that helps to understand the behavior of rule systems working with ambiguous data. Our paper was accepted KES-IDT-15 conference about intelligent decision making.

8767.jpg

 

For me the participation was one highlight of the year and I learned a lot. The most important learning was that my mathematical skills became a little bit rusty so I appreciate any help. I am convinced the Decision Making and Decision Making Technologies is one of most promising and interesting areas and cornerstone of Next Generation ERP Systems. Today Enterprise Resource Planning is not so smart but with technologies like DSM and HANA SAP provides edge technologies. It is our task to use them to develop business applications that use these technologies to create amazing new solutions. I appreciate any help from students with skills in optimization and artificial intelligence.

Neues Buch zu BRFplus und DSM: "Business Rule Management mit ABAP"

$
0
0

BRFplus—Business Rule Management for ABAP Applications

Vor rund 5 Jahren habe ich in einem Blog das erste Buch zu BRFplus angekündigt. Nach Monaten der harten Arbeit von Thomas Albrecht und mir war es im Dezember 2010 soweit. Seitdem hat sich das Buch sehr gut verkauft und unser Verlag hat den Kontakt zu uns nicht abgebrochen.   

BRFplus_Book.png

 

Business Rule Management mit ABAP - BRFplus und SAP Decision Service Management

In der Zwischenzeit hat sich BRFplus natürlich erheblich weiterentwickelt und mit DSM sind ganz neue Möglichkeiten der Nutzung von Geschäftsregeln hinzugekommen. Nach Gesprächen mit Verlag und potentiellen Koautoren haben wir uns entschieden keine neue Auflage zu veröffentlichen, sondern in einem größeren Kreis ein neues Buch zu schreiben. Zum Kreis der Autoren gehören neben Thomas und mir auch Christian Lechner, Tobias Trapp, Daniel Ridder, Wolfgang Schaper und Matthias Kucharska. Wie beim letzten Buch haben wir uns auch dieses Mal für ein SAP Press - Buch entschieden, das in Deutschland vom Verlag Rheinwerk herausgegeben wird. Nun ist die Arbeit fast geschafft. Der letzte Feinschliff wird gerade angebracht. Auf der Verlagsseite und im Buchversand werden bereits Vorbestellungen entgegengenommen. Lieferbar ist es ab dem 26. Oktober 2015. Bei Rheinwerk kann neben der gedruckten Ausgabe auch ein E-Book erworben werden. Das Buch (ISBN 978-3-8362-3743-7)erscheint in deutscher Sprache und hat circa 550 Seiten.

BRFplus_DSM.png

 

Aus dem Inhalt

  • Modellierung und Anwendung von Geschäftsregeln
  • Einsatzszenarien
  • Regelsätze und Regeln
  • Ausdrücke und Aktionen
  • Test und Transport regelbasierter Anwendungen
  • Integration mit SAP Business Workflow und BOPF
  • Erweiterungsmöglichkeiten
  • Fehleranalyse
  • Best Practices
  • Vorgehen in Geschäftsregelprojekten

Die Zusammenarbeit mit den anderen Autoren war sehr angenehm. Vielen Dank! Wir konnten unterschiedliche Sichtweisen und Erfahrungswerte in Kapiteln wie Einsatzszenarien, Best Practices oder Fehleranalyse vereinen. Damit stellt das neue Buch viele Inhalte zur Verfügung, die in unserem ersten Buch nicht berücksichtigt wurden. Ich bin sehr gespannt auf die ersten Rückmeldungen.

 

 

This blog is about a new book for DSM and BRFplus. The book will be published in German language. Therefore, the blog is written in German.

How to Compare two BRFplus Rule Systems?

$
0
0

In this blog I sketch a solution for comparing BRFplus rule systems. I’ll discuss the use case and I would be interested in your feedback. Also I would like to know whether other people are working on the same topic and would like to exchange source code. Maybe this could lead to the first open source project in the area of BRFplus.

 

Use Cases

At first I think that comparison of objects like different rule systems is a value in itself because the concept of equality resp. inequality is one of most profound ones I know in philosophy and mathematics. But there are also more business cases:

  • In larger development projects sometimes rule set are shipped which contain an implementation of decision logic. Often they are shipped as implementation accelerators, used for tests and are altered afterwards.
  • Sometimes people don’t want to change a rule system and copy it instead, do some changes, test it, and ship it after that. Then a comparison is useful.
  • Rule systems are generated/changed using metadata and the BRFplus API. You want to check the results by comparing them.

 

Let us look at the first described scenario. I develop rule systems that have be to compliant to legislation and shipped to different organizations as applications of storage type system. These implementations are mostly stable due to compliance reasons and there one is only allowed to change them minimally and only in certain parts. Usually business experts use my rule systems as template and copy and alter it. Later the comparison is useful to control what has been changed:

  • A revisior or auditor wants to analyze the adaptations.
  • If a have to change my template application (because it contained an error or legislation changed) a comparison after the import is helpful when the copied rule system has to be changed.
  • Sometimes organizations evolved the rule systems in a different way. Now they want to check the difference and perform harmonization or even want to implement a common version.

 

So please let me summarize: comparison of different rule systems can be part of a usual maintenance and evolution process. It becomes necessary if you have a couple of organizations that have rule systems that are quite similar and evolved from the same template of decision logic. But there are other use cases when comparison of decision logic is useful.

 

The Challenge

Comparing two rule systems is difficult. BRFplus has only functions for comparing two rule set versions. The transaction FDT_HELPERS contains a report that checks whether two versions are identical. This is useful if you want to check whether a transport was (successfully) imported into a system. But it is not that useful for our purposes.

 

So we need to develop a solution by ourselves. The challenge is that BRFplus does have an object oriented API but provides no simple textual representation of the rules. But there are more problems: we have to define when two BRFplus artifacts are identical:

  • Are two objects different if their technical name is different? If you allow that the technical can be different – how do you identify corresponding BRFplus entities that you want to compare?
  • Which metadata should be considered or not considered in the comparison? The information which user performed the change and the specific time should not matter for example.
  • Should the flag whether a rule set is active or not active be considered in the comparison? This depends on the use case: when you deliver a rule set assigned to a BRFplus function as template, then it is likely that it is not enabled. In this case, the user copies the rule set, sets it to active and perhaps alters it.

 

This shows the following: the comparison of two BRFplus applications is no trivial task and depends on the scenario i.e. the way that a rule system is copied and changed when working with a template. So I came to the conclusion that it would be useful to have a library with different utility functions.

 

My Approach

After some experiments with the BRFplus API it became clear that this is not the right tool for comparisons. I also learned the especially the structure of the rules is very complex and they are hard to compare. Moreover I decided that a need a flexible toolset that would allow different kinds of comparisons.

 

My solution uses the XML representation of an BRFplus application. This representation is far from being readable. When you look at the structure of an XML document you will see that it contains on different artifacts which can be seen in the picture below. The most important entity is the expression which are grouped as elements FDTNS:EXPRESSION and are identified using IDs. More complex objects like conditions of rules refer to expressions by their IDs.

expr.PNG

So f.e. a rule consists of conditions which are in fact expressions. In the XML representation the ID is stored and the expression with this ID is stored somewhere else in the XML document.

 

If you want to compare two BRFplus entities (f.e. two rules) one approach is to replace each occurrence of its expressions (think of a condition defined by its ID) with the content of the corresponding XML element which is stored in another part of the XML representation. If you do this in recursive way you will “expand” the BRFplus entity to a tree containing all relevant in expressions. This can be done easily using an iteration of the following XSL transformation which can be performed using the CALL TRANSFORMATION command in ABAP:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match=
"FDTNS:RULES/FDTNS:item/FDTNS:RULE_ID |
                      FDTNS:EXPRESSION_ID |
                      FDTNS:CONDITION |
                      /FDTNS:FDT/FDTNS:RULESET/FDTNS:COND_RANGE/FDTNS:PARAMETER_ID">
    <xsl:variable name=
"id" select="string(.)"/>
    <xsl:choose>
      <xsl:when test=
"count(/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id])>0">
        <xsl:copy-of select=
"/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select=
"node() | @*"
/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

 

If you have now a rule that is copied from another rule and both are using the same data elements then you compare them using a simple string compare. But before you have to remove the administration data since timestamps, change user and so will be always different. This can be done using the following transformation:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
    </xsl:template>

  <xsl:template match=
"FDTNS:ADMIN_DATA"/> <!-- Don't copy this element -->

</xsl:transform>


Another important operation for the above mentioned string comparison is the extraction. This can be performed also in XML. Here I show how to extract a certain rule in a rule set using XSLT:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:param name=
"POSITION"/>
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"/">
    <xsl:copy-of

select="/FDTNS:RULESET/FDTNS:RULES/FDTNS:item[string(FDTNS:POSITION)=string($POSITION)]"/>
  </xsl:template>
</xsl:transform>

 

Using those transformations you can “expand” two applications, remove administration data, extract parts and compare them using string comparison.

And this is what I implemented and tested successfully.

 

Summary

I discussed some use cases for rule system comparison and described the main ideas of my implementation. Now I have following questions for the BRFplus community:

  • Is someone working on the same problem?
  • Are there other approaches?
  • If someone is working on the same approach, is there interest in sharing the source? Maybe we could start an Open Source project by combining our source code.

Reading the Data of Decision Table using BRF+ API's

$
0
0

Hi All,

 

Let us read the below decision table using BRF+ API code in a report

DT Table in brf+.png

 

Using following code you can read the decision table data in a report.Just copy paste the below code.But change the GUID'S ,structures as per your requirement.

 

 

*The application guid

CONSTANTS:  gc_appl_id                TYPE if_fdt_types=>id  VALUE '005056C000081EE58CD3919CB9A80957'.

*create a structure as per the Decision table

types:BEGIN OF ts_msg_txt_data,

               level         type char24,

               age           type char24,

               pricing       type char24,

               base          type char24,

               currency_base type char24,

     END OF ts_msg_txt_data,

*Create a structure for the row count

     BEGIN OF ts_table_data,

            row_no                   TYPE int4,

            col_no                   TYPE int4,

            expression_id            TYPE if_fdt_types=>id,

            r_value                  TYPE REF TO data,

            ts_range                 TYPE if_fdt_range=>ts_range,

       END OF ts_table_data .

* data declarations

DATA: lref_decision_table            TYPE REF TO   cl_fdt_decision_table,

      lref_factory                   TYPE REF TO  if_fdt_factory,

      lt_msg_data                    TYPE          if_fdt_decision_table=>ts_table_data,

      ls_msg_data                    LIKE LINE OF  lt_msg_data,

      lt_table_data_msg              TYPE TABLE OF ts_table_data,

      ls_table_data_msg              TYPE          ts_table_data,

      ls_table_data1                 TYPE          ts_table_data,

      lt_msg_txt_data                type STANDARD TABLE OF ts_msg_txt_data,

      ls_msg_txt_data                type ts_msg_txt_data,

      ls_range_msg                   TYPE          if_fdt_range=>s_range.

*field symbols declaration

FIELD-SYMBOLS :<fs_lv_value> type any,

               <fs_lpw_lv_amount>       TYPE if_fdt_types=>element_amount.

*Generic factory instance

lref_factory = cl_fdt_factory=>if_fdt_factory~get_instance( gc_appl_id ).

*get the expression the decision table guid

lref_decision_table ?= lref_factory->get_expression(

                             iv_id =  '005056C000081EE58D84DE427EE2E957' )."

*to get the decision table data based on above expression guid

lref_decision_table->if_fdt_decision_table~get_table_data(

    IMPORTING

      ets_data     = lt_msg_data

  ).

IF lt_msg_data IS NOT INITIAL.

          CLEAR lt_table_data_msg.

* Processing decision table and filling the ls_table_data_msg

          LOOP AT lt_msg_data INTO ls_msg_data.

            ls_table_data_msg-row_no = ls_msg_data-row_no.

            ls_table_data_msg-col_no = ls_msg_data-col_no.

            ls_table_data_msg-expression_id = ls_msg_data-expression_id.

            ls_table_data_msg-r_value = ls_msg_data-r_value.

            ls_table_data_msg-ts_range = ls_msg_data-ts_range.

            APPEND ls_table_data_msg TO lt_table_data_msg.

            CLEAR ls_table_data_msg.

          ENDLOOP.

          SORT lt_table_data_msg BY row_no col_no.

* Processing the loop lt_table_data_msg to fill  structure as per the decision table

          LOOP AT lt_table_data_msg INTO ls_table_data_msg.

            ls_table_data1 = ls_table_data_msg.

            CASE ls_table_data1-col_no.

*              level

                when 1.

                  IF ls_table_data1-ts_range IS NOT INITIAL.

                  READ TABLE ls_table_data1-ts_range INTO ls_range_msg INDEX 1.

                  IF sy-subrc = 0.

                    ASSIGN ls_range_msg-r_low_value->* TO <fs_lv_value>.

                    ls_msg_txt_data-level = <fs_lv_value>.

                  ENDIF.

                ENDIF.

*                age

                when 2.

                  IF ls_table_data1-ts_range IS NOT INITIAL.

                  READ TABLE ls_table_data1-ts_range INTO ls_range_msg INDEX 1.

                  IF sy-subrc = 0.

                    ASSIGN ls_range_msg-r_low_value->* TO <fs_lv_value>.

                    ls_msg_txt_data-age = <fs_lv_value>.

                  ENDIF.

                ENDIF.

*                pricing

                when 3.

                  IF ls_table_data1-r_value IS NOT INITIAL.

                  ASSIGN ls_table_data1-r_value->* TO <fs_lv_value>.

                  ls_msg_txt_data-pricing  = <fs_lv_value> .

                ENDIF.

*                base and currency_base

                when 4.

                   IF ls_table_data1-r_value IS NOT INITIAL.

                  ASSIGN ls_table_data1-r_value->* TO <fs_lpw_lv_amount>.

                  ls_msg_txt_data-base = <fs_lpw_lv_amount>-number.

                  ls_msg_txt_data-currency_base = <fs_lpw_lv_amount>-currency .

                ENDIF.

              endcase.

              AT END OF row_no .

                 APPEND ls_msg_txt_data TO lt_msg_txt_data.

                 write:/ ls_msg_txt_data-LEVEL,ls_msg_txt_data-AGE,ls_msg_txt_data-PRICING,ls_msg_txt_data-BASE,ls_msg_txt_data-CURRENCY_BASE.

                 CLEAR ls_msg_txt_data.

               ENDAT.

              endloop.

              endif.

 

We get the following output in the report

data in report.png

Please find the code in the attachment as well

Upload data from excel into Decision Table using BRF+ API's

$
0
0

Hi All,

Let us upload values from excel into Decision table using the BRF+ API’S

Using the following code

 

 

PARAMETERS: ip_rule     TYPE rlgrap-filename OBLIGATORY.
CONSTANTSgc_appl_id   TYPE if_fdt_types=>id  VALUE '005056C000081EE58CD3919CB9A80957',"Application GUID
            gc_dt_id    
TYPE if_fdt_types=>id  VALUE '001E671A4F281ED5BD97A46E4673360F',"Decision Table GUID
            gc_xls      
TYPE string  VALUE '.xls',
            gc_dir      
TYPE string  VALUE 'c:\',
            gc_*xls     
TYPE string  VALUE '*.xls'.


TYPES:BEGIN OF ts_msg_txt_data,
            level        
TYPE char24,
            age          
TYPE char24,
            pricing      
TYPE char24,
            base         
TYPE char24,
            currency_base
TYPE char24,
END OF ts_msg_txt_data.

DATAlt_files               TYPE                                      filetable,
       ls_files              
TYPE                                      file_table,
       iv_rcode              
TYPE                                      int4,
       iv_action             
TYPE                                      int4,
       lref_decision_table   
TYPE REF TO                         cl_fdt_decision_table,
       lref_factory          
TYPE REF TO                         if_fdt_factory,
       lt_excel              
TYPE STANDARD TABLE OF  ts_msg_txt_data,
       wa_excel              
TYPE                                      ts_msg_txt_data,
       lt_msg_data           
TYPE                                      if_fdt_decision_table=>ts_table_data,
       ls_msg_data           
LIKE LINE OF                          lt_msg_data,
       lv_row_no             
TYPE                                      int4,
       lts_range             
TYPE                                      if_fdt_range=>ts_range,
       ls_range              
LIKE LINE OF                         lts_range,
       lx_fdt                
TYPE REF TO                        cx_fdt,
       lt_message            
TYPE                                      if_fdt_types=>t_message,
       lv_message            
TYPE                                      string,
       lv_actv_failed        
TYPE                                      abap_bool.

FIELD-SYMBOLS: <lv_value>      TYPE          any,
               <lv_amount>    
TYPE          if_fdt_types=>element_amount,
               <ls_message>   
TYPE          if_fdt_types=>s_message.

AT SELECTION-SCREEN ON VALUE-REQUEST FOR ip_rule.


CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
default_extension      
= gc_xls
file_filter            
= gc_*xls
initial_directory      
= gc_dir
CHANGING
file_table             
= lt_files
rc                     
= iv_rcode
user_action            
= iv_action
EXCEPTIONS
file_open_dialog_failed
= 1
cntl_error             
= 2
error_no_gui           
= 3
OTHERS                  = 4.
IF sy-subrc <> 0.
    
MESSAGE WITH 'file_open_dialog'.
ELSE.
READ TABLE lt_files INDEX 1 INTO ls_files.
IF sy-subrc = 0.
     ip_rule
= ls_files-filename.
ENDIF.
ENDIF.

START-OF-SELECTION.
**extraction of ceaser rules fom the excel file
CALL FUNCTION 'UPLOAD_XLS_FILE_2_ITAB'
EXPORTING
i_filename
= ip_rule
TABLES
e_itab    
= lt_excel
EXCEPTIONS
file_error
= 1
OTHERS     = 2.
IF sy-subrc <> 0.
MESSAGE 'Unable to upload file ' TYPE  'E'.
ENDIF.
*generic factory instance
lref_factory
= cl_fdt_factory=>if_fdt_factory~get_instance( gc_appl_id ).
*get the expression the decision table guid
lref_decision_table ?= lref_factory
->get_expression(
iv_id
gc_dt_id )."
lref_decision_table
->if_fdt_transaction~enqueue( ).
DELETE ADJACENT DUPLICATES FROM lt_excel.
LOOP AT lt_excel INTO wa_excel .
lv_row_no
= lv_row_no + 1.
*level
CLEAR: ls_msg_data, ls_range, lts_range.
ls_msg_data
-col_no = 1.
ls_msg_data
-row_no = lv_row_no.
ls_range
-position = 1.
ls_range
-sign     = if_fdt_range=>gc_sign_include.
ls_range
-option   = if_fdt_range=>gc_option_equal.
CREATE DATA ls_range-r_low_value TYPE if_fdt_types=>element_text.
ASSIGN ls_range-r_low_value->* TO <lv_value>.
<lv_value>
= wa_excel-level.
INSERT ls_range INTO TABLE ls_msg_data-ts_range.
INSERT ls_msg_data INTO TABLE lt_msg_data.
*age.
CLEAR: ls_msg_data, ls_range, lts_range.
ls_msg_data
-col_no = 2.
ls_msg_data
-row_no = lv_row_no.
ls_range
-position = 1.
ls_range
-sign     = if_fdt_range=>gc_sign_include.
ls_range
-option   = if_fdt_range=>gc_option_equal.
CREATE DATA ls_range-r_low_value TYPE if_fdt_types=>element_text.
ASSIGN ls_range-r_low_value->* TO <lv_value>.
<lv_value>
= wa_excel-age.
INSERT ls_range INTO TABLE ls_msg_data-ts_range.
INSERT ls_msg_data INTO TABLE lt_msg_data.
*pricing
CLEAR: ls_msg_data, ls_range, lts_range.
ls_msg_data
-col_no = 3.
ls_msg_data
-row_no = lv_row_no.
CREATE DATA ls_msg_data-r_value TYPE if_fdt_types=>element_text.
ASSIGN ls_msg_data-r_value->* TO <lv_value>.
<lv_value>
= wa_excel-pricing.
INSERT ls_msg_data INTO TABLE lt_msg_data.
*base
CLEAR: ls_msg_data, ls_range, lts_range.
ls_msg_data
-col_no = 4.
ls_msg_data
-row_no = lv_row_no.
CREATE DATA ls_msg_data-r_value TYPE if_fdt_types=>element_amount.
ASSIGN ls_msg_data-r_value->* TO <lv_amount>.
<lv_amount>
-number = wa_excel-base .
<lv_amount>
-currency = wa_excel-currency_base .
INSERT ls_msg_data INTO TABLE lt_msg_data.
UNASSIGN <lv_amount>
.
CLEAR wa_excel.
ENDLOOP.
IF lt_msg_data IS NOT INITIAL.
TRY.
lref_decision_table
->if_fdt_decision_table~set_table_data( its_data = lt_msg_data  ).
CATCH cx_fdt INTO lx_fdt.
IF lx_fdt IS NOT INITIAL.
WRITE : / 'Creation of Decision table data failed with exception'.
ENDIF.
ENDTRY.
*    Perform deep activation & saving.
TRY.
lref_decision_table
->if_fdt_transaction~activate(
EXPORTING iv_deep              = abap_true
IMPORTING et_message           = lt_message
ev_activation_failed
= lv_actv_failed ).
CATCH cx_fdt INTO lx_fdt.
IF lx_fdt IS NOT INITIAL.
WRITE : 'Activation failed with exception'.
ENDIF.
ENDTRY.
*  Save all the objects and release all locks.
IF lv_actv_failed EQ abap_true.
lref_decision_table
->if_fdt_transaction~dequeue(
EXPORTING iv_deep              = abap_true ).
WRITE : / 'Deep activation failed'.                 
LOOP AT lt_message ASSIGNING <ls_message>.
MESSAGE ID <ls_message>-msgid TYPE <ls_message>-msgty NUMBER <ls_message>-msgno
WITH <ls_message>-msgv1 <ls_message>-msgv2 <ls_message>-msgv3 <ls_message>-msgv4
INTO lv_message.
WRITE: / 'Reason : -',lv_message.                 
ENDLOOP.
ELSE.
TRY.
lref_decision_table
->if_fdt_transaction~save(
EXPORTING iv_deep              = abap_true ).
CATCH cx_fdt INTO lx_fdt.
WRITE : / 'Save failed with exception'.         
LOOP AT lx_fdt->mt_message ASSIGNING <ls_message>.
WRITE :/ <ls_message>-text.
ENDLOOP.
ENDTRY.
lref_decision_table
->if_fdt_transaction~dequeue(
EXPORTING iv_deep              = abap_true ).
ENDIF.

ENDIF.
WRITE:'DT Updated successfully'.


Input file has following values which need to be inserted into decision table.

 

dt_1.png

While execution of report provide the input file as shown in below screen shot and Click on Execute.

dt_2.png

We get the following output.

dt_3.png

Now in Decision table we get the values in BRF+ Workbench as shown in below screen .

DT_4.png

Neues Buch zu BRFplus und DSM: "Business Rule Management mit ABAP"

$
0
0

BRFplus—Business Rule Management for ABAP Applications

Vor rund 5 Jahren habe ich in einem Blog das erste Buch zu BRFplus angekündigt. Nach Monaten der harten Arbeit von Thomas Albrecht und mir war es im Dezember 2010 soweit. Seitdem hat sich das Buch sehr gut verkauft und unser Verlag hat den Kontakt zu uns nicht abgebrochen.   

BRFplus_Book.png

 

Business Rule Management mit ABAP - BRFplus und SAP Decision Service Management

In der Zwischenzeit hat sich BRFplus natürlich erheblich weiterentwickelt und mit DSM sind ganz neue Möglichkeiten der Nutzung von Geschäftsregeln hinzugekommen. Nach Gesprächen mit Verlag und potentiellen Koautoren haben wir uns entschieden keine neue Auflage zu veröffentlichen, sondern in einem größeren Kreis ein neues Buch zu schreiben. Zum Kreis der Autoren gehören neben Thomas und mir auch Christian Lechner, Tobias Trapp, Daniel Ridder, Wolfgang Schaper und Matthias Kucharska. Wie beim letzten Buch haben wir uns auch dieses Mal für ein SAP Press - Buch entschieden, das in Deutschland vom Verlag Rheinwerk herausgegeben wird. Nun ist die Arbeit fast geschafft. Der letzte Feinschliff wird gerade angebracht. Auf der Verlagsseite und im Buchversand werden bereits Vorbestellungen entgegengenommen. Lieferbar ist es ab dem 26. Oktober 2015. Bei Rheinwerk kann neben der gedruckten Ausgabe auch ein E-Book erworben werden. Das Buch (ISBN 978-3-8362-3743-7)erscheint in deutscher Sprache und hat circa 550 Seiten.

BRFplus_DSM.png

 

Aus dem Inhalt

  • Modellierung und Anwendung von Geschäftsregeln
  • Einsatzszenarien
  • Regelsätze und Regeln
  • Ausdrücke und Aktionen
  • Test und Transport regelbasierter Anwendungen
  • Integration mit SAP Business Workflow und BOPF
  • Erweiterungsmöglichkeiten
  • Fehleranalyse
  • Best Practices
  • Vorgehen in Geschäftsregelprojekten

Die Zusammenarbeit mit den anderen Autoren war sehr angenehm. Vielen Dank! Wir konnten unterschiedliche Sichtweisen und Erfahrungswerte in Kapiteln wie Einsatzszenarien, Best Practices oder Fehleranalyse vereinen. Damit stellt das neue Buch viele Inhalte zur Verfügung, die in unserem ersten Buch nicht berücksichtigt wurden. Ich bin sehr gespannt auf die ersten Rückmeldungen.

 

 

This blog is about a new book for DSM and BRFplus. The book will be published in German language. Therefore, the blog is written in German.

How to Compare two BRFplus Rule Systems?

$
0
0

In this blog I sketch a solution for comparing BRFplus rule systems. I’ll discuss the use case and I would be interested in your feedback. Also I would like to know whether other people are working on the same topic and would like to exchange source code. Maybe this could lead to the first open source project in the area of BRFplus.

 

Use Cases

At first I think that comparison of objects like different rule systems is a value in itself because the concept of equality resp. inequality is one of most profound ones I know in philosophy and mathematics. But there are also more business cases:

  • In larger development projects sometimes rule set are shipped which contain an implementation of decision logic. Often they are shipped as implementation accelerators, used for tests and are altered afterwards.
  • Sometimes people don’t want to change a rule system and copy it instead, do some changes, test it, and ship it after that. Then a comparison is useful.
  • Rule systems are generated/changed using metadata and the BRFplus API. You want to check the results by comparing them.

 

Let us look at the first described scenario. I develop rule systems that have be to compliant to legislation and shipped to different organizations as applications of storage type system. These implementations are mostly stable due to compliance reasons and there one is only allowed to change them minimally and only in certain parts. Usually business experts use my rule systems as template and copy and alter it. Later the comparison is useful to control what has been changed:

  • A revisior or auditor wants to analyze the adaptations.
  • If a have to change my template application (because it contained an error or legislation changed) a comparison after the import is helpful when the copied rule system has to be changed.
  • Sometimes organizations evolved the rule systems in a different way. Now they want to check the difference and perform harmonization or even want to implement a common version.

 

So please let me summarize: comparison of different rule systems can be part of a usual maintenance and evolution process. It becomes necessary if you have a couple of organizations that have rule systems that are quite similar and evolved from the same template of decision logic. But there are other use cases when comparison of decision logic is useful.

 

The Challenge

Comparing two rule systems is difficult. BRFplus has only functions for comparing two rule set versions. The transaction FDT_HELPERS contains a report that checks whether two versions are identical. This is useful if you want to check whether a transport was (successfully) imported into a system. But it is not that useful for our purposes.

 

So we need to develop a solution by ourselves. The challenge is that BRFplus does have an object oriented API but provides no simple textual representation of the rules. But there are more problems: we have to define when two BRFplus artifacts are identical:

  • Are two objects different if their technical name is different? If you allow that the technical can be different – how do you identify corresponding BRFplus entities that you want to compare?
  • Which metadata should be considered or not considered in the comparison? The information which user performed the change and the specific time should not matter for example.
  • Should the flag whether a rule set is active or not active be considered in the comparison? This depends on the use case: when you deliver a rule set assigned to a BRFplus function as template, then it is likely that it is not enabled. In this case, the user copies the rule set, sets it to active and perhaps alters it.

 

This shows the following: the comparison of two BRFplus applications is no trivial task and depends on the scenario i.e. the way that a rule system is copied and changed when working with a template. So I came to the conclusion that it would be useful to have a library with different utility functions.

 

My Approach

After some experiments with the BRFplus API it became clear that this is not the right tool for comparisons. I also learned the especially the structure of the rules is very complex and they are hard to compare. Moreover I decided that a need a flexible toolset that would allow different kinds of comparisons.

 

My solution uses the XML representation of an BRFplus application. This representation is far from being readable. When you look at the structure of an XML document you will see that it contains on different artifacts which can be seen in the picture below. The most important entity is the expression which are grouped as elements FDTNS:EXPRESSION and are identified using IDs. More complex objects like conditions of rules refer to expressions by their IDs.

expr.PNG

So f.e. a rule consists of conditions which are in fact expressions. In the XML representation the ID is stored and the expression with this ID is stored somewhere else in the XML document.

 

If you want to compare two BRFplus entities (f.e. two rules) one approach is to replace each occurrence of its expressions (think of a condition defined by its ID) with the content of the corresponding XML element which is stored in another part of the XML representation. If you do this in recursive way you will “expand” the BRFplus entity to a tree containing all relevant in expressions. This can be done easily using an iteration of the following XSL transformation which can be performed using the CALL TRANSFORMATION command in ABAP:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match=
"FDTNS:RULES/FDTNS:item/FDTNS:RULE_ID |
                      FDTNS:EXPRESSION_ID |
                      FDTNS:CONDITION |
                      /FDTNS:FDT/FDTNS:RULESET/FDTNS:COND_RANGE/FDTNS:PARAMETER_ID">
    <xsl:variable name=
"id" select="string(.)"/>
    <xsl:choose>
      <xsl:when test=
"count(/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id])>0">
        <xsl:copy-of select=
"/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select=
"node() | @*"
/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

 

If you have now a rule that is copied from another rule and both are using the same data elements then you compare them using a simple string compare. But before you have to remove the administration data since timestamps, change user and so will be always different. This can be done using the following transformation:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
    </xsl:template>

  <xsl:template match=
"FDTNS:ADMIN_DATA"/> <!-- Don't copy this element -->

</xsl:transform>


Another important operation for the above mentioned string comparison is the extraction. This can be performed also in XML. Here I show how to extract a certain rule in a rule set using XSLT:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:param name=
"POSITION"/>
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"/">
    <xsl:copy-of

select="/FDTNS:RULESET/FDTNS:RULES/FDTNS:item[string(FDTNS:POSITION)=string($POSITION)]"/>
  </xsl:template>
</xsl:transform>

 

Using those transformations you can “expand” two applications, remove administration data, extract parts and compare them using string comparison.

And this is what I implemented and tested successfully.

 

Summary

I discussed some use cases for rule system comparison and described the main ideas of my implementation. Now I have following questions for the BRFplus community:

  • Is someone working on the same problem?
  • Are there other approaches?
  • If someone is working on the same approach, is there interest in sharing the source? Maybe we could start an Open Source project by combining our source code.

Creation of Procedure call in SAP BRF+

$
0
0

For embedding the ABAP function modules into BRF+ we can use the procedure call.

Step 1.Choose any ABAP function module

Sample function module: CONVERSION_EXIT_ISOLA_INPUT

Let’s see the functionality of this function module.

This function module is used to convert for example if the language code (DE), then it is converted to corresponding Language key (D).

26.png

Step 2. Check the importing parameters and exporting parameters in function module.

So that we can avoid the type compatibility issues while using this function module in SAP BRF+ easily.

Step 3. Create a function as shown below

1.png

  • Give the function name and text and click on create and navigate to object.

2.png

  • Select the mode for function, let’s use the functional mode.

3.png

  • Now we create the two data objects lv_input and lv_output as per the function module in ABAP. As these data objects need to be the input and output for the function in its signature. Click on add new data object as shown below.

4.png

  • Choose element and click on create and navigate to object.

5.png

  • Provide the details for input as shown below and click on ok.

6.png

  • Activate the data element lv_input. By clicking on activate button.
  • Now we create the output data element lv_output for the function as shown below.

7.png

  • Choose element and click on create and navigate to object.

8.png

  • Provide the details as shown below.

9.png

  • Activate the data element lv_output. By clicking on activate button.
  • We have the input and output for the function as shown in below screenshot.

10.png

Step 4.Now we create an expression for function call in top expression of function.

 

    11.png

  • Choose as shown below.

12.png

  • Provide the details as shown below.

13.png

  • Choose the call type as function module in procedure call .

14.png

  • And give the function module name CONVERSION_EXIT_ISOLA_INPUT and click enter .



15.png

  • If you want you can ignore the exception just click on Ignore exception. Then your ignored exception will be shown like this.

16.png

  • Now we have to map the BRF+ function parameters to the ABAP function module parameters. For that click on add parameters. Add the input and output which are the importing and exporting parameters of CONVERSION_EXIT_ISOLA_INPUT.

17.png

  • We get the input and output as shown below.

18.png

  • Click on the input and do the same for output we get this screen shown below.

19.png

  • Click on the select context parameter for input mapping.

20.png

21.png

  • Click on the select context parameter for output mapping.

22.png

  • After mapping we get the following screen.

23.png

  • Now activate the expression exp_pc_call and the function FU_PC_CALL .Our procedure call is in top expression in function.

Step 5.Lets test the function with procedure call.

  • Click on the simulation in function.

Provide the input as DE and click execute.

24.png

  • We get the output as shown below.

25.png

Get Boolean Expression details using BRF+ API’S in SAP and upload into application server

$
0
0

Hi Everyone,

  • Suppose if we require to display the expression name,GUID,last changed by,text of a Boolean expression in brf+ .

Let us take multiple Boolean expressions in BRF+ Application as shown below.

Here we have two Boolean expressions EXP_TEST_1 and EXP_TEST_2 in Z_BOL_TEST_w application.

1.png

  • Boolean expression (EXP_TEST_1)

To display the Boolean expression (EXP_TEST_1) details like Boolean expression name , Boolean expression GUID, Last changed by ,Text as shown in below screen shots.

2.png

3.png

  • Likewise for Boolean expression (EXP_TEST_2) we have following details shown in below screen shot.

4.png

5.png

  • Now we will use the following code to get Boolean expression details and upload those details in to Application server.
    *constants declarations

CONSTANTSgc_appl_id    TYPE if_fdt_types=>id  VALUE '005056C000081ED58ADDAB4AA60FF5F2',

  gc_semi_colon    TYPE char01 VALUE ';',

  gc_x                       TYPE char1     VALUE 'X',

  gc_csv                   TYPE string    VALUE 'csv'.

*types declarations

TYPES: BEGIN OF ty_id,

                   id TYPE if_fdt_types=>id,

               END OF ty_id,

 

              BEGIN OF ty_boolean,

                 name         TYPE if_fdt_types=>name,

                 id               TYPE if_fdt_types=>id,

                 last_user TYPE sy-uname,

                 text           TYPE if_fdt_types=>text,

             END OF ty_boolean,

 

              tt_id TYPE  STANDARD TABLE OF  ty_id,

              tt_boolean TYPE  STANDARD TABLE OF ty_boolean.

 

*variable declarations

DATA: lref_boolean                 TYPE REF TO    if_fdt_boolean,

             lref_factory                  TYPE REF TO if_fdt_factory,

             lv_bol_id            TYPE if_fdt_types=>id,

             it_id TYPE STANDARD TABLE OF  ty_id,

             wa_id TYPE   ty_id,

             it_boolean TYPE STANDARD TABLE OF ty_boolean,

             wa_boolean TYPE ty_boolean,

             lv_last_chged_user TYPE sy-uname,

             lv_text TYPE if_fdt_types=>text,

             lv_name  TYPE if_fdt_types=>name.

*selection screen

SELECTION-SCREEN BEGIN OF BLOCK b1.

               SELECT-OPTIONS:s_bol_id FOR  lv_bol_id.

                PARAMETERS:p_file TYPE string.

SELECTION-SCREEN END OF BLOCK b1.

 

AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

*for applicatin server file

   PERFORM get_appl_server_filepath_input CHANGING p_file.

 

START-OF-SELECTION.

*fill boolean ids from the select options

   LOOP AT s_bol_id WHERE option = 'EQ' AND sign ='I'.

                       wa_id-id  = s_bol_id-low.

                      APPEND wa_id TO it_id.

   ENDLOOP.

 

*generic factory instance

   lref_factory = cl_fdt_factory=>if_fdt_factory~get_instance( gc_appl_id ).

*generic factory instance

   lref_factory = cl_fdt_factory=>if_fdt_factory~get_instance( gc_appl_id ).

*get boolean details

   PERFORM boolean_details USING it_id

   CHANGING it_boolean .

* upload boolean details into application server file path

   PERFORM upload_boolean_data USING it_boolean

   p_file .

*f4 help for filepath

FORM get_appl_server_filepath_input

CHANGING p_ap_file TYPE string.

 

   DATA:l_title   TYPE  string.

   l_title = text-001.

 

   CALL METHOD cl_rsan_ut_files=>f4

     EXPORTING

       i_applserv       = gc_x

       i_title          = l_title

       i_gui_extension  = gc_csv

       i_gui_ext_filter = gc_csv

     CHANGING

       c_file_name      = p_ap_file

     EXCEPTIONS

       failed           = 1

       OTHERS           = 2.

ENDFORM.                          "get_appl_server_filepath_input

*&---------------------------------------------------------------------*

*&      Form  boolean_details

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->PIT_IT       text

*      -->PIT_BOOLEAN  text

*----------------------------------------------------------------------*

FORM boolean_details USING  pit_it TYPE tt_id

CHANGING pit_boolean TYPE tt_boolean.

 

**processing the boolean expression for details

   LOOP AT pit_it INTO wa_id.

     lref_boolean ?= lref_factory->get_expression(

     iv_id wa_id-id ).

*get boolean name

     TRY.

         lref_boolean->if_fdt_admin_data~get_name(

         RECEIVING

         rv_name      lv_name

         ).

       CATCH cx_fdt_input .

         IF sy-subrc EQ 0.

           MESSAGE text-002 TYPE 'I'.

         ENDIF.

     ENDTRY.

* get last changed user

     TRY.

         lref_boolean->if_fdt_admin_data~get_change_info(

         IMPORTING

         ev_change_user        = lv_last_chged_user

         ).

       CATCH cx_fdt_input.

         IF sy-subrc EQ 0.

           MESSAGE text-003 TYPE 'I'.

         ENDIF.

     ENDTRY.

* get description

     lref_boolean->if_fdt_admin_data~get_texts(

     IMPORTING

     ev_text    =   lv_text

     ).

*Fill the boolean expression details

     wa_boolean-name = lv_name.

     wa_boolean-id   = wa_id-id.

     wa_boolean-last_user = lv_last_chged_user.

     wa_boolean-text    = lv_text.

     APPEND wa_boolean TO pit_boolean.

     CLEAR wa_boolean.

   ENDLOOP.

 

ENDFORM.                    "boolean_details

 

*&---------------------------------------------------------------------*

*&      Form  upload_boolean_data

*&---------------------------------------------------------------------*

*       text

*----------------------------------------------------------------------*

*      -->PIT_BOOLEAN   text

*      -->PIV_FILENAME  text

*----------------------------------------------------------------------*

FORM upload_boolean_data USING pit_boolean TYPE tt_boolean

piv_filename TYPE string.

   DATAwa_boolean_tmp TYPE ty_boolean,

   lv_var TYPE string.

   IF pit_boolean IS NOT INITIAL.

* open file

     OPEN DATASET piv_filename FOR OUTPUT IN TEXT MODE ENCODING  UTF-8 .

     IF sy-subrc EQ 0.

       LOOP AT pit_boolean INTO wa_boolean_tmp.

         CONCATENATE wa_boolean_tmp-name

         wa_boolean_tmp-id

         wa_boolean_tmp-last_user

         wa_boolean_tmp-text INTO lv_var SEPARATED BY gc_semi_colon.

         TRANSFER lv_var TO piv_filename.

       ENDLOOP.

       WRITE:'Data uploaded successfully in Application server'.

     ENDIF.

*close file

     CLOSE DATASET piv_filename.

     CLEAR piv_filename.

   ENDIF.

ENDFORM.                    "upload_boolean_data

 

 

  • Provide multiple Boolean GUID’S and Application server file path then click on AL11 Files as shown below.

6.png

  • Choose any of the directories as shown in below screen shot.

7.png

  • Select any file and Copy file name as shown below.

8.png

  • Then Click execute.

9.png

  • We get the Following output.

10.png

  • Now open Tcode AL11 and open the filepath for the boolean expression details. Double click on filename ABC.CSV

11.png

  • We get following the boolean expression details from EXP_TEST_1 and EXP_TEST_2 Booleans.

12.png

Performance Improvements in the DSM Test Case Tool

$
0
0

Test case tool provides the infrastructure to define inputs and expected output for decision services and is very well integrated with DSM and the BRF+ workbench. The Test Case Administration screen looks as below: -

pic1.png

 

You could read more about the test-case tool via the SCN page: http://scn.sap.com/docs/DOC-57956

 

Following are some recent improvements done in the tool: -

  • Loading of test-cases for a particular function is much faster now, it takes less than a second to load 400 odd test-cases plus associated test-runs where in earlier it used to time-out – this improvement has been introduced via note: 2217352 – with this correction we read the test-run details on demand i.e. only when a particular test run is clicked
  • Test-cases now can be executed in an asynchronous manner rather than the earlier much slower synchronous sequential manner of execution – this has been enabled via note 2277388 – with this correction the performance of the execution now depends on the no. of free resources available in the system. A simple comparison would be as below: - o 5 test-cases each taking 2s to execute with 5 free CPU processes would earlier take 10 seconds to execute but now would take between 2 – 3 seconds only i.e. almost a gain of 7 seconds
  • The above note provides apis which could help build a report for scheduling of test-execution for multiple functions in the background. A sample report looks as below:-

pic2.png

 

You can enhance the attached report code to suit your requirements.


DSM Experiences and Practices

$
0
0

Those days where you wait hours and hours for a single transport to be imported through the landscape. Not any more, they are long gone with DSM. Now with a click of a button we have all what we need in the desired managed system in real quick time. I’m more than exited to share my experience and love towards DSM and may be a few helpful tips along the way.


I was so driven to write a lot of blogs/share my experience and love towards BRFplus and DSM about an year ago or so; well that lasted for one blog hopefully it will be different this time around since I have few things I would like to share which may be helpful to some

 

I work in a enormous project where something or the other is deployed to production every week and a major release every three months. Which may not be the case in some if not most of the projects. When you add BRFplus transport to that it will be long nights for sure. Then when you have around 20-30 functions in a major release, imagine amount it takes to generate them is just cherry on the top for the transports. On the top of this when you have multiple clients in a system and you will defiantly end up in inconsistencies over the two clients to say the least (some developer did not sync his application the second development client, now I cannot test this before I move to quality). Well those days are long gone, With DSM you don’t have to worry about long transports, you don’t have to worry about inconsistency with the rules in multiple clients, you don’t have to worry about generating the functions, all that you need to do is push that sweet little button (‘deploy’) and wallah you have it in any manages systems you desire. Their are lots of blogs/books from Carsten Ziegler and Jocelyn Dart on DSM which come in more than handy when you are new to DSM or if you have to understand/learn anything related to DSM.

 

From my experience it is good to have two DSM systems where one is connected to DEV, QAS and PRE-PROD and the other is connected to PROD. This gives an opportunity to do hot fixes for PROD in the second system and them deployed to PROD and use the first system for further releases. Obviously any and all the changes which are done in second system has to be replicated in first system. This is not easy thing, no one wants to do the same thing twice. Their are few ways to go about it, we can achieve this by some standard tools, but most of it depends on the design of the application, the changes which you are making.

1) The hardest way would be to redo all the changes which are made in second system (which is connected to production), for some cases this would be frustrating and time consuming.

2) Their are few expressions such as decision tables where you can export the data of the table and have it imported in any system you like. I can def speak on every one who has worked on BRFplus that how much we love the decision table import and export.

3) XML export and XML import, this would be the one which is the game changer where you can export an expression/entire application and have it imported into the system you would like. you have to be careful here >> when you have use this and if you have already made changes to the objects in first system (development system) which you are importing from second system (production system); all the changes will be over written.

The main thing is that this has to be considered during the design phase of the BRFplus applications so that we can take advantage of the tool (for example 2nd or 3rd option) which would make life a lot easier. I have played around with a lot of XML export and XML import, I will try to share them in coming blogs. Which is defiantly what I would suggest/what I would use. Again it all depends on how the design and what kinda changes you plan to make. Their are a lot of ways on how to go about this having two system or copy of the system after the release for the next one, so on. Always more than happy to learn and understand what we can do to make life simpler.


When you have multiple system when one is connected to DEV and other is connected to PROD and you have to use transports to move the objects between the systems this makes it a bit challenging since you will not have any of the metadata available in the DSM systems. Since when you move the transport to the system it will not add the managed system via transports in the system which you are importing. This would mean the objects which you move will not have access to any of the metadata. To overcome this we have made a practice; Once any application is created in DSM system we move the transport to second system(which is connected to PROD) and assign the managed system, so any objects from that application will always have access to metadata in the second system also, which would allow the transports to go through. Also I have come across few transports which failed to perform the post import steps and activate the objects even when the application is assigned to a manages system; Not to worry, report 'FDT_TRANS_PHASE_EXECUTION' to rescue. By with you can trigger the after import steps. Jocelyn Darthas a dedicated blog explaining metadata which would help you understand what metadata is and what it means in DSM environment.

 

Another thing which comes into picture is timeframes of the applications/objects going to PROD. This is very frustrating and almost impossible to handle when you work on enormous project where multiple people are working on multiple things and which creates decencies on other transports. let me take a simple scenario to go about this, I’m using a table in BRFplus and wanted to send it to production, but I came to know that one of the field in the table is not in production and my change cannot go until the transport with the table goes in to production which is planned to go in two months time and still needs test sign off. What do I do?? Obviously I need that table for my rules and I cannot delete that one filed since it is bound to that table. Do I create a new table with one less field?? again I will be referring to a different table which I cannot do. With DSM I can do this little trick when I assign the PRE-PROD system where it is similar to production and refresh the binding and assign it back to the managed system I like. NO! we cannot do this in BRFplus without DSM and this is just a tip of the iceberg of what we can do with DSM.

 

Another little advice from my experience is to have as less function calls as you can in the rules. The more function call you have the longer it takes to deploy the function via DSM from my experience. I have seen a lot of applications where they use function calls at will, stating reusability even for a small table operation or a rule which may not change in a million years (not to judge ones design). Avoiding function calls and procedure calls is what I always keep in my mind when I design/build rules. Obviously their comes a debate of reusability, maintenance and performance, lets pick that another day in time, not a topic for today

 

To end I would like to point out that we have to rebuild the application exit classes and create currencies/unit of measures(may be their is already a note which I did not come across). You have to copy and past every class and replicate all the currencies/unit of measures when you are migrating to DSM and your CRM/ERP or what ever system it may be has application exit classes and currencies/unit of measures.


Hope this was knowledgeable and will come in handy in your future endeavors and that you will stay with me for the next blogs. Any and all the feedback is much appreciated, which would help me learn new things or correct things which we could handle in a  different and a better way.

Embed your BRF+ Customizing catalog within your own customizing

$
0
0

Do you wonder how you can add a BRF+ customizing to you individual customizing structure?

Well here is my solution for this:

1) Create report to display a catalog

                REPORT zdisplay_catalog.

PARAMETERS p_catidTYPE if_fdt_types=>id.
DATA lo_cat_maint_mode TYPE if_fdt_wd_types=>catalog_maintenance_mode.
DATA lv_enable_structure_changeTYPE abap_bool.
DATA lo_ui_executionTYPE REF TO cl_fdt_wd_viewer.

lo_cat_maint_mode
= if_fdt_wd_constants=>gc_catalog_mmode_no_maint.
lv_enable_structure_change
= abap_false.

CREATE OBJECT lo_ui_execution.
lo_ui_execution
->if_fdt_wd_ui_execution~execute_catalog_browser(
EXPORTING
   iv_id                     
= p_catid    " ID
   iv_maintenance_mode       
= lo_cat_maint_mode    " Catalog Maintenance Mode
   iv_enable_structure_change
= lv_enable_structure_change).

Of course here you can call whatever customizing you created and what is support by the BRF+ API

2) Create a variant with the concrete catalog ID.

3) Create a report transaction with this variant        

4) To skip the start screen create a second parameter transaction for the transaction created in step 3.

Of course you can simply hard code the catalog but for reuse purpose I created the parameter report.

5) Create a customizing object via TA SOBJ: Typ = T

6) Create your own customizing node in SIMGH

7) Add the created customizing object with type t and your created transaction.

Done.

Now you can call this BRF+ customizing within your own SPRO

Neues Buch zu BRFplus und DSM: "Business Rule Management mit ABAP"

$
0
0

BRFplus—Business Rule Management for ABAP Applications

Vor rund 5 Jahren habe ich in einem Blog das erste Buch zu BRFplus angekündigt. Nach Monaten der harten Arbeit von Thomas Albrecht und mir war es im Dezember 2010 soweit. Seitdem hat sich das Buch sehr gut verkauft und unser Verlag hat den Kontakt zu uns nicht abgebrochen.   

BRFplus_Book.png

 

Business Rule Management mit ABAP - BRFplus und SAP Decision Service Management

In der Zwischenzeit hat sich BRFplus natürlich erheblich weiterentwickelt und mit DSM sind ganz neue Möglichkeiten der Nutzung von Geschäftsregeln hinzugekommen. Nach Gesprächen mit Verlag und potentiellen Koautoren haben wir uns entschieden keine neue Auflage zu veröffentlichen, sondern in einem größeren Kreis ein neues Buch zu schreiben. Zum Kreis der Autoren gehören neben Thomas und mir auch Christian Lechner, Tobias Trapp, Daniel Ridder, Wolfgang Schaper und Matthias Kucharska. Wie beim letzten Buch haben wir uns auch dieses Mal für ein SAP Press - Buch entschieden, das in Deutschland vom Verlag Rheinwerk herausgegeben wird. Nun ist die Arbeit fast geschafft. Der letzte Feinschliff wird gerade angebracht. Auf der Verlagsseite und im Buchversand werden bereits Vorbestellungen entgegengenommen. Lieferbar ist es ab dem 26. Oktober 2015. Bei Rheinwerk kann neben der gedruckten Ausgabe auch ein E-Book erworben werden. Das Buch (ISBN 978-3-8362-3743-7)erscheint in deutscher Sprache und hat circa 550 Seiten.

BRFplus_DSM.png

 

Aus dem Inhalt

  • Modellierung und Anwendung von Geschäftsregeln
  • Einsatzszenarien
  • Regelsätze und Regeln
  • Ausdrücke und Aktionen
  • Test und Transport regelbasierter Anwendungen
  • Integration mit SAP Business Workflow und BOPF
  • Erweiterungsmöglichkeiten
  • Fehleranalyse
  • Best Practices
  • Vorgehen in Geschäftsregelprojekten

Die Zusammenarbeit mit den anderen Autoren war sehr angenehm. Vielen Dank! Wir konnten unterschiedliche Sichtweisen und Erfahrungswerte in Kapiteln wie Einsatzszenarien, Best Practices oder Fehleranalyse vereinen. Damit stellt das neue Buch viele Inhalte zur Verfügung, die in unserem ersten Buch nicht berücksichtigt wurden. Ich bin sehr gespannt auf die ersten Rückmeldungen.

 

 

This blog is about a new book for DSM and BRFplus. The book will be published in German language. Therefore, the blog is written in German.

How to Compare two BRFplus Rule Systems?

$
0
0

In this blog I sketch a solution for comparing BRFplus rule systems. I’ll discuss the use case and I would be interested in your feedback. Also I would like to know whether other people are working on the same topic and would like to exchange source code. Maybe this could lead to the first open source project in the area of BRFplus.

 

Use Cases

At first I think that comparison of objects like different rule systems is a value in itself because the concept of equality resp. inequality is one of most profound ones I know in philosophy and mathematics. But there are also more business cases:

  • In larger development projects sometimes rule set are shipped which contain an implementation of decision logic. Often they are shipped as implementation accelerators, used for tests and are altered afterwards.
  • Sometimes people don’t want to change a rule system and copy it instead, do some changes, test it, and ship it after that. Then a comparison is useful.
  • Rule systems are generated/changed using metadata and the BRFplus API. You want to check the results by comparing them.

 

Let us look at the first described scenario. I develop rule systems that have be to compliant to legislation and shipped to different organizations as applications of storage type system. These implementations are mostly stable due to compliance reasons and there one is only allowed to change them minimally and only in certain parts. Usually business experts use my rule systems as template and copy and alter it. Later the comparison is useful to control what has been changed:

  • A revisior or auditor wants to analyze the adaptations.
  • If a have to change my template application (because it contained an error or legislation changed) a comparison after the import is helpful when the copied rule system has to be changed.
  • Sometimes organizations evolved the rule systems in a different way. Now they want to check the difference and perform harmonization or even want to implement a common version.

 

So please let me summarize: comparison of different rule systems can be part of a usual maintenance and evolution process. It becomes necessary if you have a couple of organizations that have rule systems that are quite similar and evolved from the same template of decision logic. But there are other use cases when comparison of decision logic is useful.

 

The Challenge

Comparing two rule systems is difficult. BRFplus has only functions for comparing two rule set versions. The transaction FDT_HELPERS contains a report that checks whether two versions are identical. This is useful if you want to check whether a transport was (successfully) imported into a system. But it is not that useful for our purposes.

 

So we need to develop a solution by ourselves. The challenge is that BRFplus does have an object oriented API but provides no simple textual representation of the rules. But there are more problems: we have to define when two BRFplus artifacts are identical:

  • Are two objects different if their technical name is different? If you allow that the technical can be different – how do you identify corresponding BRFplus entities that you want to compare?
  • Which metadata should be considered or not considered in the comparison? The information which user performed the change and the specific time should not matter for example.
  • Should the flag whether a rule set is active or not active be considered in the comparison? This depends on the use case: when you deliver a rule set assigned to a BRFplus function as template, then it is likely that it is not enabled. In this case, the user copies the rule set, sets it to active and perhaps alters it.

 

This shows the following: the comparison of two BRFplus applications is no trivial task and depends on the scenario i.e. the way that a rule system is copied and changed when working with a template. So I came to the conclusion that it would be useful to have a library with different utility functions.

 

My Approach

After some experiments with the BRFplus API it became clear that this is not the right tool for comparisons. I also learned the especially the structure of the rules is very complex and they are hard to compare. Moreover I decided that a need a flexible toolset that would allow different kinds of comparisons.

 

My solution uses the XML representation of an BRFplus application. This representation is far from being readable. When you look at the structure of an XML document you will see that it contains on different artifacts which can be seen in the picture below. The most important entity is the expression which are grouped as elements FDTNS:EXPRESSION and are identified using IDs. More complex objects like conditions of rules refer to expressions by their IDs.

expr.PNG

So f.e. a rule consists of conditions which are in fact expressions. In the XML representation the ID is stored and the expression with this ID is stored somewhere else in the XML document.

 

If you want to compare two BRFplus entities (f.e. two rules) one approach is to replace each occurrence of its expressions (think of a condition defined by its ID) with the content of the corresponding XML element which is stored in another part of the XML representation. If you do this in recursive way you will “expand” the BRFplus entity to a tree containing all relevant in expressions. This can be done easily using an iteration of the following XSL transformation which can be performed using the CALL TRANSFORMATION command in ABAP:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
  </xsl:template>

  <xsl:template match=
"FDTNS:RULES/FDTNS:item/FDTNS:RULE_ID |
                      FDTNS:EXPRESSION_ID |
                      FDTNS:CONDITION |
                      /FDTNS:FDT/FDTNS:RULESET/FDTNS:COND_RANGE/FDTNS:PARAMETER_ID">
    <xsl:variable name=
"id" select="string(.)"/>
    <xsl:choose>
      <xsl:when test=
"count(/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id])>0">
        <xsl:copy-of select=
"/FDTNS:FDT/FDTNS:EXPRESSION[FDTNS:ADMIN_DATA/FDTNS:ID/text()=$id]"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select=
"node() | @*"
/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:transform>

 

If you have now a rule that is copied from another rule and both are using the same data elements then you compare them using a simple string compare. But before you have to remove the administration data since timestamps, change user and so will be always different. This can be done using the following transformation:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:transform version=
"1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"node() | @*">
    <xsl:copy>
      <xsl:apply-templates select=
"node() | @*"/>
    </xsl:copy>
    </xsl:template>

  <xsl:template match=
"FDTNS:ADMIN_DATA"/> <!-- Don't copy this element -->

</xsl:transform>


Another important operation for the above mentioned string comparison is the extraction. This can be performed also in XML. Here I show how to extract a certain rule in a rule set using XSLT:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:FDTNS="http://sap.com/fdt/transport">
  <xsl:param name=
"POSITION"/>
  <xsl:output method=
"xml" version="1.0" encoding="UTF-8" indent="yes"/>
  <xsl:strip-space elements=
"*"/>

  <xsl:template match=
"/">
    <xsl:copy-of

select="/FDTNS:RULESET/FDTNS:RULES/FDTNS:item[string(FDTNS:POSITION)=string($POSITION)]"/>
  </xsl:template>
</xsl:transform>

 

Using those transformations you can “expand” two applications, remove administration data, extract parts and compare them using string comparison.

And this is what I implemented and tested successfully.

 

Summary

I discussed some use cases for rule system comparison and described the main ideas of my implementation. Now I have following questions for the BRFplus community:

  • Is someone working on the same problem?
  • Are there other approaches?
  • If someone is working on the same approach, is there interest in sharing the source? Maybe we could start an Open Source project by combining our source code.
Viewing all 119 articles
Browse latest View live




Latest Images