BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation (1)

November 16, 2017 | Author: Yassine Chaabo | Category: Parameter (Computer Programming), Ibm Db2, Business Process, Ibm System I, Software
Share Embed Donate


Short Description

Download BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation (1)...

Description

BRFplus for Decision Services How to Automatically Set the Tax Code in Purchase Order Creation

Applies to: Business experts and IT professionals that are considering automating decisions, checking data, defaulting or calculating values in business applications. A pre-requisite to apply the approaches explained in this document is SAP NetWeaver (ABAP) 7.0 Enhancement Package 2 or above. For more information, visit the Business Rules Management homepage.

Summary The document describes, with the help of an example, how a decision service can be implemented using BRFplus. Each step from concept to final implementation is shown. The example demonstrates automatic setting of the tax code during purchase order creation. Author:

Carsten Ziegler

Company: SAP AG Created on: 22 November 2011

Author Bio Carsten Ziegler is the Lead Architect and Chief Product Owner of Business Rule Framework plus. He joined SAP in 2000. Since then he has been working in various projects as a developer, development architect and project lead.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 1

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Table of Content Purpose of this Document .................................................................................................................................. 3 The Example ....................................................................................................................................................... 3 Steps in the implementation of a Decision Service ............................................................................................ 4 Definition of Task ............................................................................................................................................ 4 Decision Service Definition ............................................................................................................................. 4 Decision Service Trigger Implementation ....................................................................................................... 6 Decision Service Implementation .................................................................................................................... 8 Decision Service Testing .................................................................................................................................. 11 Related Content ................................................................................................................................................ 15 Copyright........................................................................................................................................................... 16

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Purpose of this Document This document shows, with the help of an example, how a decision service can be implemented using BRFplus and subsequently connected to a business process. IT professionals will find this document very helpful as it explains and structures an approach that can minimize time and effort when dealing with changes. Once the connection of the process to the decision service has been established, further changes to the decision logic will not require code changes. Business professionals will find this document helpful as it gives an idea of what is possible with BRFplus. BRFplus will enable them to understand the business logic of a particular decision. Therefore, their input to changes will be better informed and in some cases, as domain experts, they may even want to do the changes themselves. Clearly, the approach shown provides increased agility to react to changes in the business context compared to similar logic directly implemented in code. The example is the setting of the tax code during purchase order creation. However the approach is not limited to this particular example. Whenever a task has to be automated, BRFplus may be used to implement a decision service and plug it into the relevant process step - ideally via a BADI, enhancement spot or any other exit technology. Remote invocation of BRFplus decision services is also possible by calling a web service or an RFC-enabled function module. Both can be generated from within the BRFplus workbench.

