cancel
Showing results for 
Search instead for 
Did you mean: 

Generic Datasource using RUN_RSDRI_QUERY

Former Member
0 Kudos

I want to write a function module to extract data from BPC to BW using a generic datasource.  I want to data package the records for when there are large volumes of data.  The first time the code executes, 100 records are returned.  The second call fails with a runtime error in method RUN_RSDRI_QUERY on the statement "assert lo_query_engine is not initial."  I am not an ABAP expert so I am stuck on why my code is failing.  If I comment out the "i_packagesize = l_pack", all the BPC data is returned but I am nervous that this code will not work with large volumes of data.  Can anyone provide help on how I can package the data?

Thanks.

field-symbols: <lt_data> type standard table

* First data package
     IF s_counter_datapakid = 0.


*populating selection table
       LOOP AT s_s_if-t_select INTO l_s_select WHERE fieldnm = 'VERSION'.
         wa_sel-dimension = l_s_select-fieldnm.
         wa_sel-attribute = 'VERSION'.
         wa_sel-sign = l_s_select-sign.
         wa_sel-option = l_s_select-option.
         wa_sel-low = l_s_select-low.
         APPEND wa_sel TO it_sel.
       ENDLOOP.

*populating dimension table
       LOOP AT i_t_fields.
         IF i_t_fields-fieldnm <> 'SIGNDATA'.
           ls_dim_name = i_t_fields-fieldnm.
           APPEND ls_dim_name TO lt_dim_name.
         ENDIF.
       ENDLOOP.
       l_pack = i_maxsize.
       l_start = 'X'.
     ENDIF.

     IF l_end NE 'X'.  
 
     try.
         lo_appl_mgr = cl_uja_bpc_admin_factory=>get_application_manager( i_appset_id = lv_appset_id
                                                                          i_application_id = lv_application_id ).
 
         call method lo_appl_mgr->create_data_ref
           exporting
             i_data_type  = 'T'
             it_dim_name  = lt_dim_name
             if_tech_name = space
           importing
             er_data      = lo_dataref.
       catch cx_uja_admin_error
             cx_uj_no_auth
             cx_uj_static_check.                         "#EC NO_HANDLER
     endtry.

     assign lo_dataref->* to <lt_data>.
     lo_query = cl_ujo_query_factory=>get_query_adapter( i_appset_id = lv_appset_id
                                                         i_appl_id   = lv_application_id ).


     try.

         lo_query = cl_ujo_query_factory=>get_query_adapter( i_appset_id = lv_appset_id
                                                             i_appl_id   = lv_application_id ).
         call method lo_query->run_rsdri_query
           exporting
             it_dim_name       = lt_dim_name
              it_range          = it_sel
             if_check_security = abap_false
            i_packagesize     = l_pack          "all data is returned if I comment out this line
            importing
             et_data           = <lt_data>
             e_end_of_data     = l_end
           changing
            c_first_call       = l_start.


       catch cx_ujo_read.
         message text-011 type 'I'.
         return.
     endtry.
        APPEND LINES OF <lt_data> TO e_t_data.
       s_counter_datapakid = s_counter_datapakid + 1.

     ELSE.
       RAISE no_more_data.

     ENDIF.

   ENDIF.     

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hello Sandy ,

Export data source is good mechanism. but to solve your assert lo_query_engine is not initial

from second read onwards you just need the call to run_rsdri_query.

The function module z_bw_bpc2_read_model_in_pkt   in the packet size you want to similar to genereic extractor

===============================================================

Global Data for the function module

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,

                 <ls_tx_data> type any.

  data: lr_tab_ctdata  type ref to data.

  data: lr_row_ctdata  type ref to data.

  data: lr_row_tx_data type ref to data.

  field-symbols: <l_tab_ctdata> type standard table, "CT_DATA

                 <l_row_ctdata> type any .           "Line of CT_DATA

  data: r_cx_uj_static_check type ref to cx_uj_static_check.

  data: w_cx_uj_static_check type string.                   "#EC NEEDED

  data: r_cx_ujo_read        type ref to cx_ujo_read.

  data: w_cx_ujo_read        type string.

===============================================================

Function module

function z_bw_bpc2_read_model_in_pkt.

*"----------------------------------------------------------------------

*"*"Local Interface:

*"  IMPORTING

*"     VALUE(I_APPSET_ID) TYPE  UJ_APPSET_ID

*"     VALUE(I_APPL_ID) TYPE  UJ_APPL_ID

*"     VALUE(I_PACKAGE_SIZE) TYPE  INT4

