36
Custom BADIs in Script Logic

Custom Logic

Embed Size (px)

Citation preview

Page 1: Custom Logic

Custom BADIs in Script Logic

Page 2: Custom Logic

© SAP 2009 / Page 2

1. BPC version for NetWeaver Script Logic Overview2. Custom BADIs in Script Logic Overview3. Create a Custom BADI4. Testing and Debugging Custom BADIs5. Custom BADI Example6. References

Agenda

Page 3: Custom Logic

© SAP 2008 / Page 3

BPC version for NetWeaver ScriptLogic Overview

Script Logic – enables calculations on base-level cells that result in data stored withinan application. The results are aggregated up the dimensional hierarchy intact,without being re-calculated at upper levels.

Some example of when to use a Script Logic formulas are: unit times pricecalculations, foreign currency translation, allocations, and others.

Script logic can be run in any of three ways:Automatically after data is sent to the database from BPC for Excel using the Default.lgffile.After Journal data sends using either Default.lgf, or if present, Journal.lgf files.From Data Manager as a batch processing event to call Script Logic formulas.

Page 4: Custom Logic

© SAP 2008 / Page 4

BPC version for NetWeaver ScriptLogic Overview

Script Logic Feature Comparison

New Features in SAP Business Planning and Consolidation (not in SAP BusinessPlanning and Consolidation 5.x):

Script Logic DebuggingCall Custom LogicObeys Concurrency Locking within SAP Business Planning and Consolidation.

Changes in SAP Business Planning and Consolidation vs. SAP Business Planningand Consolidation 5.x:

SQL Based keywords are not supported.Run stored procedures were replaced with native Script Logic keywords.

See class CL_UJK_RUN_PROGRAMS for list of proceduresMinor differences in validation checking of Script Logic.Less SAP NetWeaver BI MDX keywords are supported than Microsoft MDX.

See function module BAPI_MDPROVIDER_GET_FUNCTIONS for a list of SAPNetWeaver BI supported MDX keywords.

Page 5: Custom Logic

© SAP 2008 / Page 5

BPC version for NetWeaver ScriptLogic Overview

Script Logic Basics

All Script Logic statements are Case-Insensitive.New to SAP Business Planning and Consolidation, all AppSet/Application/Dimension/Membernames are case-sensitive.

You will have two files for each Script logic you create..LGF - an ASCII file used to create/edit your logic calculations..LGX - the compiled logic file.

Page 6: Custom Logic

© SAP 2008 / Page 6

BPC version for NetWeaver ScriptLogic Overview

Maintaining Script Logic

Accessed from SAP Business Planning and Consolidation Administration in theScript Logic subdirectory in the hierarchy of a particular Application.

Page 7: Custom Logic

© SAP 2008 / Page 7

BPC version for NetWeaver ScriptLogic Overview

Nesting Logic Files

Default Logic gets executed on every write-back to an application.

Use the *INCLUDE command to have one logic file call another logic file.

Page 8: Custom Logic

BPC version for NetWeaver ScriptLogic Overview

How Script Logic worksThe Logic module:

Reads a specific data selection from the application.Applies to it a set of user-defined formulas (stored in a logic file).Derives the values.Writes those values back to the application.

Results are written directly to the application as base data, and are aggregated upthe dimensional hierarchy as they are, without being recalculated at upper levels.

All dimension member formulas are applied to these results.This process allows you to perform such calculations as units times price because theformulas are applied only to those members specified in the logic file.

Page 9: Custom Logic

BPC version for NetWeaver ScriptLogic Overview

Structure of Script Logic

Logic can be broken down into 3 componentsScoping- What am I running the data on?

Data manager scopingBPC for Excel Scoping*XDIM_Memberset

Body/Code – What do I want to do with the scoped records?Script Logic keywords (example *WHEN / *ENDWHEN, *REC Statements)Allocation LogicCustom BADI

Writing the record*Commit

Page 10: Custom Logic

BPC version for NetWeaver ScriptLogic Overview

Running Script LogicAdvanced logic can be automatically invoked each time data is sent to thedatabase.

Logic contained in the Default logic file is executed immediately after data is sent and theresults can be seen in SAP Business Planning and Consolidation 5.1 right away.

Advanced logic can be run from Data Manager for batch processing of formulas.Using Data Manager to execute Logic module formulas is useful for calculations that donot need to be executed immediately.For example, an administrator may decide to wait until all the data has been entered inthe local currency before generating the translated amounts in the reporting currencies.

Page 11: Custom Logic

BPC version for NetWeaver ScriptLogic Overview

Maintaining Script Logic in the Default.LGF fileAll logic in DEFAULT.LGF is run after data sends.The INCLUDE statement shown below enables currency translation to happen in real time,rather than as a batch process.

