Financial Management Blogs by Members
Dive into a treasure trove of SAP financial management wisdom shared by a vibrant community of bloggers. Submit a blog post of your own to share knowledge.
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

This is an updated version of Code Snippet #3 which had been posted by Pankaj Patil in his excellent post pertaining to useful ABAP Codes for BPC 7.x which can be found here : http://scn.sap.com/docs/DOC-28777

The below mentioned code will apply only to BPC 10, and for prior versions of BPC, the link posted above should be referred.

As mentioned by Pankaj in his post, the gist of what the below mentioned code will achieve is as follows:

To save the extra time overhead in read of application data whenever QUERY is set to ON in START_BADI... END_BADI construct, this parameter can be set to OFF and an equivalent ABAP logic can then fetch the application data. This way the code executes much faster.

To elaborate, in a START_BADI…END_BADI syntax, we generally keep QUERY=ON and WRITE = ON.

eg.

*START_BADI (insert filter name here)

QUERY=ON

WRITE=ON

*END_BADI

QUERY = ON helps to populate the CT_DATA table so that the logic can be executed on the records populated as per the scope file. However, the ABAP code below helps fetch the data records directly into ct_data [] in the BAdI itself. Since the BAdI fetches the data records, we can keep QUERY = OFF, and save the time involved in querying data from BPC. The LGF file will now look this:

*START_BADI (insert filter name here)

QUERY=OFF

WRITE=ON

*END_BADI

** 1. **--------- Data Declarations -------**

DATA: lt_sel TYPE uj0_t_sel, "Selection criteria table

      ls_sel TYPE uj0_s_sel,

      ls_cv TYPE ujk_s_cv,      " Logic Current View

      lt_dim_member TYPE UJA_T_DIM_MEMBER ,

      ls_dim_member LIKE LINE OF lt_dim_member ,

      lo_appl TYPE REF TO cl_uja_application,

      lt_appl_dim TYPE uja_t_appl_dim,

      ls_appl_dim LIKE LINE OF lt_appl_dim,

      lt_dim_name TYPE ujq_t_dim,

      ls_dim_name LIKE LINE OF lt_dim_name,

      lo_model TYPE REF TO if_uj_model,

      lo_dataref TYPE REF TO data,

      lo_query TYPE REF TO if_ujo_query ,

      lt_message TYPE uj0_t_message .

FIELD-SYMBOLS: <lt_tx_data> TYPE STANDARD TABLE.

*Declare the dimensions  of ct_data which should have same number  of dimensions as  in  the scope  ,In this example it has 12 fields given below:

TYPES : begin of ty_ctdata,

                                     account_p      type c length 32,

       audittrail     type c length 32,

*      flow           type c length 32,

       legal_entity   type c length 32,

       measures       type c length 32,

                                     plant          type c length 32,

                                     product        type c length 32,

                                     profit_center  type c length 32,

                                     rptcurrency    type c length 32,

       time           type c length 32,

version type c length 32,

zones type c length 32,

             signeddata     type /b28/oisdata ,"(11) type p decimals 7,

end of ty_ctdata.

DATA :   it_ctd_int         type standard table of ty_ctdata , " Initial temporary table.

          wa_ctd_int         type ty_ctdata .

**---------------End of Data Declaration----------------------**

*---- 2. Create an object  for  the input parameters such i_appset_id,  i_appl_id.-------*

CREATE OBJECT lo_appl
EXPORTING
i_appset_id     
= i_appset_id
i_application_id
= i_appl_id.

*---- 3. Use this object to read the dimension for the  i_appl_id  & Append ' Measures ' to the dimension table -----*

                                     REFRESH lt_appl_dim.

lo_appl->get_appl_dim(
EXPORTING
i_appl_id  
= i_appl_id
IMPORTING
et_appl_dim
= lt_appl_dim ).”Dimension table

                                     REFRESH lt_dim_name.

