SAP-BI: Starting Process-Chain via Programm RSPC_API_CHAIN_START and wait for result

Sometimes you want to start a Processchain via programm and wait for it to end. This is a bit tricky as a Processchain starts normaly in Background and doesn’t give you a result if it is ended correctly.
SAP provides for !!!small!!! Processchain the Function
RSPC_API_CHAIN_START

This can be called synchonous with the following example:
call function 'RSPC_API_CHAIN_START'
exporting
i_chain = 'ZMYPROCCESSCHAIN
* I_T_VARIABLES =
i_synchronous = 'X'
* I_SIMULATE =
* I_NOPLAN =
* I_DONT_WAIT =
* IMPORTING
* E_LOGID =
exceptions
failed = 1
others = 2
.

What you have to know is – the result of this function is given on the !!!first!!! finished step – and !!!not!!! for the whole chain. To wait you have to use a little trick:

While using a one-step-chain with a Sub-Processchain this little problem is solved.

SAP-BI: Starting Process-Chain via Programm RSPC_API_CHAIN_START and wait for result

SAP BI: Read Masterdata with compounded keys / RSAU_READ_MASTER_DATA

Hi SAP-BI-Folks,

this little template gives you the possibility to read on InfoObjects with compounded keys : I am normaly more a friend of my own Masterdata-Read-Routines – but i think it’s usefull to know:
released as usual under BSD-Licence:

TYPE-POOLS rsd.
DATA:
l_chavl TYPE rsd_chavl ,
t_dep_m TYPE rrsv_t_dep ,
s_dep_m TYPE rrsv_s_dep ,
l_chavl_m TYPE rschavl ,
wa_zmy_infoobject TYPE /bic/mzmy_infoobject.

CLEAR l_chavl.
l_chavl = result_fields-/bic/zmy_infoobject .

CLEAR t_dep_m[].
s_dep_m-chanm = 'ZCOMPOUND1' .
s_dep_m-chavl_int = result_fields-/bic/zcompound1 .
APPEND s_dep_m TO t_dep_m.
s_dep_m-chanm = 'ZCOMPOUND2' .
s_dep_m-chavl_int = result_fields-comp_code .
APPEND s_dep_m TO t_dep_m.
s_dep_m-chanm = 'ZMY_INFOOBJECT' .
s_dep_m-chavl_int = l_chavl .
APPEND s_dep_m TO t_dep_m.

CALL FUNCTION 'RRSV_CHA_VALUE_CONCATENATE'
EXPORTING
i_chanm = 'ZMY_INFOOBJECT'
i_chavl_int = l_chavl
IMPORTING
e_chavl_int = l_chavl_m
CHANGING
c_t_dep = t_dep_m
EXCEPTIONS
unknown_chanm = 1
invalid_format = 2
no_input_given = 3
OTHERS = 4.

REPLACE ALL OCCURRENCES OF '#' IN l_chavl_m WITH ` `.

CALL FUNCTION 'RSAU_READ_MASTER_DATA'
EXPORTING
i_iobjnm = 'ZMY_INFOOBJECT'
i_chavl = l_chavl_m
IMPORTING
e_structure = wa_zmy_infoobject
EXCEPTIONS
read_error = 1
no_such_attribute = 2
wrong_import_parameters = 3
chavl_not_found = 4.

SAP BI: Read Masterdata with compounded keys / RSAU_READ_MASTER_DATA

Read on SAP BI InfoCubes or InfoProvider via RSDRI_INFOPROV_READ or class CL_RSDRI_INFOPROV

As you SAP Gurus out there knew, it is quite hard to read directly from InfoProviders. One of the reasons why you create DatastorageObjects is to have the possibility to read on it via SELECT.

The nice people of SAP has produced a function method which allows you, with proper use – to read directly in your InfoProviders and select as simple as you like. You may wonder what i’m talking about. I talk about the function RSDRI_INFOPROV_READ or the class cl_rsdri_infoprov. Many good men and women had try to solve the use of this freakin‘ module and has suffered from it.