Page 12: Custom Logic

BPC version for NetWeaver ScriptLogic Overview

ProsReal-time - allows for real-time calculations.Flexible - enables you to apply different formulas to different applications within an applicationset (dimension logic is applied to all applications using the dimension).Syntax options - you can use MDX, Script Logic Keywords, and Custom ABAP.

ConsCustom maintenanceCan be too technical for certain users (for instance Custom BADI)If not properly written can be a negative performance impact

Page 13: Custom Logic

© SAP 2009 / Page 13

1. BPC version for NetWeaver Script Logic Overview2. Custom BADIs in Script Logic Overview3. Create a Custom BADI4. Testing and Debugging Custom BADIs5. Custom BADI Example6. References

Agenda

Page 14: Custom Logic

Custom BADIs in Script LogicOverview

Usage:*CALL_CUSTOM_LOGIC

DescriptionThis instruction is used to call any custom ABAP programming you have written

Examples:*XDIM_MEMBERSET ACCOUNT=CASH*XDIM_MEMBERSET RPTCURRENCY = LC*XDIM_MEMBERSET TIME = 2006.JAN*XDIM_MEMBERSET CATEGORY = ACTUAL*XDIM_MEMBERSET INTCO=NON_INTERCO

*CALL_CUSTOM_LOGIC CUST_CALC_ACCT

Operation TypeControl Flow

CategoryTechnical

Syntax*CALL_CUSTOM_LOGIC <BADI name>

Page 15: Custom Logic

Custom BADIs in Script LogicOverview

Usage:*START_BADI

DescriptionThis instruction is used to call any custom ABAP programming you have written *WITH PARAMETERS

Examples:*XDIM_MEMBERSET ACCOUNT=CASH*XDIM_MEMBERSET RPTCURRENCY = LC*XDIM_MEMBERSET TIME = 2006.JAN*XDIM_MEMBERSET CATEGORY = ACTUAL*XDIM_MEMBERSET INTCO=NON_INTERCO

*START_BADI CUST_CALC_ACCTACCT_FROM = 10000ACCT_TO = 10001

*END_BADI

Operation TypeControl Flow

CategoryTechnical

Syntax*START_BADI

<key1> = <value1><key2> = <value2>

*END_BADI

Optional ParametersYou can use the following optional parameters within a *START_BADI / *END_BADIinstruction:Query - Performs the default query. Valid values are On and Off; the default is On. Set Queryto Off if you want to perform your own query.Write - Automatically writes back the data. Valid values are On and Off; the default is On.Example*START_BADI TEST

QUERY=ON

WRITE=OFF

*END_BADI

Page 16: Custom Logic

Custom BADIs in Script LogicOverview

Call Custom LogicCan be used to call ABAP programs and parameters can be passed from the BPC ScriptLogic (it’s like defining new key words)

Script Logic DebuggingCustom Logic can be debugged

If the BADI has a filter, then in the script logic before calling the BADI, thecustomer needs to provide the filter value

NOTE: To pass parameters to the BADI, you can use the *START_BADI / *END_BADIcommandNOTE: The BADI will run on data that was filtered through the Data Manager prompts

All BPC Script Logic within BPC 7.0 Obeys Concurrency LockingBW Transaction RSPLSE

Page 17: Custom Logic

© SAP 2009 / Page 17

1. BPC version for NetWeaver Script Logic Overview2. Custom BADIs in Script Logic Overview3. Create a Custom BADI4. Testing and Debugging Custom BADIs5. Custom BADI Example6. References

Agenda

Page 18: Custom Logic

Create a Custom BADI

To create a BPC Script Logic Custom BADI, you must first create an EnhancementImplementation of the Enhancement Spot: UJ_CUSTOM_LOGIC

TWO ENTRY POINTS:(transactions SE19 and SE20)

Page 19: Custom Logic

Create a Custom BADI

Using Transaction SE19, you can create a new Enhancement Implementation like so:

Name the new Enhancement Implementation and assign it to an ABAP Package:

Page 20: Custom Logic

Create a Custom BADI

Using Transaction SE19, you can create a new Enhancement Implementation like so:

Assign the newEnhancementImplementation toa transport (TypeWorkbenchRequest) to moveit through theQA/PRODlandscape:

Page 21: Custom Logic

Create a Custom BADI

Using Transaction SE19, the next step is to create the new BADI Implementation like so:Define the BADI Implementation Name and the ABAP Implementation Class Namebehind the BADI

(The Implementation Class is where you code your custom logic in ABAP)

Page 22: Custom Logic

Create a Custom BADI

