100% found this document useful (1 vote)
3K views

BPC Sample Code - 2

This document contains code for a custom logic method in SAP Business Planning and Consolidation (BPC) that copies a profit and loss account to the main version. It gets the category and year for the specified version parameter. It then gets time-based members between the version's start and end dates. Finally, it runs a query to retrieve cost data from transactions for specific dimension values and copies it to the main version.

Uploaded by

satyajoshi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
3K views

BPC Sample Code - 2

This document contains code for a custom logic method in SAP Business Planning and Consolidation (BPC) that copies a profit and loss account to the main version. It gets the category and year for the specified version parameter. It then gets time-based members between the version's start and end dates. Finally, it runs a query to retrieve cost data from transactions for specific dimension values and copies it to the main version.

Uploaded by

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

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

*& Method
: IF_UJ_CUSTOM_LOGIC~EXECUTE
*& Application : Retail
*&--------------------------------------------------------------------*
*& Details:
*& Copy P&L account to main version
*&--------------------------------------------------------------------*
* MODIFICATION HISTORY LOG:
* Date
Programmer
Description
TR
*---------------------------------------------------------------------*
*---------------------------------------------------------------------*
METHOD if_uj_custom_logic~execute.
DATA:
lo_appset
lo_application
lo_gentab

TYPE REF TO cl_uja_appset,


TYPE REF TO if_uja_application_manager,
TYPE REF TO cl_uj_gen_table, " Singleton instance

ls_appset_info
ls_application
ls_prefix

TYPE uja_s_appset_info,
TYPE uja_s_application,
TYPE uja_s_prefix,

lv_tab_name
lv_gotstate

TYPE tabname,
TYPE ddgotstate,

lo_ref_table_descr
lo_ref_table_type

TYPE REF TO cl_abap_structdescr,


TYPE REF TO cl_abap_tabledescr,

lo_ref_itab

TYPE REF TO data,

lo_context
ls_user_original
ls_user
ls_status
lo_write_back

TYPE
TYPE
TYPE
TYPE
TYPE

REF TO if_uj_context,
uj0_s_user,
uj0_s_user,
ujo_s_wb_status,
REF TO cl_ujo_write_back,

"Variables used to return messages to the log file.


ls_param
TYPE ujk_s_script_logic_hashentry,
lv_log
TYPE string,
lo_cx_uj_static_check TYPE REF TO cx_uj_static_check,
lo_cx_uj_obj_not_found TYPE REF TO cx_uj_obj_not_found,
lo_cx_uja_admin_error TYPE REF TO cx_uja_admin_error,
lo_cx_uja_md_error
TYPE REF TO cx_uja_md_error,
lo_query
TYPE REF TO if_ujo_query,
lo_dim
lv_dim
lo_hier
lv_flg

TYPE
TYPE
TYPE
TYPE

REF TO if_uja_dim_data,
uj_dim_name, "member
REF TO if_uja_hier,
uj_flg,

lt_message

TYPE uj0_t_message,

lr_data
lv_errors
lv_model

TYPE REF TO data,


TYPE REF TO data,
TYPE REF TO if_uj_model,

lo_dataref
lo_model

TYPE REF TO data,


TYPE REF TO if_uj_model,

lo_appl

TYPE REF TO cl_uja_application,

lt_appl_dim
ls_appl_dim

TYPE uja_t_appl_dim,
LIKE LINE OF lt_appl_dim,

lt_dim_name
ls_dim_name

TYPE ujq_t_dim,
LIKE LINE OF lt_dim_name,

lt_selection
ls_sel

TYPE uj0_t_sel,
LIKE LINE OF lt_selection,

lt_attr_list
ls_attr_list

TYPE uja_t_attr_name,
LIKE LINE OF lt_attr_list,

lt_dim_list
ls_member
lt_slicer

TYPE uja_t_dim_list,
TYPE ujo_s_member,
TYPE ujo_t_members.