I hope that the followin code examples will light your days as it has mine. Thanks, rewards, updates, comments are very welcome.
Download a TXT:read_from_infoprovider_template.abap.txt
New version with Class is here: cl_rsdri_infoprov.abap.template

  • Update 06.2012: it runs some time – so now i ‚d come to update this template. I know you are using it out there so – here is an update to object oriented abap with class cl_rsdri_infoprov rather than the function-module.

Be honest – if we had encountered in the pub – you had sponsored me a beer for this, right?








*Copyright (c) 2012 J.Rumpf, www.web-dreamer.de / BSD Licence
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without modification
*are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice, th
* is list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the owner nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific
* prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
*FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
*DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
*SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
*CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
*OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
*OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
TYPE-POOLS: rsdrc.
CONSTANTS: cube TYPE rsinfoprov VALUE 'ZYOURINFOPROVIDER'.
DATA: cube_struct TYPE string,
fact_struct TYPE string.
"generic structure with ALL Characteristics and Keyfigures of the Cube
CONCATENATE '/bic/v' cube 'j' INTO cube_struct.
* cube_struct = 'YOUR_STRUCTURE'.
"Facttable of the Cube - be carfull in Big Cubes - there is an 'f' and an 'g'
CONCATENATE '/bic/v' cube 'f' INTO fact_struct.

TYPES:
t_cube_struct TYPE TABLE OF /bic/vzyourinfoproviderj „== Set on YOUR Target Structure or the content of cube_struct !!!
WITH DEFAULT KEY INITIAL SIZE 0.

DATA:
e_th_sfc TYPE rsdri_th_sfc, „Characteristics of the Cube
e_th_sfk TYPE rsdri_th_sfk, „Keyfigures of the cube

line_of_e_th_sfc TYPE rsdri_s_sfc,
line_of_e_th_sfk TYPE rsdri_s_sfk,

ddic TYPE dd_x031l_table, „Datadictonary for later use
ldic LIKE LINE OF ddic, „Ddic row
fact_ddic TYPE dd_x031l_table, „fact_ddic

my_structure TYPE REF TO data, „Structure of DDIC

g_t_data TYPE t_cube_struct, „table-typ of return-table
t_all_data TYPE t_cube_struct, „Table-type of return-table
c_first_call TYPE rs_bool, “ First-call
r_seloption TYPE rsdri_t_range, „Selection-Table
w_seloption TYPE LINE OF rsdri_t_range, „Selection-Row
end_of_data TYPE rs_bool, „Last Call
infoprov TYPE rsinfoprov “ Infoprovider = cube
.
**********************************************************************
„Sometimes your Structure has Columns you don’t have in your Cube
“ Here you can add this columns to be ignored by the cube.
“ !!! Please note – the function will aggregate on it’s standard key figure behaviour
“ if you don’t add all relevant primary keys!

DATA: ignore_list TYPE STANDARD TABLE OF fieldname.
ldic-fieldname = ‚MY_IGNORE_COLUMN_NAME‘. APPEND ldic-fieldname TO ignore_list.

**********************************************************************
“ From here you go with your selection on your cube – for each selection
“ you need to copy the following lines
DATA: z_infoobjekt TYPE /bic/oiz_infoobjekt. “ == Important because of the selection-type

“ Selection-Condition:
z_infoobjekt = ‚my_selection‘.
w_seloption-chanm = ‚Z_INFOOBJEKT‘. „technical name of InfoObjekt
w_seloption-sign = ‚I‘. “ Include
w_seloption-compop = ‚EQ‘. “ EQUAL
w_seloption-low = z_infoobjekt. „

APPEND w_seloption TO r_seloption.

**********************************************************************
* No change from here necessary.

