0% found this document useful (0 votes)
77 views

Implementing BAdI's For SAP BPC - Tips & Tricks - Element61

Uploaded by

Bo Zhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

Implementing BAdI's For SAP BPC - Tips & Tricks - Element61

Uploaded by

Bo Zhang
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

Implementing BAdI’s for SAP BPC - Tips & Tricks


Home > Knowledge base > Implementing BAdI’s for SAP BPC - Tips & Tricks

  

Introduction
SAP Business Planning and Consolidation (SAP BPC) is available in a version for SAP
Netweaver and a version for the Microsoft platform. SAP BPC Netweaver has the advantage
that ABAP (Advanced Business Application Programming) can be used, the SAP
programming language.
Search 
The SAP BPC script logic can be converted to ABAP, using the SAP BAdI (Business Add Ins)
CONTACT 
functionality. BAdI is an enhancement to the standard version of the code of SAP. The
performance of BAdIs is signi cant better than SAP BPC script.
Competences
This document combines several tips & tricks that will help you creating BAdI
Customers implementations for SAP BPC.

News Choose the right BAdI


Open the BAdi Builder via transaction SE18 to display all the available Enhancement Spot
Academy entries. Several BAdIs relevant to SAP BPC, are available (eg UJR_WRITE_BACK,
UJ_CUSTOM_LOGIC) and can be found by searching (press F4) for the string UJ*. Select the
Events
one that best ts your needs.

Knowledge base Figure 1: BAdI Builder

Meet the team

Join us

click to enlarge
About us
Once you display the selected enhancement spot, right-click Implementations and choose
Take
Create BAdI Implementation orthe Analytics
select & AI Maturity
an existing Survey
implementation.

Figure 2: Create BAdI Implementation


Contact us

   EN NL FR

click to enlarge

Several objects need to be created:

Class (eg ZCLASS_BADI_JOURNAL); Create a new class per BAdI implementation,


Enhancement Implementation (eg ZBPC_ELEMENTARYPACK); One enhancement
implementation can contain multiple BAdI implementations,
BAdI Implementation (eg ZBPC_BADI_JOURNAL_C_IFRS_DEV). One BAdI
implementation can be linked to one or more applications.

Another way to access existing BAdI coding is via transaction SE80 Object Navigator. Enter
the desired class and open the method to change it directly.

Figure 3: Object Navigator

click to enlarge

Filter the BAdI


https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 1/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

Once the Enhancement Implementation is available, you need to lter the BAdI. This
guarantees that the code is only executed for the desired application set and application
(which corresponds to InfoArea and InfoCube respectively). Multiple lter combinations can
be added by clicking Create Filter Combination multiple times.

The lters are speci c for each Enhancement Spot. Below is an example of the
UJR_WRITE_BACK enhancement Spot.

Figure 4: Filter the BAdI

click to enlarge

Module_ID can have several values:

COMM Comment Entry


Search 
DM Data Manager CONTACT 
DOCS Document Modi cations
Competences
JRN Journal Entry

Customers MAN Manual Input

News
Declare Data
Academy At the beginning of the method, several constants, eld symbols, etc are declared. A
constant is a xed value, eg value AST (Account Type Asset). If this value has to be changed,
Events the change has to be done only once.

CONSTANTS: c_acctype_act TYPE c LENGTH 3 VALUE 'AST', "asset


Knowledge base
Field symbols and data references allow dynamic access to data objects. No need to specify
Meet the team the name of the object like with static access, eld symbols and data references allow you to
access and pass data objects whose name and attributes you do not know until runtime.
Join us FIELD-SYMBOLS:
TYPE table, "result itab
About us
The declaration for each custom object used in this document is listed in Annex.
Take the Analytics & AI Maturity Survey
Access Incoming Data
Facilitating access to any dimension Contact
requiresusextensive coding, which is due to the
abstractness of the BAdI implementation.
   The following code enables access to the dimension account and should to be repeated for EN NL FR
each dimension that needs to be consulted or updated.

"Find the account dimension by its type


LOOP AT it_dim_obj ASSIGNING

WHERE dim_type = uj00_cs_dim_type-account.


lo_account ?=
-dim_obj.
ls_account =
.
ENDLOOP.
"preparation: create data structure and assign fields
CREATE DATA lr_data LIKE LINE OF ct_array.
ASSIGN lr_data->* TO
.
ASSIGN COMPONENT ls_account-dimension OF
STRUCTURE
TO
. "account

The object it_dim_obj contains the metadata of the dimensions. You can nd the InfoObject
name for each dimension and all of its attributes.
https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 2/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

Figure 5: Contents of IT_DIM_OBJ

click to enlarge

Figure 6: Contents of IT_DIM_OBJ(1)-T_ATTR

click to enlarge

Figure 7: Contents of LS_ACCOUNT

Search 
CONTACT 
Competences
click to enlarge