FIELD-SYMBOLS:
"Table and reference to the data. Temporary storage of data.
<lt_rate>
TYPE STANDARD TABLE,
<ls_rate>
TYPE any,
<lt_output>
TYPE STANDARD TABLE,
<ls_output>
TYPE any,
<lt_errors>
TYPE STANDARD TABLE,
<ls_wa>
TYPE any,
<lt_query_result>
TYPE STANDARD TABLE,
<lt_cat_md>
<ls_cat_md>
<lt_time_md>
<ls_time_md>

TYPE
TYPE
TYPE
TYPE

STANDARD TABLE,
any,
STANDARD TABLE,
any,

<fs_version_start_date> TYPE any,


<fs_version_end_date> TYPE any,
"Field Symbols for dimension members.
<ld_measures>
TYPE uj_dim_member,
<ld_time_out>
<ld_time>

TYPE uj_dim_member,
TYPE uj_dim_member,

<ld_datasrc_out>
<ld_account_out>
<ld_region_out>
<ld_market_segment_out>

TYPE
TYPE
TYPE
TYPE

<ld_signeddata_out>
<ld_signeddata_cost>
<ld_signeddata_rate>

TYPE p,
TYPE p,
TYPE p,

<ld_year>
<ld_pc_type>
<ld_id>

TYPE any,
TYPE any,
TYPE uj_dim_member.

CONSTANTS:
"Dimensions
lc_measures
lc_signeddata
lc_time

uj_dim_member,
uj_dim_member,
uj_dim_member,
uj_dim_member,

TYPE uj_dim_name VALUE 'MEASURES',


TYPE uj_dim_name VALUE 'SIGNEDDATA',
TYPE uj_dim_name VALUE 'TIME',

lc_account
lc_datasrc
lc_green_scheme
lc_region
lc_version
lc_market_segment
lc_currency
lc_erm_entity
" Hierarchy Node name
lc_skf_group
lc_x(1)
lc_ci(3)
lc_sme(3)
lc_aud(3)
lc_calc(4)
lc_1013(4)
lc_s0131(5)
lc_input(5)
lc_no_gs(5)
lc_no_ms(5)
lc_no_rg(5)
lc_upload(6)
lc_input_inp(9)
lc_800000(6)
lc_total(5)
DATA:
lt_cat_md
lt_time_md

TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

uj_dim_name
uj_dim_name
uj_dim_name
uj_dim_name
uj_dim_name
uj_dim_name
uj_dim_name
uj_dim_name

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'ACCOUNT',
'DATASRC',
'GREEN_SCHEME',
'REGION',
'VERSION',
'MARKET_SEGMENT',
'CURRENCY',
'ERM_ENTITY',

TYPE uj_dim_member VALUE 'SKF_GROUP',


TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE
TYPE

c
c
c
c
c
c
c
c
c
c
c
c
c
c
c

VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE
VALUE

'X',
'C&I',
'SME',
'AUD',
'CALC',
'1013',
'S0131',
'INPUT',
'NO_GS',
'NO_MS',
'NO_RG',
'UPLOAD',
'INPUT_INP',
'800000',
'TOTAL'.

TYPE REF TO data, "master data


TYPE REF TO data, "master data

ls_account(32)
lt_account

TYPE c,
LIKE STANDARD TABLE OF ls_account,

lv_category(8)
lv_cond
lv_msg

TYPE c,
TYPE string,
TYPE string,

lv_year
lv_total_rom(16)
lv_total_cost(16)

TYPE i,
TYPE p DECIMALS 10,
TYPE p DECIMALS 10.

"Write message to log.


cl_ujk_logger=>log( i_object = '' ).
*------------------------------------------------------------------* PARAMTERS
* Get paramters from the BPC script logic.
*------------------------------------------------------------------CLEAR ls_param.
READ TABLE it_param WITH KEY hashkey = 'VERSION' INTO ls_param.
IF sy-subrc NE 0.
lv_log = 'You have not specified the parameter ''VERSION'' which is required
.'.
cl_ujk_logger=>log( i_object = lv_log ).
RAISE EXCEPTION TYPE cx_uj_custom_logic.
EXIT.
ENDIF.

lv_category = ls_param-hashvalue.

"Main version

*------------------------------------------------------------------* Get Category - year property members