Using Transaction SE19, the next step is to assign the ABAP Implementation Class to atransport:

Assign the newImplementationClass to atransport(WorkbenchRequest) tomove it throughthe QA/PRODlandscape:

Page 23: Custom Logic

Create a Custom BADI

Using Transaction SE19, you have just created the starting framework for your new BADI:This screen allows you to modify your BADI configuration

Page 24: Custom Logic

Create a Custom BADI

Define a new KeyWord to call your newly created Script Logic Custom BADI:The BADI Filter Val is the same as the Key Word you use inside BPC Script Logic. Using thisKeyWord with “CALL_CUSTOM_LOGIC” or “START_BADI / END_BADI” will invoke your BADIcode

The BADI FilterValue is the Script

Logic KeyWord

ClickHere

Page 25: Custom Logic

Create a Custom BADI

Choose your KeyWord and set the value:NOTE: The KeyWord should represent what the Script Logic Custom BADI actually does(ie CUST_CALC_ACCT)

Page 26: Custom Logic

Create a Custom BADI

ACTIVATE the BADINOTE: This activation is only for the BADI Enhancement Implementation – you must alsoactivate your ABAP Implementing Class (see next few slides)

Page 27: Custom Logic

Create a Custom BADI

ACTIVATE the Implementing ClassNOTE: Once you have activated your BADI you should thereafter only have to deal with yourImplementing Class (unless you want to change the BADI properties – such as the Filter Value)

1st Click Here Next, Double-Click the text (or gostraight to Transaction SE24 and enterthe name of your Implementing Class)

Page 28: Custom Logic

Create a Custom BADI

ACTIVATE the Implementing ClassNOTE: You have all the options of ABAP Object-Oriented Class Methodologies (Inheritance,Encapsulation, Poly-Morphism, Public and Private Methods, Attributes and Types, etc)

Your Business-Specific Logic willgo inside the Execute Method

Page 29: Custom Logic

Create a Custom BADI

You are now ready to begin coding ABAP for your Script Logic Custom BADI:NOTE: Beginners should set a break-point inside the execute method first and see what datawill be passed to the BADI (filtering should be done in a careful and controlled manner).

Page 30: Custom Logic

© SAP 2009 / Page 30

1. BPC version for NetWeaver Script Logic Overview2. Custom BADIs in Script Logic Overview3. Create a Custom BADI4. Testing and Debugging Custom BADIs5. Custom BADI Example6. References

Agenda

Page 31: Custom Logic

Testing and Debugging CustomBADIs

Program UJK_SCRIPT_LOGIC_TESTER can be used to test and debug script logicstatements

Page 32: Custom Logic

Testing and Debugging CustomBADIs

Once you hit execute on the Script Logic Tester, the Debugger should pop up at the breakpoint you set in the Implementing Class

CT_DATA is the tablecontaining the retrieved dataNOTE: it is also where you

insert new records to bewritten back to the Application

Page 33: Custom Logic

© SAP 2009 / Page 33

1. BPC version for NetWeaver Script Logic Overview2. Custom BADIs in Script Logic Overview3. Create a Custom BADI4. Testing and Debugging Custom BADIs5. Custom BADI Example6. References

Agenda

Page 34: Custom Logic

Custom BADI – Simple example todelete records

method if_uj_custom_logic~execute.* Declarationsconstants:c_bus type string value 'BUSINESS',c_acct type string value 'ACCOUNT',c_ind type string value 'INDUSTRY',c_data type string value 'SIGNEDDATA'.

data:l_success type abap_bool,l_log_msg type string,l_ref type ref to data,lines type i,clines type string,lo_cx_uj_null_obj type ref to cx_uj_null_obj_ref,lo_cx_uj_static type ref to cx_uj_static_check.

field-symbols:<lt_data> type standard table,<l_acct> type any,<l_srcacct> type any,<l_ind> type any,<l_data> type any,<ls_tmpline> type any,<ls_line> type any,<l_bus> type any.

* End Declarations

break connz.cl_ujk_logger=>log( 'Starting Delete function.' ).

describe table ct_data lines lines.clines = lines.clear l_log_msg.concatenate 'Read' clines 'lines for deletion in Application' p_appl_id into l_log_msg separated by space.cl_ujk_logger=>log( l_log_msg ).

loop at ct_data assigning <ls_line>.assign component c_data of structure <ls_line> to <l_data>.clear <l_data>.

endloop.

cl_ujk_logger=>log( 'Ending Delete function.' ).

endmethod.

Page 35: Custom Logic

References

For instructions about implementing an SAP Business Add-In, see the ABAPonline help at:

http://help.sap.com/saphelp_nw70/helpdata/en/32/a83942424dac04e10000000a1550b0/content.htm.

