How to Create Formula Functions BRF Plus
March 20, 2017 | Author: satyajc | Category: N/A
Short Description
Download How to Create Formula Functions BRF Plus...
Description
How to Create Formula Functions
Applies to: Business Rules Framework plus shipped with enhancement package 1 for SAP NetWeaver 7.0.
Summary The paper introduces the formula functions in BRFplus. The paper also explains the procedure to create custom formula functions and the use of these formula functions in business rules. Author:
Carsten Ziegler
Company: SAP AG Created on: 01 August 2008
About the Author Carsten Ziegler is the Architect and Project Manager of Business Rules 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 © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 1
How to Create Formula Functions
Table of Contents Expression Type Formula...................................................................................................................................3 Formula Functions ..............................................................................................................................................4 Built-in Functions.............................................................................................................................................4 Formula Functions in Enhancement Package 1 .............................................................................................5 Formula Functions in ABAP ............................................................................................................................9 Definition of Custom Formula Functions ..........................................................................................................11 Scenario ........................................................................................................................................................11 Formula Function Method .............................................................................................................................11 Step 1: Create a class for the formula function. .........................................................................................................11 Step 2: Create a method for the formula function. .....................................................................................................13 Step 3: Implement the method. ..................................................................................................................................14 Step 4: Create Documentation...................................................................................................................................15
Application with Application Exit ...................................................................................................................16 Step 5: Create a BRFplus Application........................................................................................................................16 Step 6: Create an Application Exit Class. ..................................................................................................................17 Step 7: Implement the Application Exit Method for Functions. ...................................................................................18 Step 8: Add the Exit Class to your Application. ..........................................................................................................18
Testing the Formula Function .......................................................................................................................19 Step 9: Create a Formula Expression using your new Function. ...............................................................................19 Step 10: Create a BRFplus Function to Test the Formula Function...........................................................................21 Step 11: Create a Test Program. ...............................................................................................................................22
Related Content................................................................................................................................................24 Copyright...........................................................................................................................................................25
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 2
How to Create Formula Functions
Expression Type Formula The expression type formula allows the definition of simple and complex formula expressions. A formula expression can be used for arithmetical and simple logical calculations. For instance, •
Numeric:
1+2*3^4/6-5
--> 23
VAR x = 1 IF (x = 1, 2, 3)
--> 2
•
Textual:
CONCATENATE( 'A', 'B' )
--> 'AB'
•
Boolean:
'1 = 2 AND 1 = 1'
--> false
Several standard functions as well as time and date functions are available in the formula expression. Formula expressions can also use context data and nested expressions in the formula. For instance, it is possible to nest one formula into another. A good example is a case expression nested into a formula (See image below). The case expression converts qualitative information into quantitative information that can be used for arithmetical calculations.
The formula returns an amount. The amount consists of two fields: Number and Currency. MONTHLY_SALARY is a field of type amount in the context. PERFORMANCE_FACTOR is a nested case expression that turns the qualitative information, PERFORMANCE_RATING into the quantitative information, PERFORMANCE_FACTOR. The quantitative information PERFORMANCE_FACTOR is then used by the formula expression for the calculation of an amount.
The expression type is implemented with the interface IF_FDT_FORMULA and class CL_FDT_FORMULA. Formulas are provided as string or token table. Internally, the formula is parsed into tokens according to the Reverse Polish Notation. In the package SFDT_DEMO_OBJECTS, you can find reports that demonstrate how to use the API for the creation and processing of formula expressions. Note: Internally, the expression type formula uses the formula builder component (package S_FORMULA_BUILDER). In this package, you can also find the demo reports SFBE_EXAMPLE1 to SFBE_EXAMPLE8.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 3
How to Create Formula Functions
Formula Functions Functions are built-in functions that can be used in formula expressions. For instance, in the image given below, CONCATENATE and TOUPPER are formula functions. The result of the formula will be ABCDEFG.
Many formula functions are shipped with BRFplus. The formula expression also allows the use of custom formula functions. Hence, it is possible to extend the functionality of formula expressions. Built-in Functions Some formula functions are called built-in functions and are used with simplified infix syntax. Infix Syntax
Description
+
Addition
-
Subtraction
*
Multiplication
/
Division
^
Raise to a power (x to the power of y)
=
Equals
>=
Greater than or equal to
Greater than
AND
And
&
Concatenate
OR
Or
NOT
Not
DIV
Quotient (without fraction)
MOD
Modulo division (remainder of division)
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 4
How to Create Formula Functions
Formula Functions in Enhancement Package 1 With Enhancement Package 1 the following functions are shipped: Function
Description
SUBSTRING( IM_ARG , IM_OFFSET , IM_LENGTH )
Part of character string
TOUPPER( IM_ARG )
Conversion to uppercase letters
EQUIV( IM_ARG1 , IM_ARG2 )
Returns true if both the logical expressions are true or when both of them are false. If the logical expressions differ then this returns false.
IMPLY( IM_ARG1 , IM_ARG2 )
If logical expression 1 is true, the logical expression 2 must be true so that the result is true. Otherwise, the result is false. If logical expression 1 is false, then the result is always true.
SQUARE_ROOT( IM_NUMBER )
Root
ABS_VALUE( IM_NUMBER )
Amount (Absolute value) of a number
LOG_E( IM_NUMBER )
Natural logarithm
LOG_10( IM_NUMBER )
Logarithm for basis 10
EXPONENT( IM_NUMBER )
Exponential function
IF( IM_CONDITION , IM_RESULT_TRUE , IM_RESULT_FALSE )
Test – if condition is true then the second parameter is returned. Otherwise, the third parameter is returned.
SIGN_( IM_NUMBER )
Indicates whether a number is positive, negative or equal to 0
TRUNC_( IM_NUMBER )
Integer part
FRAC_( IM_NUMBER )
Decimal part
SIN_( IM_NUMBER )
Sine
COS_( IM_NUMBER )
Cosine
TAN_( IM_NUMBER )
Tangent
ARCSIN( IM_NUMBER )
Arc Sine
ARCCOS( IM_NUMBER )
Arc Cosine
ARCTAN( IM_NUMBER )
Arc Tangent
SINH_( IM_NUMBER )
Hyperbolic Sine
COSH_( IM_NUMBER )
Hyperbolic Cosine
TANH_( IM_NUMBER )
Hyperbolic Tangent
TONUMBER( IM_VALUE )
Amount, Quantity -> Number
AMOUNT( IM_VALUE , IM_CURRENCY )
Currency amount
QUANTITY( IM_VALUE , IM_UNIT )
Quantity with Unit
PRICE( IM_AMOUNT , IM_QUANTITY )
Currency amount and quantity are linked to a price If you have calculations with prices, the currency and quantity units are compared. If these units are different, the evaluation of the formula will produce an error.
CONDENSE( IV_STRING )
Trims off leading trailing spaces and reduces consecutive spaces inside the string to single
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 5
How to Create Formula Functions
space EDIT_DISTANCE( IV_STRING1 , IV_STRING2 )
Computes the Levenshtein distance which gives a measure of how similar the strings are
STRING_SIMILARITY( IV_STRING1 , IV_STRING2 )
This is the edit distance calculated above divided by the length of the longer string. Used for measuring string similarity.
Additionally, the following date & time functions are also shipped: Function
Description
DT_DURATION_DIFF (IS_TIMEPOINT1 , IS_TIMEPOINT2 , IV_TIME_UNIT , RS_DIFFERENCE)
Calculate duration between two Timepoints (returns Decimals)
DT_DURATION_DIFF_INT (IS_TIMEPOINT1 , IS_TIMEPOINT2 , IV_TIME_UNIT , RS_DIFFERENCE)
Calculate duration between two Timepoints (returns Integer only)
DT_GET_CURRENT_DATE (RS_TIMEPOINT)
Get current date
DT_GET_CURRENT_DT (RS_TIMEPOINT)
Get current date & time
DT_GET_CURRENT_TIME (RS_TIMEPOINT)
Get current time
DT_GET_CURRENT_UTC (RS_TIMEPOINT)
Get current UTC timestamp
DT_IS_ACTIVE (IS_TIMEPOINT , RV_IS_ACTIVE)
Check whether Timepoint is active with regard to the calendar An active Timepoint is the working Timepoint. For example, Saturday and Sunday are non-working days and Monday to Friday are working days. We can call Saturday and Sunday as inactive Timepoint and Monday to Friday as active Timepoint. Also, if the work timings on Monday to Friday are 08:00 to 17:00 hours, the Timepoint Monday, 18:00 hours is inactive and Timepoint Friday, 10:00 hours is active.
DT_IS_VALID (IS_TIMEPOINT , RV_IS_VALID)
Check validity of Timepoint
DT_MAX (IS_TIMEPOINT1 , IS_TIMEPOINT2 , RS_TIMEPOINT)
Find the later one of two given Timepoints
DT_MIN (IS_TIMEPOINT1 , IS_TIMEPOINT2 , RS_TIMEPOINT)
Find the earlier one of two given Timepoints
DT_NEXT_ACTIVE (IS_TIMEPOINT , RS_TIMEPOINT)
Get the next active Timepoint if given Timepoint is not active
DT_PART_DAYS (IS_TIMEPOINT , RV_NUMBER)
Get part from Timepoint: days
DT_PART_HOURS (IS_TIMEPOINT , RV_NUMBER)
Get part from Timepoint: hours
DT_PART_MINUTES (IS_TIMEPOINT , RV_NUMBER)
Get part from Timepoint: minutes
DT_PART_MONTHS (IS_TIMEPOINT , RV_NUMBER)
Get part from Timepoint: months
DT_PART_SECONDS (IS_TIMEPOINT ,
Get part from Timepoint: seconds
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 6
How to Create Formula Functions
RV_NUMBER) DT_PART_YEARS (IS_TIMEPOINT , RV_NUMBER)
Get part from Timepoint: years
DT_PREVIOUS_ACTIVE (IS_TIMEPOINT , RS_TIMEPOINT)
Get the previous active Timepoint if given Timepoint is not active
DT_ROUND_TO_FIRST (IS_TIMEPOINT , IV_TIME_UNIT , RS_TIMEPOINT)
Round Timepoint to first with regard to the given time unit
DT_ROUND_TO_LAST (IS_TIMEPOINT , IV_TIME_UNIT , RS_TIMEPOINT)
Round to first rounds the Timepoint to the beginning of any unit. For example, the result for method DT_ROUND_TO_FIRST on Timepoint 2007-01-10T16:00:00 and unit as day will be 2007-01-10T00:00:00. Round Timepoint to last with regard to the given time unit Round to last rounds the Timepoint to the end of any unit. For example, the result for method DT_ROUND_TO_LAST on Timepoint 2007-0110T16:00:00 and unit is end of day will be 200701-10T23:59:59.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 7
How to Create Formula Functions
The following table functions are also shipped: Function
Description
TABLE_MAX_AMOUNT (ITA_TABLE , IV_COLUMN_NAME , RV_MAX_AMOUNT)
Maximum amount found in a table column
TABLE_MAX_NUMBER (ITA_TABLE , IV_COLUMN_NAME , RV_MAX_NUMBER)
Maximum number found in a table column
TABLE_MAX_QUANTITY (ITA_TABLE , IV_COLUMN_NAME , RV_MAX_QUANTITY)
Maximum quantity found in a table column
TABLE_MAX_TIMEPOINT (ITA_TABLE , IV_COLUMN_NAME , RV_MAX_TIMEPOINT)
Maximum Timepoint found in a table column
TABLE_MIN_AMOUNT (ITA_TABLE , IV_COLUMN_NAME , RV_MIN_AMOUNT)
Minimum amount found in a table column
TABLE_MIN_NUMBER (ITA_TABLE , IV_COLUMN_NAME , RV_MIN_NUMBER)
Minimum number found in a table column
TABLE_MIN_QUANTITY (ITA_TABLE , IV_COLUMN_NAME , RV_MIN_QUANTITY)
Minimum quantity found in a table column
TABLE_MIN_TIMEPOINT (ITA_TABLE , IV_COLUMN_NAME , RV_MIN_TIMEPOINT)
Minimum Timepoint found in a table column
TABLE_SUM_AMOUNT (ITA_TABLE , IV_COLUMN_NAME , RV_SUM_AMOUNT)
Sum of the amounts in a table column
TABLE_SUM_NUMBER (ITA_TABLE , IV_COLUMN_NAME , RV_SUM_NUMBER)
Sum of the amounts in a table column
TABLE_SUM_QUANTITY (ITA_TABLE , IV_COLUMN_NAME , RV_SUM_QUANTITY)
Sum of the amounts in a table column
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 8
How to Create Formula Functions
Formula Functions in ABAP Formula functions are implemented in ABAP methods. In the ABAP class, CL_FOEV_BUILTINS, formula function builds can be found. Implementation of the date and time formula functions can be found in the ABAP class, CL_FDT_DATE_TIME.
Some formula functions can also be found in the ABAP class CL_FDT_FORMULA. Most formula functions have a method documentation that is useful while creating a custom formula function. To call the method documentation, choose the icon (circled in red) as shown in the image below.
An external breakpoint can also be set in class CL_FDT_FORMULA and method GET_FUNCTIONALS. The BRFplus workbench (transaction FDT_WORKBENCH) is called to find out which functions exist and where they are implemented in BRFplus.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 9
How to Create Formula Functions
In the image above, the two parameters CT_FUNCTIONAL_DEFINITION and CT_FUNCTIONAL_CATEGORY have been changed in the method. CT_FUNCTIONAL_CATEGORY contains a list of all the function categories.
CT_FUNCTIONAL_DEFINITION contains a list of all functions assigned to a category and the method of implementation.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 10
How to Create Formula Functions
Definition of Custom Formula Functions Now that we know what a formula function is and how it is implemented in BRFplus, we can take a look at how custom formula functions are built. Firstly, the task to be achieved by the new formula function is defined. Then, the formula function is developed and added to the list of formula functions. Lastly, the formula function is tested with the help of an example. Scenario The task is to provide a very special function which removes decimal values, if the decimal value is equal to zero. The result is a text. Example: Value before
1234567.890000
Value after
1234567.89
Formula: REMOVE_TRAILING_ZEROS ( NUMBER ) Formula Function Method Step 1: Create a class for the formula function.
In order to enable BRFplus to use the new class (NetWeaver 710 or higher) it is necessary to add an access object SFDT_CODE_COMPOSER_ACCESS in the client interface section of the package in which the class is implemented.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 11
How to Create Formula Functions
The class has to be added to the list of accessible objects.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 12
How to Create Formula Functions
Step 2: Create a method for the formula function. The method must be defined as a static public method. Method Definition Create a static public method for your formula function as shown in the picture.
Method Interface Definition The parameters correspond to the inputs to be used when defining a formula using the function.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 13
How to Create Formula Functions
Step 3: Implement the method. METHOD remove_trailing_zeros. DATA: lv_number TYPE if_fdt_types=>element_number, lv_i TYPE i, lv_last TYPE i, lv_decimals TYPE abap_bool. CHECK iv_value IS NOT INITIAL. ">>> rv_value = iv_value. TRY. lv_number = iv_value. CATCH cx_sy_conversion_no_number. * no number means no trailing zeros RETURN. ">>> ENDTRY. CONDENSE rv_value. lv_i = strlen( rv_value ). DO lv_i TIMES. lv_i = sy-index - 1. IF lv_decimals EQ abap_false. IF rv_value+lv_i(1) NA '0123456789'. lv_decimals = abap_true. lv_last = lv_i. ENDIF. ELSE. "lv_decimals eq abap_true. IF rv_value+lv_i(1) NE '0'. lv_last = lv_i + 1. ENDIF. ENDIF. ENDDO. rv_value = rv_value(lv_last). ENDMETHOD.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 14
How to Create Formula Functions
Step 4: Create Documentation. The documentation is saved as a SAPScript document. This will also be reused in the ABAP WebDynpro UI such as BRFplus Workbench.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 15
How to Create Formula Functions
Application with Application Exit Step 5: Create a BRFplus Application Use the BRFplus Workbench (transaction FDT_WORKBENCH) to create an application. To create the application, you can either use the menu bar or the context menu. Using the Context Menu In the Navigation Panel, choose the Repository view, in the context menu, choose Create Application…
Using the Menu Bar In the menu bar, choose Workbench > Create Application... In the Object Creation dialog box that appears, enter the data as shown below.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 16
How to Create Formula Functions
The application name has to be unique. For instance, you can give a unique name such as ZSDN. To create an application for testing, use a local application. Step 6: Create an Application Exit Class. Define a setting class for your application. The setting class is used to implement application specific features. For the formula functions, we need to create such an application exit class. The application exit class needs to implement the interface IF_FDT_APPLICATION_SETTINGS.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 17
How to Create Formula Functions
Step 7: Implement the Application Exit Method for Functions. We only want to implement the exit for the formula functions. The interface provides static attributes for the exits to be used. Hence, we need to create a class constructor and set the attribute for the formula functions to true. METHOD class_constructor. if_fdt_application_settings~gv_get_formula_functionals = abap_true. ENDMETHOD. Now, we add a formula function in the exit method. METHOD if_fdt_application_settings~get_formula_functionals. DATA: ls_func_def TYPE if_fdt_formula=>s_functional_def, ls_func_categ TYPE if_fdt_formula=>s_functional_categ. ls_func_categ-category = 'SDN_EXAMPLES'. ls_func_categ-description = 'Examples for SDN'. APPEND ls_func_categ TO ct_functional_category. ls_func_def-category = 'SDN_EXAMPLES'. ls_func_def-token = 'REMOVE_TRAILING_ZEROS'. ls_func_def-class = 'CL_FDT_SDN_FORMULA_FUNCTION'. ls_func_def-method = 'REMOVE_TRAILING_ZEROS'. APPEND ls_func_def TO ct_functional_definition. ENDMETHOD. Note: The categories are used to group the formula functions. It makes sense to create a new category when new formula functions are introduced to solve similar problems.
Warnings may be received when dummy implementation are not created for the other methods in IF_FDT_APPLICATION_SETTINGS. In such a case, create an empty method. The empty method will not be processed by BRFplus because of the code in the class constructor. Step 8: Add the Exit Class to your Application. When the application exit class is activated, add it to the application and activate the application.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 18
How to Create Formula Functions
Testing the Formula Function Step 9: Create a Formula Expression using your new Function. In the Navigation Panel, use the application’s context menu to create a formula expression. The new application exit will work only for objects in your application.
The new formula function appears in the UI of the formula expression. The new formula function can be used in the formula expressions.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 19
How to Create Formula Functions
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 20
How to Create Formula Functions
Step 10: Create a BRFplus Function to Test the Formula Function. Create a function using the application’s context menu. The function uses the formula expression as the top expression and has the same result as the formula expression. All objects have to be activated.
Use the simulation tool to test the function and debug your formula function. To use the simulation tool, in the menu bar, choose Tools > Simulation
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 21
How to Create Formula Functions
Step 11: Create a Test Program. REPORT BRF_FORMULA_FUNCTION_SDN. * This report tests the creation of an application with application exit * for formula functions. It creates also a function and a formula * expression. At the end the function is processed. * In this example there is no exception/error handling. * Instead of activaten, save, dequeue on each object this can also be * bundled to save some lines of code (see other tutorials and demo * reports). DATA: lo_factory
TYPE REF TO if_fdt_factory, lo_application TYPE REF TO if_fdt_application, lo_formula TYPE REF TO if_fdt_formula, lv_formula TYPE string, lo_function TYPE REF TO if_fdt_function, lv_name TYPE if_fdt_types=>name, lt_message TYPE if_fdt_types=>t_message, lv_activation_failed TYPE abap_bool, lx_fdt TYPE REF TO cx_fdt, lv_result TYPE string, ls_message TYPE if_fdt_types=>s_message. TRY. lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( ). * creation of a local application with application exit lo_application = lo_factory->get_application( ). lo_application->if_fdt_transaction~enqueue( ). lo_application->create_local_application( ). lo_application->set_development_package( '$TMP' ). lv_name = cl_fdt_services=>get_unique_name( ). lo_application->if_fdt_admin_data~set_name( lv_name ). lo_application->set_settings_class( iv_class = 'CL_FDT_SDN_APPL_SETTINGS' ). lo_application->if_fdt_transaction~activate( IMPORTING et_message = lt_message ev_activation_failed = lv_activation_failed ). IF lv_activation_failed EQ abap_true. LOOP AT lt_message INTO ls_message. WRITE / ls_message-text. ENDLOOP. RETURN. ENDIF. lo_application->if_fdt_transaction~save( ). lo_application->if_fdt_transaction~dequeue( ).
* get a factory for the new application so that new objects are created * for this application and the application exit is used lo_factory = cl_fdt_factory=>if_fdt_factory~get_instance( lo_application->mv_id ).
* creation of a formula expression lo_formula ?= lo_factory->get_expression( iv_expression_type_id = if_fdt_constants=>gc_exty_formula ). lo_formula->if_fdt_transaction~enqueue( ). lo_formula->if_fdt_admin_data~set_name( 'MY_FUNCTIONAL_TEST' ). lo_formula->if_fdt_expression~set_result_data_object( if_fdt_constants=>gc_dobj_element_text ). lv_formula = 'REMOVE_TRAILING_ZEROS($1234567.890000$)'. REPLACE ALL OCCURRENCES OF '$' IN lv_formula WITH ''''. lo_formula->set_formula( lv_formula ). lo_formula->if_fdt_transaction~activate(
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 22
How to Create Formula Functions
IMPORTING et_message
= lt_message ev_activation_failed = lv_activation_failed ). IF lv_activation_failed EQ abap_true. LOOP AT lt_message INTO ls_message. WRITE / ls_message-text. ENDLOOP. RETURN. ENDIF. lo_formula->if_fdt_transaction~save( ). lo_formula->if_fdt_transaction~dequeue( ).
* creation of a function lo_function ?= lo_factory->get_function( ). lo_function->if_fdt_transaction~enqueue( ). lo_function->if_fdt_admin_data~set_name( 'MY_FUNCTIONAL_TEST' ). lo_function->set_expression( lo_formula->mv_id ). lo_function->set_result_data_object( if_fdt_constants=>gc_dobj_element_text ). lo_function->if_fdt_transaction~activate( IMPORTING et_message = lt_message ev_activation_failed = lv_activation_failed ).
IF lv_activation_failed EQ abap_true. LOOP AT lt_message INTO ls_message. WRITE / ls_message-text. ENDLOOP. RETURN. ENDIF. lo_function->if_fdt_transaction~save( ). lo_function->if_fdt_transaction~dequeue( ).
* processing of the function (includes formula expression and functional) cl_fdt_function_process=>process( EXPORTING iv_function_id = lo_function->mv_id IMPORTING ea_result = lv_result ).
WRITE: / 'Formatted String:' , lv_result. CATCH cx_fdt INTO lx_fdt. LOOP AT lx_fdt->mt_message INTO ls_message. WRITE: / ls_message-text. ENDLOOP. ENDTRY.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 23
How to Create Formula Functions
Related Content
BRFplus – The Very Basics
Using BRFplus with Third-Party Rules Engine
Carsten Ziegler, About Business Rules: https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/9713
Carsten Ziegler, BRFplus a Business Rule Engine written in ABAP, https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/8889
Carsten Ziegler, Important Information for Using BRFplus https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/11632
Rajagopalan Narayanan, Business Rules and Software Requirements, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40aae118-42c2-2a10-fcaffdd9d30bcb1a
Rajagopalan Narayanan, Seven Tips for Your First Business Rules Project, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/201a9e3d-3ec2-2a10-85b2ce56d276dd7a
Rajagopalan Narayanan, Real World Return of Investment Scenarios with Business Rules Management, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b050905e-3cc22a10-979a-81a57a787f56
Rajagopalan Narayanan, Five Reasons to Build Agile Systems Using Business Rules Management Functionality, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/504486eb-43c2-2a10-f5a7e84ef3fd45be
Rajagopalan Narayanan, How Business Rules Management Functionality Helps Tariff Plans Management in Transportation and Shipping, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/40a9cf69-40c2-2a10-8a8b969fb311dd31
Rajagopalan Narayanan, Getting Started with Business Rules Management, https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/70c669d8-3ac2-2a10-0e96c7c3786168f0
Online Help: http://docudelivery.wdf.sap.corp:1080/saphelp_docs/Netweaver/nw70_Ehp01/index/en/helpdata/ en/cc/85414842c8470bb19b53038c4b5259/frameset.htm
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 24
How to Create Formula Functions
Copyright © 2008 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, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation. IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, System i, System i5, System p, System p5, System x, System z, System z9, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, POWER5+, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation. 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 Sun Microsystems, Inc. JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape. MaxDB is a trademark of MySQL AB, Sweden. SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, 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 in several other countries all over the world. 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. These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement. SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages. Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.
SAP DEVELOPER NETWORK | sdn.sap.com © 2008 SAP AG
BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com 25
View more...
Comments