*------------------------------------------------------------------REFRESH: lt_attr_list,
lt_selection.
lo_model = cl_uj_model=>get_model( i_appset_id ).
lo_dim = lo_model->get_dim_data( i_dim_name = lc_version ).
CLEAR ls_sel.
ls_sel-dimension = lc_version.
ls_sel-attribute = 'ID'.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lv_category.
APPEND ls_sel TO lt_selection.
TRY.
CALL METHOD lo_dim->read_mbr_data
EXPORTING
it_sel = lt_selection
if_sort = abap_true
IMPORTING
er_data = lt_cat_md.
ASSIGN lt_cat_md->* TO <lt_cat_md>.
CATCH cx_sy_ref_is_initial.
CATCH cx_uja_admin_error INTO lo_cx_uja_admin_error.
RAISE EXCEPTION TYPE cx_uj_custom_logic
EXPORTING
textid = lo_cx_uja_admin_error->if_t100_message~t100key.
ENDTRY.
READ TABLE <lt_cat_md> ASSIGNING <ls_cat_md> WITH KEY ('ID') = lv_category BIN
ARY SEARCH.
ASSIGN COMPONENT 'START_DATE' OF STRUCTURE <ls_cat_md> TO <fs_version_start_da
te>.
ASSIGN COMPONENT 'END_DATE' OF STRUCTURE <ls_cat_md> TO <fs_version_end_date
>.
IF <fs_version_start_date> IS INITIAL OR <fs_version_end_date> IS INITIAL.
CONCATENATE 'The start/end date for version' lv_category 'is not defined.' I
NTO lv_msg SEPARATED BY ` `.
CALL METHOD cl_ujk_logger=>log
EXPORTING
i_object = lv_msg.
RAISE EXCEPTION TYPE cx_uj_custom_logic.
EXIT.
ENDIF.
*------------------------------------------------------------------* Get Time base members
*------------------------------------------------------------------REFRESH: lt_attr_list,
lt_selection.

lo_model = cl_uj_model=>get_model( i_appset_id ).


lo_dim = lo_model->get_dim_data( i_dim_name = lc_time ).
CLEAR ls_sel.
ls_sel-dimension = 'TIME'.
ls_sel-attribute = 'ID'.
ls_sel-sign = 'I'.
ls_sel-option = 'BT'.
ls_sel-low = <fs_version_start_date>.
ls_sel-high = <fs_version_end_date>.
APPEND ls_sel TO lt_selection.
CLEAR ls_sel.
ls_sel-dimension = 'TIME'.
ls_sel-attribute = 'CALC'.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = 'N'.
APPEND ls_sel TO lt_selection.
TRY.
CALL METHOD
EXPORTING
it_sel
if_sort
IMPORTING
er_data

lo_dim->read_mbr_data
= lt_selection
= abap_true
= lt_time_md.

ASSIGN lt_time_md->* TO <lt_time_md>.


CATCH cx_sy_ref_is_initial.
CATCH cx_uja_admin_error INTO lo_cx_uja_admin_error.
RAISE EXCEPTION TYPE cx_uj_custom_logic
EXPORTING
textid = lo_cx_uja_admin_error->if_t100_message~t100key.
ENDTRY.
*------------------------------------------------------------------* Prepare variables for reading Transaction DATA
*------------------------------------------------------------------* Get applications dimensions
CREATE OBJECT lo_appl
EXPORTING
i_appset_id
= i_appset_id
i_application_id = i_appl_id.
REFRESH lt_appl_dim.
lo_appl->get_appl_dim(
EXPORTING
i_appl_id = i_appl_id
IMPORTING
et_appl_dim = lt_appl_dim ).
* populate internal table for SQE call
REFRESH lt_dim_name.

LOOP AT lt_appl_dim INTO ls_appl_dim.


ls_dim_name = ls_appl_dim-dimension.
APPEND ls_dim_name TO lt_dim_name.
ENDLOOP.
TRY.

CALL METHOD cl_ujk_model=>get_structure


EXPORTING
i_appset_id
= i_appset_id
i_appl_id
= i_appl_id
i_type
= 'T'
if_with_measure
= abap_true
IF_WITH_SIGNEDDATA = ABAP_TRUE
RECEIVING
rr_data
= lo_dataref.
ASSIGN lo_dataref->* TO <lt_query_result>.
CATCH cx_uj_static_check.
ENDTRY.