Customers The object uj00_cs_dim_type is de ned in the global type pool UJ00. uj00_cs_dim_type-
account can thus be replaced by uj00_cs_dim_type-entity etc for other dimensions.
News
begin of uj00_cs_dim_type,
account type uj_dim_type value 'A',
Academy
entity type uj_dim_type value 'E',
time type uj_dim_type value 'T',
Events
currency type uj_dim_type value 'R',

Knowledge base category type uj_dim_type value 'C',


datasrc type uj_dim_type value 'D',
intco type uj_dim_type value 'I',
Meet the team
subtables type uj_dim_type value 'S',
user type uj_dim_type value 'U',
Join us
group type uj_dim_type value 'G',

About us end of uj00_cs_dim_type.

Suppose the attributes account type and account group are needed. The list of attributes for
Take the Analytics & AI Maturity Survey
a dimension is fetched using the function get_attr_list. The actual members are fetched via
function read_mbr_data.
Contact us
"Get attribute AccountType / Account Group

   lo_account->get_attr_list( IMPORTING et_attr_list = lt_attr_list ). EN NL FR


LOOP AT lt_attr_list INTO ls_attr_list
WHERE attribute_name = ujr0_c_attr_acctype OR
attribute_name = c_attr_group.
APPEND ls_attr_list-attribute_name TO lt_attr_name.
ENDLOOP.
"Get Members of account
CALL METHOD lo_account->read_mbr_data
EXPORTING
if_ret_hashtab = abap_true
it_attr_list = lt_attr_name "columns:attributes name list
* it_hier_list = lt_hier_name "columns:hieracies name list
IMPORTING
er_data = lr_data.
ASSIGN lr_data->* TO
.

Figure 8: Contents of LT_ACCOUNT_MBR

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 3/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

click to enlarge

The internal table ct_array is a generated object that contains all the records coming from
the BPC application. Looping over this table ct_array gives access to each record.

LOOP AT ct_array INTO


.

During the rst loop several objects are created that will capture the new, calculated
records. Object lt_tab
is a temporary object that is created at runtime with the same structure as ct_array. Then the
structure of lt_tab is assigned to the eld-symbols so the latter has a structure and it is a
table. To be able to work with one line of the table, the eld-symbols is created similarly. A
eld-symbols can be assigned to the individual eld of one line using the ASSIGN
Search COMPONENT 
statement. Eg, the column account can then be accessed via .
CONTACT 
Competences
IF

Customers IS NOT ASSIGNED.


CREATE DATA lt_tab LIKE ct_array.
News ASSIGN lt_tab->* TO
.
Academy CREATE DATA lr_data_r LIKE LINE OF ct_array.
ASSIGN lr_data_r->* TO
Events .
ASSIGN COMPONENT ls_account-dimension OF
Knowledge base STRUCTURE
TO
Meet the team . "account
ENDIF.
Join us
Next we search the internal table containing the account member data for the current
About us account and its attributes. These attributes are saved into the eld-symbols and
.

"get account members


Take the Analytics & AI Maturity Survey
READ TABLE
WITH TABLE KEY (ujr0_c_member_id) =
Contact us
ASSIGNING
   . EN NL FR
IF sy-subrc = 0.
ASSIGN COMPONENT c_attr_acctype OF
STRUCTURE
TO
.
ASSIGN COMPONENT c_attr_group OF
STRUCTURE
TO
.

Now all elds are accessible via their corresponding eld-symbols. All kinds of calculations
and manipulations can be executed using these eld-symbols.

Access Existing Data


When new data is sent from BPC towards the BW InfoCube in the backend, sometimes we
need to have access to the data that already exists in the BW InfoCube. Data disaggregation
is a perfect example for this. In BPC data can be entered at parent level and then this data
can be distributed across its children prorated to the existing data. This makes most sense
for dimensions like entity and time.

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 4/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

The following code retrieves the hierarchy information for entity and is also repeated for the
time component.

lo_entity->get_hier_list( IMPORTING et_hier_info = lt_hier_info ).


LOOP AT lt_hier_info INTO ls_hier_info.
APPEND ls_hier_info-hier_name TO lt_hier_name.
ENDLOOP.

Data is disaggregated pro rata to existing data. So we need to look up the existing data that
corresponds to the data coming from the BPC application. This is achieved by launching a
RSDRI query, which requires a list of dimensions to be returned and the list of lters to be
applied. First step is to retrieve the cube metadata.

CLEAR ls_application.
lo_appl_mgr->get(
EXPORTING
if_with_measures = abap_false
if_summary = abap_false
IMPORTING
CONTACT 
es_application = ls_application ).

If the processed line is a parent, we need to get its children to be able to distribute the data
across the children afterwards. This code has to be repeated for the time dimension.

CALL METHOD lo_entity->get_children_mbr


EXPORTING
i_parent_mbr =

