You are on page 1of 4

23.10.

13

ABAP Code (BPC 10 NW) to read an application's ... | SCN


Getting Started New sletters

Welcome, Guest

Login

Store

Search the Community

Register

Products

Services & Support

About SCN

Downloads

Industries

Training & Education

Partnership

Developer Center

Lines of Business

University Alliances

Events & Webinars

Innovation

ABAP Code (BPC 10 NW) to read an


application's transaction data within the
BAdI

Activity

Communications

Actions

Brow se

Version 1

created by Rajesh Balakrishnan on Jan 14, 2013 7:27 PM, last modified by Rajesh Balakrishnan on Jan 14, 2013 7:55 PM
Share

Tw eet

Like

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_BADIEND_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 numb er of dimensions as in the
scope ,In this example it has 12 fields given b elow:

TYPES : begin of ty_ctdata,

scn.sap.com/docs/DOC-35054

account_p
audittrail
flow
legal_entity
measures
plant
product
profit_center
rptcurrency

type c length 32,


type c length 32,
type c length 32,
type c length 32,
type c length 32,
type c length 32,
type c length 32,
type c length 32,
type c length 32,

1/4

23.10.13

ABAP Code (BPC 10 NW) to read an application's ... | SCN


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 ob ject 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 ob ject 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 ,Attrib ute, 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 ' .
A. 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 ' **

scn.sap.com/docs/DOC-35054

2/4

23.10.13

ABAP Code (BPC 10 NW) to read an application's ... | SCN


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
IMPORTING
et_data

" BPC: Generic indicator

= <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.

3228 View s

Average User Rating


(1 rating)

Share

Tw eet

Like

1 Comment

scn.sap.com/docs/DOC-35054

3/4

23.10.13

ABAP Code (BPC 10 NW) to read an application's ... | SCN


Ariel Linetzky Jun 24, 2013 7:38 PM

Dear Rajesh
I would like to regards your ABAP code, i implemented it and worked
I'm quite new on this but i want tou know if you could help me with some thing
1.- How can include information at other model, example OWNERSHIP, to do some special
calculations
2.- How can I include Master Data information from dimensin to extract the entity intercomany and
group currency
3.- Witch part of eh code line i have to include my code to do the calculation
For example in this part:

loop at <lt_tx_data> into wa_ctd_int .


append wa_ctd_int to it_ctd_int .
ENDLOOP.
Thanks in advance
Regards
Ariel
Like (0)

Site Index
Privacy

Contact Us
Terms of Use

scn.sap.com/docs/DOC-35054

SAP Help Portal


Legal Disclosure

Copyright

Follow SCN

4/4