*------------------------------------------------------------------* GET COST DATA


*------------------------------------------------------------------REFRESH lt_selection.
CLEAR ls_sel.
ls_sel-dimension = lc_account.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lc_s0131.
APPEND ls_sel TO lt_selection.
CLEAR ls_sel.
ls_sel-dimension = lc_datasrc.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lc_input.
APPEND ls_sel TO lt_selection.
CLEAR ls_sel.
ls_sel-dimension = lc_currency.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lc_aud.
APPEND ls_sel TO lt_selection.
CLEAR ls_sel.
ls_sel-dimension = lc_market_segment.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lc_no_ms.
APPEND ls_sel TO lt_selection.
CLEAR ls_sel.
ls_sel-dimension = lc_version.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lv_category.

APPEND ls_sel TO lt_selection.


CLEAR ls_sel.
ls_sel-dimension = lc_time.
ls_sel-sign = 'I'.
ls_sel-option = 'EQ'.
ls_sel-low = lc_input_inp.
APPEND ls_sel TO lt_selection.
TRY.
lo_query = cl_ujo_query_factory=>get_query_adapter(
i_appset_id = i_appset_id
i_appl_id = i_appl_id
).
lo_query->run_rsdri_query(
EXPORTING
it_dim_name
= lt_dim_name
" BPC: Dimension List
it_range
= lt_selection
" BPC: Selection condition
if_check_security = abap_false
" BPC: Generic indicator
IMPORTING
et_data
= <lt_query_result>
).
CATCH cx_ujo_read.
ENDTRY.

" Exception of common read

* Create work area for importing data


CREATE DATA lr_data LIKE LINE OF ct_data.
ASSIGN lr_data->* TO <ls_rate>.
* Create tables.
CREATE DATA lr_data LIKE STANDARD TABLE OF <ls_rate> WITH DEFAULT KEY.
ASSIGN lr_data->* TO <lt_rate>.
* Store global data into hash table
LOOP AT <lt_query_result> ASSIGNING <ls_wa>.
<ls_rate> = <ls_wa>.
COLLECT <ls_rate> INTO <lt_rate>.
ENDLOOP.
REFRESH <lt_query_result>.
*------------------------------------------------------------------* Calculate Total
*------------------------------------------------------------------* Create work area for importing data
CREATE DATA lr_data LIKE LINE OF ct_data.
ASSIGN lr_data->* TO <ls_output>.
ASSIGN COMPONENT
t>.
ASSIGN COMPONENT
t>.
ASSIGN COMPONENT
>.
ASSIGN COMPONENT
ment_out>.

lc_datasrc

OF STRUCTURE <ls_output> TO <ld_datasrc_ou

lc_account

OF STRUCTURE <ls_output> TO <ld_account_ou

lc_region

OF STRUCTURE <ls_output> TO <ld_region_out

lc_market_segment OF STRUCTURE <ls_output> TO <ld_market_seg

ASSIGN COMPONENT lc_signeddata


_out>.

OF STRUCTURE <ls_output> TO <ld_signeddata

READ TABLE <lt_rate> ASSIGNING <ls_rate> INDEX 1.


ASSIGN COMPONENT lc_signeddata OF STRUCTURE <ls_rate> TO <ld_signeddata_rate>.
LOOP AT <lt_query_result> ASSIGNING <ls_wa>.
<ls_output> = <ls_wa>.
ASSIGN COMPONENT lc_signeddata
_cost>.

OF STRUCTURE <ls_wa> TO <ld_signeddata

<ld_account_out>
= lc_800000.
<ld_datasrc_out>
= lc_calc.
<ld_region_out>
= lc_no_rg.
<ld_market_segment_out> = lc_no_ms.
<ld_signeddata_out> = <ld_signeddata_cost> * <ld_signeddata_rate> * -1.
COLLECT <ls_output> INTO ct_data.
ENDLOOP.
"Write message to log.
cl_ujk_logger=>log( i_object = 'Apply Rates: COMPLETED' ).
cl_ujk_logger=>log( i_object = '' ).

ENDMETHOD.

You might also like