The Example A purchase order can be created using transaction code ME21N. By default the Tax Code field (see the highlighted field below) has to be set manually. Some countries such as Brazil have very complex tax laws and consequently the tax codes are frequently not set correctly and setting it correctly takes considerable time that should be spent in more value adding activities.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 3

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Steps in the implementation of a Decision Service Definition of Task First clarify the task to be accomplished with the decision service. Perfect candidates are tasks that are free from side effects, this means you have a set of attributes and based on the values of those attributes you want to derive or calculate the values of one or several other attributes. Often tasks are related to one of the following:  Validations  Derivations  Defaulting  Classification  Calculation  Mapping  Boolean decisions Typically these are micro decisions. Micro decisions occur very frequently but the impact of a particular decision is not big compared with decisions that affect the complete enterprise such as strategic decisions about starting a new product line. However, micro decisions tend to occur very frequently and to be wellstructured. Cumulatively they can have a big impact on the financial result of a company as they directly impact the efficiency of the operations. In the example of this document the decision service is called for every purchase made. Incorrect tax codes require the purchase order to be reworked, which is a significant cost factor for organizations burdened by complex tax laws where purchasers frequently have difficulty determining the correct tax code. Decision Service Definition Knowing the task we can start to define the decision service:  Name “Set Tax Code”  Description “Set the Tax Code in the Purchase Order Creation process” This definition is not yet complete. We also need to define inputs (the context for the decision rules) and outputs (the results) of the service. Usually business people can derive that from the rules they have in mind. It is not a problem if this list is not complete upfront as more parameters can be easily added at a later point in time. Ideally, the equivalent Data Dictionary data elements (shown in brackets in the example below) are already known so that technical attributes as well as business semantics can be derived from the dictionary.  Inputs/Context o Company Code (BUKRS) o Plant (EWERK) o CFOP Category (J_1BINDUS3) o Material Usage (J_1BMATUSE) o Material Group (MATKL)  Outputs/Results o Tax Code (MWSKZ) Parameters are not always elementary (i.e. single value). This is why BRFplus also supports structure parameters, table parameters, and even deeply nested complex types (e.g. a structure with a component being a table). The service definition is shown in the next screenshot. In BRFplus a service is implemented with the help of a BRFplus Function. The Signature tab contains the context, which provides the inputs for the service call. It also contains a Result Data Object, the tax code. The following screenshot shows the function in the BRFplus workbench (transaction code BRF+).

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Data objects are used in BRFplus to define parameters. The parameter Material Group, for example, is defined by a data object shown in the next screenshot. This can be reached by selecting the hyperlink on MATKL in the Signature tab. You can see that properties such as texts, element type (text), and length are taken over from the data element MATKL which is defined in the data dictionary. BRFplus is also able to find possible values in domain lists or check tables so that a value help based on those values can be provided when modeling rules. Note: The implementation of the rule, i.e. how it calculates the tax code, will be shown a little later in this article.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 5

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Decision Service Trigger Implementation After having created and activated the data objects and functions, the new decision service is ready to be plugged into the right place in the process. Often you can find BADIs, enhancement spots or other exit options for exactly that purpose. For the setting of tax codes BADI ME_PROCESS_PO_CUST provides exactly what is needed in method PROCESS_ITEM. The screenshot below shows the BADI implementation in transaction SE19.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 6

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

The call of the decision service happens in the implementing class ZCL_IM_ME_PROCESS_CUST in method IF_EX_ME_PROCESS_PO_CUST~PROCESS_ITEM. METHOD if_ex_me_process_po_cust~process_item. DATA: ls_item TYPE mepoitem, ls_header TYPE mepoheader, lv_tax_code TYPE mwskz, lo_function TYPE REF TO if_fdt_function, lo_context TYPE REF TO if_fdt_context, lo_result TYPE REF TO if_fdt_result, lx_fdt TYPE REF TO cx_fdt. ls_item = im_item->get_data( ). ls_header = im_item->get_header( )->get_data( ). * NOTE: use CL_FDT_FUNCTION_PROCESS=>PROCESS( ) for better performance lo_function ?= cl_fdt_factory=>if_fdt_factory~get_instance( )->get_function( 'FE69C64EA2DB3811E10000000A428A79' ). TRY.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 7

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

lo_context = lo_function->get_process_context( ). * NOTE: consider using IDs instead of names (IDs do never change but names may) lo_context->set_value( iv_name = 'BUKRS' ia_value = ls_header-bukrs ). lo_context->set_value( iv_name = 'MATKL' ia_value = ls_item-matkl ). lo_context->set_value( iv_name = 'EWERK' ia_value = ls_item-werks ). lo_context->set_value( iv_name = 'J_1BINDUS3' ia_value = ls_item-j_1bindust ). lo_context->set_value( iv_name = 'J_1BMATUSE' ia_value = ls_item-j_1bmatuse ). lo_function->process( EXPORTING io_context = lo_context IMPORTING eo_result = lo_result ). lo_result->get_value( IMPORTING ea_value = lv_tax_code ). CATCH cx_fdt INTO lx_fdt. * TODO: error handling, take error message text from lx_fdt->mt_message ENDTRY. ls_item-mwskz = lv_tax_code. im_item->set_data( im_data = ls_item ). ENDMETHOD.

In the code first the item and header data is retrieved from the user interface. Then an instance of the BRFplus function is created. Note that the ID can be found in the BRFplus workbench (see screenshot above). The next step in the code is passing the parameters. Then the function is processed, meaning the decision service is called, and the result is copied back to the tax code field of the item data structure. There are also other ways of invoking a rules service. Some of them guarantee better performance. But this instance-based approach is easier to read. Decision Service Implementation The service is defined and plugged in to the right place in the process, but there no business logic has been defined so far. Business logic can be implemented in Rulesets in BRFplus. One or more rulesets can be created from the function screen. Rulesets can have pre-conditions and priorities to define the order of execution. In the tax code example there are two rulesets. One is valid for all cases where the company code is 0001 and the other one is valid for all other cases.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 8

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