*"  CHANGING

*"     VALUE(IT_CV) TYPE  UJK_T_CV

*"     VALUE(IT_PARAM) TYPE  UJK_T_SCRIPT_LOGIC_HASHTABLE

*"     VALUE(ET_MESSAGE) TYPE  UJ0_T_MESSAGE OPTIONAL

*"     VALUE(CT_DATA) TYPE  STANDARD TABLE OPTIONAL

*"     VALUE(LF_END) TYPE  UJ_FLG

*"     VALUE(LF_FIRST_QUERY) TYPE  UJ_FLG

*"----------------------------------------------------------------------

* Date:  7/11/2015                                                     *

* Author: Ramana Inguva                                                *

* Title:  Custom function to read a BPC2 Model                         *

*

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

* Description: Custom function to read a BPC model                     *

*                                                                      *

* This function module is called from Z_BW_IO_PLAN and Z_BW_WBS_PLAN   *

* This function module calls run_rsdri_query method of standard        *

* sap object

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

* Change History:                                                      *

* Author           Date       Request #   Description                  *

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

* Ramana Inguva  7/11/2015                Initial development          *

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

  if  lf_first_query = abap_true.

    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.

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

    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 into r_cx_uj_static_check.

        w_cx_uj_static_check =

           r_cx_uj_static_check->get_text( ).

        cl_ujk_logger=>log( w_cx_uj_static_check ).

    endtry.

* Assigning the structure to table

    assign lo_dataref->* to <lt_tx_data>.

    create data lr_row_tx_data like line of <lt_tx_data>.

    assign lr_row_tx_data->* to <ls_tx_data>.

**Run  a query using method  '  run_rsdri_query ' **

    refresh: <lt_tx_data>.

    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

        i_packagesize     = i_package_size

        importing

        et_data           = <lt_tx_data>

        et_message        = lt_message    " BPC: Messages

        e_end_of_data     = lf_end

        changing

              c_first_call      = lf_first_query

        ).

      catch cx_ujo_read  into r_cx_ujo_read.

        w_cx_ujo_read  =

           r_cx_ujo_read->get_text( ).

        cl_ujk_logger=>log( w_cx_ujo_read ).

    endtry.

    et_message[] = lt_message[].

    create data lr_tab_ctdata like ct_data.

    assign lr_tab_ctdata->* to <l_tab_ctdata>.

    create data lr_row_ctdata like line of ct_data.

    assign lr_row_ctdata->* to <l_row_ctdata>.

    loop at <lt_tx_data> into  <ls_tx_data>.

      move-corresponding <ls_tx_data> to  <l_row_ctdata>.

      append <l_row_ctdata> to ct_data.

    endloop.

    clear : <lt_tx_data>.

  else.

    refresh: <lt_tx_data>.

    try.

** 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

        i_packagesize     = i_package_size

        importing

        et_data           = <lt_tx_data>

        et_message        = lt_message    " BPC: Messages

        e_end_of_data     = lf_end

        changing

              c_first_call      = lf_first_query

        ).

      catch cx_ujo_read  into r_cx_ujo_read.

        w_cx_ujo_read  =

           r_cx_ujo_read->get_text( ).

        cl_ujk_logger=>log( w_cx_ujo_read ).

    endtry.

    et_message[] = lt_message[].

    loop at <lt_tx_data> into  <ls_tx_data>.

      move-corresponding <ls_tx_data> to  <l_row_ctdata>.

      append <l_row_ctdata> to ct_data.

    endloop.

    clear : <lt_tx_data>.

  endif.

endfunction.

--------------------------------------------

Calling this function module - from a prohram

report z_bw_read_model_head_count.

data: t_cv      type ujk_t_cv,

      t_cv_std  type table of ujk_s_cv,

      t_param   type ujk_t_script_logic_hashtable,

      t_message type uj0_t_message.

data  w_cv           type ujk_s_cv.

data: t_temp_member  type uja_t_dim_member.

data: w_temp_member  type uj_dim_member.

data: p_appset        type uj_appset_id value 'BPC2'.

data: p_appl_id       type uj_appl_id   value 'HR_HEADCOUNT_PLAN'.

data: w_dime_hracct   type uj_dim_name  value 'HRACCT'.

data: i_parent_member type uj_dim_member value 'HR_ACTIONS'.

data: t_hr_headcount_plan_std type zbw_bpc2_hr_headcount_plan_tab,

      t_hr_headcount_plan_all type zbw_bpc2_hr_headcount_plan_tab.

************************************************************