See each of the BPC version for NetWeaver Support Package’s Documentation Addendumfor new supported Script Logic keywordsSDN BLOGS

Running BPC process chains within non-BPC process chains:https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/12929How to Pass Parameters to Custom Logic BADI using START_BADIhttps://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/20f4252d-98ca-2b10-e689-f85085ae2d12

Page 36: Custom Logic

© SAP 2009 / Page 36

Copyright 2009 SAP AGAll 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 changedwithout prior notice.

Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.

SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, SAP Business ByDesign, ByDesign, PartnerEdge and other SAP products and services mentioned herein as well as their respective logos aretrademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned and associated logos displayedare the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.

The information in this document is proprietary to SAP. This document is a preliminary version and not subject to your license agreement or any other agreement with SAP. This documentcontains only intended strategies, developments, and functionalities of the SAP® product and is not intended to be binding upon SAP to any particular course of business, product strategy,and/or development. SAP assumes no responsibility for errors or omissions in this document. SAP does not warrant the accuracy or completeness of the information, text, graphics, links, orother items contained within this material. This document is provided without a warranty of any kind, either express or implied, including but not limited to the implied warranties ofmerchantability, fitness for a particular purpose, or non-infringement.

SAP shall have no liability for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials. This limitationshall not apply in cases of intent or gross negligence.

The statutory liability for personal injury and defective products is not affected. SAP has no control over the information that you may access through the use of hot links contained in thesematerials and does not endorse your use of third-party Web pages nor provide any warranty whatsoever relating to third-party Web pages

Weitergabe und Vervielfältigung dieser Publikation oder von Teilen daraus sind, zu welchem Zweck und in welcher Form auch immer, ohne die ausdrückliche schriftliche Genehmigung durchSAP AG nicht gestattet. In dieser Publikation enthaltene Informationen können ohne vorherige Ankündigung geändert werden.

Einige von der SAP AG und deren Vertriebspartnern vertriebene Softwareprodukte können Softwarekomponenten umfassen, die Eigentum anderer Softwarehersteller sind.

SAP, R/3, xApps, xApp, SAP NetWeaver, Duet, SAP Business ByDesign, ByDesign, PartnerEdge und andere in diesem Dokument erwähnte SAP-Produkte und Services sowie diedazugehörigen Logos sind Marken oder eingetragene Marken der SAP AG in Deutschland und in mehreren anderen Ländern weltweit. Alle anderen in diesem Dokument erwähnten Namenvon Produkten und Services sowie die damit verbundenen Firmenlogos sind Marken der jeweiligen Unternehmen. Die Angaben im Text sind unverbindlich und dienen lediglich zuInformationszwecken. Produkte können länderspezifische Unterschiede aufweisen.

Die in diesem Dokument enthaltenen Informationen sind Eigentum von SAP. Dieses Dokument ist eine Vorabversion und unterliegt nicht Ihrer Lizenzvereinbarung oder einer anderenVereinbarung mit SAP. Dieses Dokument enthält nur vorgesehene Strategien, Entwicklungen und Funktionen des SAP®-Produkts und ist für SAP nicht bindend, einen bestimmtenGeschäftsweg, eine Produktstrategie bzw. -entwicklung einzuschlagen. SAP übernimmt keine Verantwortung für Fehler oder Auslassungen in diesen Materialien. SAP garantiert nicht dieRichtigkeit oder Vollständigkeit der Informationen, Texte, Grafiken, Links oder anderer in diesen Materialien enthaltenen Elemente. Diese Publikation wird ohne jegliche Gewähr, wederausdrücklich noch stillschweigend, bereitgestellt. Dies gilt u. a., aber nicht ausschließlich, hinsichtlich der Gewährleistung der Marktgängigkeit und der Eignung für einen bestimmten Zwecksowie für die Gewährleistung der Nichtverletzung geltenden Rechts.

SAP übernimmt keine Haftung für Schäden jeglicher Art, einschließlich und ohne Einschränkung für direkte, spezielle, indirekte oder Folgeschäden im Zusammenhang mit der Verwendungdieser Unterlagen. Diese Einschränkung gilt nicht bei Vorsatz oder grober Fahrlässigkeit.

Die gesetzliche Haftung bei Personenschäden oder die Produkthaftung bleibt unberührt. Die Informationen, auf die Sie möglicherweise über die in diesem Material enthaltenen Hotlinkszugreifen, unterliegen nicht dem Einfluss von SAP, und SAP unterstützt nicht die Nutzung von Internetseiten Dritter durch Sie und gibt keinerlei Gewährleistungen oder Zusagen überInternetseiten Dritter ab.

Alle Rechte vorbehalten.