FIELD-SYMBOLS: TYPE ANY.
DATA: fact_ref TYPE REF TO cl_abap_structdescr.
CREATE DATA my_structure TYPE (fact_struct). „Struktur-Objekt der Faktentabelle lesen
fact_ref ?= cl_abap_tabledescr=>describe_by_data_ref( my_structure ).
CALL METHOD fact_ref->get_ddic_object „DDIC Beschreibung auslesen
RECEIVING
p_object = fact_ddic
EXCEPTIONS
not_found = 1
no_ddic_type = 2
OTHERS = 3.

DATA: descr_ref TYPE REF TO cl_abap_structdescr.
CREATE DATA my_structure TYPE (cube_struct).
descr_ref ?= cl_abap_tabledescr=>describe_by_data_ref( my_structure ). „Struktur-Objekt der zu lesenden Objekte lesen
CALL METHOD descr_ref->get_ddic_object “ DDic Beschreibung auslesen
RECEIVING
p_object = ddic
EXCEPTIONS
not_found = 1
no_ddic_type = 2
OTHERS = 3.

DATA: wa_rol LIKE ldic-fieldname.
LOOP AT ddic INTO ldic. “ Iterate over all relevant Keyfigures
READ TABLE ignore_list FROM ldic-fieldname INTO wa_rol.
IF sy-subrc NE 0.
READ TABLE fact_ddic WITH KEY rollname = ldic-rollname ASSIGNING . „Compare if rollname of fact-table is in Cube-structure – if it is ne 0;
IF sy-subrc NE 0. “ Key-Figure
line_of_e_th_sfc-chanm = ldic-fieldname.
INSERT line_of_e_th_sfc INTO TABLE e_th_sfc.
ELSE. “ must be a characteristic
line_of_e_th_sfk-kyfnm = ldic-fieldname. „
INSERT line_of_e_th_sfk INTO TABLE e_th_sfk. “ !! Be carefull by Cubes with many keyfigures see above !!
ENDIF.
ENDIF.
ENDLOOP.

infoprov = cube. “ Just for type-matching.
DATA: s_r_infoprov TYPE REF TO cl_rsdri_infoprov.

WHILE ( end_of_data NE ‚X‘). “ As long as not end_of_data

CREATE OBJECT s_r_infoprov
EXPORTING
i_infoprov = infoprov
EXCEPTIONS
illegal_input = 1
OTHERS = 2.

CALL METHOD s_r_infoprov->read
EXPORTING
i_th_sfc = e_th_sfc
i_th_sfk = e_th_sfk
i_t_range = r_seloption
* i_th_tablesel = i_th_tablesel
* i_t_rtime = i_t_rtime
* i_reference_date = i_reference_date
* i_t_requid = i_t_requid
* i_save_in_table = i_save_in_table
* i_tablename = i_tablename
* i_save_in_file = i_save_in_file
* i_filename = i_filename
i_packagesize = 999999 „set to a maxvalue – try for your system
* i_maxrows = i_maxrows
i_authority_check = rsdrc_c_authchk-none „use if you want to check auth
* i_currency_conversion = i_currency_conversion
* i_use_db_aggregation = i_use_db_aggregation
* i_use_aggregates = i_use_aggregates
* i_rollup_only = i_rollup_only
* i_read_ods_delta = i_read_ods_delta
* i_caller = i_caller
* i_debug = i_debug
IMPORTING
e_t_data = g_t_data
e_end_of_data = end_of_data
* e_aggregate = e_aggregate
* e_split_occurred = e_split_occurred
* e_t_msg = e_t_msg
* e_stepuid = e_stepuid
EXCEPTIONS
illegal_download = 1
illegal_input = 2
illegal_input_range = 3
illegal_input_sfc = 4
illegal_input_sfk = 5
illegal_input_tablesel = 6
illegal_tablename = 7
inherited_error = 8
no_authorization = 9
trans_no_write_mode = 10
x_message = 11.

IF sy-subrc NE 0.
RAISE EXCEPTION TYPE cx_static_check.
ENDIF.


APPEND LINES OF g_t_data TO t_all_data.
ENDWHILE.

Read on SAP BI InfoCubes or InfoProvider via RSDRI_INFOPROV_READ or class CL_RSDRI_INFOPROV