i_level = -1
if_only_base_mbr = abap_true
IMPORTING
et_member = lt_ent_children.
DESCRIBE TABLE lt_ent_children LINES nr_ent_chil.

We prepare a range to lter on entity base members. The same range has to be expanded
for the time dimension.

LOOP AT lt_ent_children INTO ls_base_en.


ls_range-dimension = 'COMPANY'.
ls_range-low = ls_base_en.
APPEND ls_range TO lt_range.
ENDLOOP.

We save the cube dimensions in a list and expand the range to use the same restrictions as
in BPC.

REFRESH lt_dim_list.
LOOP AT ls_application-dimensions INTO ls_dimensions.
APPEND ls_dimensions-dimension TO lt_dim_list.
ls_range-dimension = ls_dimensions-dimension.
ASSIGN COMPONENT ls_dimensions-dimension
OF STRUCTURE
TO
.
ls_range-low =
.
APPEND ls_range TO lt_range.
ENDLOOP.

We build a structure to capture the result of the RSDRI query

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 5/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

lo_appl_mgr->create_data_ref(
EXPORTING
i_data_type = 'T'
it_dim_name = lt_dim_list
if_tech_name = abap_false
if_signeddata = abap_true
IMPORTING
er_data = lr_data ).
ASSIGN lr_data->* TO
.

Now we can execute the RSDRI query which retrieves the required date from the SAP BW
InfoCube and stores it in eld symbols

TRY.
lo_query = cl_ujo_query_factory=>get_query_adapter(
i_appset_id = lv_environment_id
i_appl_id = lv_application_id ).
lo_query->run_rsdri_query(
EXPORTING
it_dim_name = lt_dim_list
it_range = lt_range
if_check_security = abap_false
IMPORTING
et_data =
et_message = lt_message
).
CATCH cx_ujo_read.
ENDTRY.

Test your application


In order to debug the ABAP coding, set an external breakpoint and (un)post a test journal.
Select the line of code where you would like to start debugging and hit the red button Set /
Delete external breakpoint (Ctrl+Shift+F9) in the toolbar. Note that an icon appears in front of
the selected line. Now you can (un)post a test journal, using the same SAP user and you
should enter the debugger. Now you execute the code step by step and check the content
of all elds.

Figure 9: Debugging in Class Builder

click to enlarge

Conclusion
SAP BPC Netweaver can make use of ABAP, the SAP programming language. BAdI is an
enhancement to the standard version of the code of SAP. The performance of BAdIs is
signi cant better than SAP BPC script. These functionalities enable endless possibilities.

Annex
This annex contains the ABAP declarations for all elds contained in this insight.

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 6/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

DATA:
ls_record_r TYPE REF TO data,
lt_attr_list TYPE uja_t_attr, "Attributes info
ls_attr_list TYPE uja_s_attr,
lt_attr_name TYPE uja_t_attr_name, "Attribute names
lr_data TYPE REF TO data,
lt_tab TYPE REF TO data,
ls_account TYPE ujr_s_dim_handler, "account
lo_account TYPE REF TO if_uja_dim_data.

FIELD-SYMBOLS:

TYPE ujr_s_dim_handler,

TYPE HASHED TABLE, "All account members

TYPE any,

TYPE uj_dim_member, "account member of current rec

TYPE any, "account group

TYPE any, "account type

TYPE table, "result itab

TYPE any, "result


record

TYPE
uj_dim_member,"account member of result rec

TYPE any, "attr GROUP of result record

Friday, March 20, 2015

Topic

CPM - Consolidation & Reporting


CPM - Planning & Budgeting

Technology

SAP Business Analytics

Competence

Corporate Performance Management

Financial Reporting & Consolidation Practice

CONTACT US 

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 7/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

JOIN US 

Complete our Analytics & AI Maturity Survey

And get a free benchmark of your organisation vs. the market.

LEARN MORE

ELEMENTARY

BI-KIPEDIA
6
JOIN US

TEAM

CONTACT US

OUR COMPETENCES

Business Intelligence

Business Analytics Advisory


Business Intelligence
Data Warehousing
Data Integration
Data Quality
Master Data Management

Performance Management

Consolidation
Financial Reporting
Financial Planning & Analysis
Sales & Operations Planning
Disclosure Management
Conso Outsourcing & Interim

Data Science & Strategy

Data Strategy
Data Science
Advanced Analytics
Big Data
Data Management Platform
Customer Data Platform

Technologies

Microsoft Data Platform


SAP Business Analytics

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 8/9
4/22/2020 Implementing BAdI’s for SAP BPC - Tips & Tricks | element61

IBM Business Analytics


CCH Tagetik
Qlik
Vena
Sigma Conso
Databricks
Mindbridge

element61 © 2007-2020 - Disclaimer - Privacy

https://www.element61.be/en/resource/implementing-badis-sap-bpc-tips-tricks 9/9

You might also like