*ZBW_BPC2_HR_HEADCOUNT_PLAN_TAB is table type for *ZBW_BPC2_HR_HEADCOUNT_PLAN_STR

*ZBW_BPC2_HR_HEADCOUNT_PLAN_STR

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

*COSTCENTER Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*CUR Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*DATATAG Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*EMPLOYEE Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*HRACCT Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*HRPOSITION Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*JOB Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*PAYCYCLE Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*RECEIVER_CC Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*RECEIVER_POS Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*SKF Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*TIME Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*VER Types UJ_DIM_MEMBER CHAR 32 0 BPC: Dimension Member

*SIGNEDDATA Types ZBW_BPC2_SIGNDATA DEC 20 7 Signdata

*************************************************************

data: w_end          type uj_flg.

data: w_first_query  type uj_flg.

**********************************************************

** Populate Employee

**********************************************************

*  if not g_employee is initial.

*    move 'EMPLOYEE'     to w_cv-dimension.

*    move 'EMPLOYEE'     to w_cv-dim_upper_case.

*    append g_employee   to w_cv-member.

*    append w_cv         to t_cv_std.

*    refresh: w_cv-member[].

*  endif.

**********************************************************

** Populate Cost Center

**********************************************************

*  if not g_costcenter is initial.

*    move 'COSTCENTER'     to w_cv-dimension.

*    move 'COSTCENTER'     to w_cv-dim_upper_case.

*    append g_costcenter   to w_cv-member.

*    append w_cv           to t_cv_std.

*    refresh: w_cv-member[].

*  endif.

**************************************************

* Populate Version

**************************************************

move 'VER'  to w_cv-dimension.

move 'VER'  to w_cv-dim_upper_case.

append 'WV1'  to w_cv-member.

append w_cv to t_cv_std.

refresh: w_cv-member[].

***************************************************

** Populate CUR

***************************************************

*

*  move 'CUR'  to w_cv-dimension.

*  move 'CUR'  to w_cv-dim_upper_case.

*  append g_cur  to w_cv-member.

*  append w_cv to t_cv_std.

*  refresh: w_cv-member[].

**************************************************

* Populate Paycycle

**************************************************

*  move 'PAYCYCLE'            to w_cv-dimension.

*  move 'PAYCYCLE'            to w_cv-dim_upper_case.

*  w_cv-member[]              =  t_member_paycycle[].

*  append w_cv                to t_cv_std.

*  refresh: w_cv-member[].

********************************************

*Populate HRACCT

*******************************************

*  call function 'Z_BW_BPC_GET_BASE_MEMBERS'

*    exporting

*      i_appset_id      = p_appset

*      i_dimension      = w_dime_hracct

*      i_parent_member  = i_parent_member

*    tables

*      base_member_list = t_temp_member.

*

*  append 'INITIALHDCNT'    to t_temp_member .

*  move 'HRACCT'           to w_cv-dimension.

*  move 'HRACCT'           to w_cv-dim_upper_case.

*  w_cv-member[]           = t_temp_member[].

*  append w_cv             to t_cv_std.

*  refresh: w_cv-member[].

*********************************

t_cv[] = t_cv_std[].

w_first_query  = abap_true.

refresh: t_hr_headcount_plan_std,

         t_hr_headcount_plan_all.

while w_end is initial.

  refresh: t_hr_headcount_plan_std.

  call function 'Z_BW_BPC2_READ_MODEL_IN_PKT'

    exporting

      i_appset_id    = p_appset

      i_appl_id      = p_appl_id

      i_package_size = 21000

    changing

      it_cv          = t_cv

      it_param       = t_param

      et_message     = t_message

      ct_data        = t_hr_headcount_plan_std

      lf_end         = w_end

      lf_first_query = w_first_query.

  append lines of t_hr_headcount_plan_std to  t_hr_headcount_plan_all.

endwhile.

Former Member
0 Kudos

Hi Sandy, Can you let me know how you had resolved this issue.

Former Member
0 Kudos

open a new thread.

Former Member
0 Kudos

I went a different direction and created an export datasource on the BPC cube.

former_member200327
Active Contributor
0 Kudos

You have to check if <lt_data> is assigned before you do a LOOP on that table. RSDRI doesn't return an empty table when there is no more data - it just doesn't assign anything to that field symbol.

Former Member
0 Kudos

Hi Sandy,

In this case you have to call run_rsdri_query only once - during first call and store result into table and then for subsequent calls use cursor on that table to read and return data in packages.

Please refer sdn articles related to FM based generic extraction for implementation details.

Thanks!

Prashant