**Populate dimension table '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.
CLEAR ls_dim_name.
ENDLOOP.
* Include ' Measures ' as dimension table *

ls_dim_name  = 'MEASURES'.
APPEND ls_dim_name TO lt_dim_name.

SORT lt_dim_name.

*--4. Prepare Selection range table say for ex :  'lt_sel '  for each dimension passing values to fields Dimension ,Attribute, Option ,Sign , low ----*.


loop at  lt_dim_name INTO ls_dim_name  .
CLEAR : ls_cv .
* Read from scope for each dimension from current view table*
READ TABLE it_cv INTO ls_cv WITH KEY dimension ls_dim_name .
IF sy-subrc = 0.
LOOP AT ls_cv-member into ls_dim_member.
ls_sel
-dimension = ls_cv-dimension.
ls_sel
-attribute = 'ID'.
ls_sel
-sign = 'I'.
ls_sel
-option = 'EQ'.
ls_sel
-low = ls_dim_member.
APPEND ls_sel TO lt_sel.
CLEAR ls_dim_member.
ENDLOOP.
CLEAR lt_dim_member.
ENDIF.
ENDLOOP.

      *---5. Create a reference structure similar to ct_data using the method -----*

create_tx_data_ref  '  .

  1. TRY.
    lo_model
    = cl_uj_model=>get_model( i_appset_id ).
    lo_model
    ->create_tx_data_ref(
    EXPORTING
    i_appl_name 
    = i_appl_id
    i_type      
    = 'T'
    it_dim_name 
    = lt_dim_name
    if_tech_name
    = space
    IMPORTING
    er_data     
    = lo_dataref ).
    CATCH cx_uj_static_check.
    ENDTRY.
    * Assigning the structure to table
    ASSIGN lo_dataref->* TO <lt_tx_data>.

**Run  a query using method  run_rsdri_query ' **

TRY.

lo_query
= cl_ujo_query_factory=>get_query_adapter(
i_appset_id
= i_appset_id
i_appl_id  
= i_appl_id
).
** Run Query to populate ct_data based on dimensions , selection criteria **.

lo_query
->run_rsdri_query(

EXPORTING
it_dim_name      
lt_dim_name " BPC: Dimension List
it_range         
=   lt_sel     " BPC: Selection condition
if_check_security
= ABAP_FALSE   " BPC: Generic indicator

IMPORTING
et_data          
= <lt_tx_data>
et_message       
= lt_message    " BPC: Messages
).

CATCH cx_ujo_read" Exception of common read

ENDTRY.

*Move the Queried data into initial temp table.
loop at <lt_tx_data> into wa_ctd_int .
append wa_ctd_int to it_ctd_int .
ENDLOOP.
clear :wa_ctd_int , <lt_tx_data>.


*-- 6.  Copy data into ct_data ----*


REFRESH CT_DATA.

* !!Ensure the scope file has a 'MEASURES" dimension!!!*
* for data to get correctly copied into ct_data  *

ct_data[]
= it_ctd_int[] .
CLEAR  it_ctd_int[]

*---------------------------------------------------------------------------------------------------------------------------------------*

Things to Remember:

  • Ensure that your scope file also includes the MEASURES dimension. eg. *XDIM_MEMBERSET MEASURES = PERIODIC.

        Without this, the two internal tables end up being incompatible and we get a dump.

  • The CT_DATA fails to populate for some reasion if the CURRENCY dimension is scoped as <ALL>. We were forced to individually specify every currency in our Scope file as *XDIM_MEMBERSET RPTCURRENCY = INR,USD,GBP,EUR (If any of the experts here can explain the reason for the same, it would be very helpful)


  • The code pasted above can be used in any BPC 10 implementation but it might need slight modifications from project to project (eg. list of dimensions etc)

We request all BPC experts to pitch in and correct us or help us improve our code, if a possibility to do so exists.

Hope this is helpful to everyone.


5 Comments
Top kudoed authors