The first ruleset (below) is self-explanatory. For demonstration purposes the ruleset has been deliberately defined in this simple way.

In practice, rulesets vary in complexity. To manage this complexity, rules can draw on different Expressions based on a wide range of Expression Types. The second Ruleset demonstrates the use of the Expression Type “Decision Table”. The second Ruleset is a little more complex as does not just consist of simple checks and value assignments. It also uses decision tables, spreadsheet-like rules, to implement more complex rules. In the Ruleset the decision tables are referenced by the Expressions “Find Tax Code based on CFOP Category” and “Find Tax Code based on Material Group and Plant”. The icon in front of these references indicates that they are decision tables (i.e. based on the Expression Type “Decision Table”).

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 9

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

The following screenshot shows a decision table that derives the tax code from the fields Material Group and Plant. Selecting the hyperlink on the expression takes the user to the decision table. Decision tables are very powerful and therefore used excessively in some use cases. Business people also love decision tables because they can load them into Microsoft Excel, change them and upload them into BRFplus again. Decision tables with several hundred or even thousands of rows are sometimes required by the domain experts. BRFplus also supports many other expression types: such as those to help implement mathematical calculations (formula expression) or analyze tabular data (loop expression, table operation expression).

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Finally all objects need to be activated and then the decision service is ready to be used.

Decision Service Testing A decision service can be tested directly in the BRFplus workbench on the Function user interface with the button Start Simulation. On the simulation screen values can be entered or loaded from excel.

When using the option “Execute and Display Processing Steps” the simulation output will be very detailed showing context, processing steps and result(s) in a well-organized execution hierarchy tree, which also can be downloaded into Microsoft Excel.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 11

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Finally, the decision service can of course also be tested in the ABAP debugger and in the UI.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

So the Set Tax Code task is now solved with help of a decision service implemented in BRFplus. With an effort of just a few hours BRFplus can be used to implement a decision service to cater for automation of many tasks, freeing up time for more value adding work. The business rules that implement the decision service can be understood and even be changed by the domain expert so that the IT professional does not need to understand the business details.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 14

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Related Content Carsten Ziegler, About Business Rules Carsten Ziegler, BRFplus a Business Rule Engine written in ABAP BRFplus Knowledge Burst For more information, visit the Business Rules Management homepage.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 15

BRFplus for Decision Services - How to Automatically Set the Tax Code in Purchase Order Creation

Copyright © Copyright 2011 SAP AG. All rights reserved. No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice. Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors. Microsoft, Windows, Excel, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, System i, System i5, System p, System p5, System x, System z, System z10, System z9, z10, z9, iSeries, pSeries, xSeries, zSeries, eServer, z/VM, z/OS, i5/OS, S/390, OS/390, OS/400, AS/400, S/390 Parallel Enterprise Server, PowerVM, Power Architecture, POWER6+, POWER6, POWER5+, POWER5, POWER, OpenPower, PowerPC, BatchPipes, BladeCenter, System Storage, GPFS, HACMP, RETAIN, DB2 Connect, RACF, Redbooks, OS/2, Parallel Sysplex, MVS/ESA, AIX, Intelligent Miner, WebSphere, Netfinity, Tivoli and Informix are trademarks or registered trademarks of IBM Corporation. Linux is the registered trademark of Linus Torvalds in the U.S. and other countries. Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries. Oracle is a registered trademark of Oracle Corporation. UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group. Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc. HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology. Java is a registered trademark of Oracle Corporation. JavaScript is a registered trademark of Oracle Corporation, used under license for technology invented and implemented by Netscape. SAP, R/3, SAP NetWeaver, Duet, PartnerEdge, ByDesign, SAP Business ByDesign, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and other countries. Business Objects and the Business Objects logo, BusinessObjects, Crystal Reports, Crystal Decisions, Web Intelligence, Xcelsius, and other Business Objects products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of Business Objects S.A. in the United States and in other countries. Business Objects is an SAP company. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary. These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.

SAP DEVELOPER NETWORK | sdn.sap.com © 2011 SAP AG

BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 16

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF