You are on page 1of 21

FUNCTION /obiz/mfw_bi_view_data.

*"---------------------------------------------------------------------*"*"Local Interface: *" IMPORTING *" VALUE(I_CATEGORY) TYPE SALRTDCAT *" VALUE(I_REQUESTER) TYPE /OBIZ/MFW_ST_RQSR *" TABLES *" T_RETURN TYPE /OBIZ/MFW_TT_MSG OPTIONAL *" T_VALUES TYPE /OBIZ/MFW_TT_DAT OPTIONAL *" T_RESULT TYPE /OBIZ/MFW_TT_DAT OPTIONAL *" T_MESSAGE STRUCTURE /OBIZ/ALM_STR_MESSAGE_MAIN OPTIONAL *" T_DATATYPE TYPE /OBIZ/MFW_TT_DTYP OPTIONAL *"---------------------------------------------------------------------* DATA Declaration TYPE-POOLS: rrx1 . DATA : r_dataset TYPE REF TO cl_rsr_data_set. DATA: lcount TYPE i . DATA: xcount TYPE i . DATA: i_var TYPE rrx1_t_var. DATA: i_var_final TYPE rrx1_t_var. DATA: wf_variant TYPE variant . DATA: wa_axis LIKE LINE OF r_dataset->n_sx_version_20a_1-axis_data . DATA: wa_axis_info LIKE LINE OF r_dataset->n_sx_version_20a_1-axis_info . DATA: wa_chars LIKE LINE OF wa_axis_info-chars . DATA: it_tmp_char TYPE rrws_thx_axis_chars. DATA: wa_tmp_char TYPE rrws_sx_axis_chars . DATA: wa_attrinm TYPE rrws_s_attrinm. DATA: wa_cell LIKE LINE OF r_dataset->n_sx_version_20a_1-cell_data . DATA: wa_textsymbols LIKE LINE OF r_dataset->n_sx_version_20a_1-txt_symbols . DATA: wa_textsymbols1 LIKE LINE OF r_dataset->n_sx_version_20a_1-txt_symbols . DATA: wa_set LIKE LINE OF wa_axis-set. DATA: it_tmp_set TYPE rrws_tx_set. DATA: wa_tmp_set TYPE rrws_sx_tuple . DATA: wa_dattrinm TYPE rrws_s_attributes . DATA: wrk_iset_iobjnm TYPE rsd_iobjnm , wrk_e_iobjnm TYPE rsd_iobjnm . DATA: error_message TYPE string. DATA: q_variables TYPE rrxw3tquery .

DATA: wrk_no_of_chars TYPE i, "Stores the no. of Characteristics in Query wrk_no_of_keyf TYPE i. "Stores the no. of Key figures in Query DATA: var_nam TYPE c LENGTH 10. DATA: wa_iobj_detail TYPE bapi6108 . DATA: it_obj_details TYPE bapi6108_t .

DATA: it_fieldcat TYPE lvc_t_fcat, wa_fieldcat LIKE LINE OF it_fieldcat, wa_fieldcat_tmp LIKE LINE OF it_fieldcat. DATA: return TYPE bapiret2_tab . FIELD-SYMBOLS: <ltable> TYPE ANY TABLE, <l_line> TYPE ANY, <l_field> TYPE ANY. TYPES: BEGIN OF metatype , fieldname(30) TYPE c, outputlen(6) TYPE n, datatype(4) TYPE c, scrtext_l(40) TYPE c, END OF metatype . DATA: meta_data TYPE STANDARD TABLE OF metatype , wa_meta_data TYPE metatype . DATA: off TYPE i, moff TYPE i, mlen TYPE i. DATA: it_obj_return TYPE bapiret2_tab . DATA: it_axis_info TYPE rrws_thx_axis_info , it_cell_data TYPE rrws_t_cell , it_axis_data TYPE rrws_thx_axis_data , it_txt_symbols TYPE rrws_t_text_symbols . DATA: n_counter(3) TYPE n . DATA: char_count TYPE i . DATA: wrk_fldnm(40) TYPE c . DATA: struct_type TYPE REF TO cl_abap_structdescr, tab_type TYPE REF TO cl_abap_tabledescr , comp_tab TYPE cl_abap_structdescr=>component_table, comp LIKE LINE OF comp_tab, dref TYPE REF TO data , dref1 TYPE REF TO data , op_len TYPE i . DATA: fields TYPE tihttpnvp, wa_fields TYPE ihttpnvp, wa_var TYPE w3query, wa_symbols LIKE LINE OF it_txt_symbols. DATA : st_mfw_bi TYPE /obiz/mfw_bi, "Str to store BI Query ID, View ID, RFC Dest. flg_error TYPE c, "Flag to indicate if error occured when fetching Query from BI flg_ref TYPE c, "Flag to indicate if new columns needs to be added for currency/unit. flg_cap TYPE c. "Flag to indicate if new column needs to be added for caption (characteristics). DATA : wa_set_tmp LIKE LINE OF wa_axis-set.

DATA: wrk_old_tuple TYPE rrws_sx_tuple-tuple_ordinal, * wrk_tabix_kf is Line no. of key figure in it_axis_data-SET (000) * to match with line in it_cell_data wrk_tabix_kf TYPE sy-tabix, wrk_col_pos TYPE i, "To store order/sequence of columns in dynamic int. table wrk_lineno TYPE sy-tabix. "Line no. of each item to fill in t_result TYPES : BEGIN OF st_kf_fldnam, "Storing fieldnames of key figures line TYPE n LENGTH 3, fieldname TYPE lvc_s_fcat-fieldname, END OF st_kf_fldnam. * Int. table that stores fieldnames of key figures. * This is used later when we assign values from it_cell_data to final table DATA : it_kf TYPE STANDARD TABLE OF st_kf_fldnam, wa_kf LIKE LINE OF it_kf, wrk_fields TYPE sy-tabix. "No. of fields in dynamically created structure CONSTANTS: c_kf TYPE n LENGTH 3 VALUE '000', "Axis no. to identify Key Figure c_ch TYPE n LENGTH 3 VALUE '001', "Axis no. to identify Characteristics c_us3 TYPE c LENGTH 3 VALUE '___', "3 Underscores c_us2 TYPE c LENGTH 2 VALUE '__', "2 Underscores c_zer TYPE n LENGTH 1 VALUE '0', c_p TYPE c LENGTH 2 VALUE 'P_', "Plain Value code c_f TYPE c LENGTH 2 VALUE 'F_', "Formatted Value code c_c TYPE c LENGTH 2 VALUE 'C_', "Caption code (Characteristics) c_r TYPE c LENGTH 2 VALUE 'R_'. "Currency/Unit Ref code (Key fig.) DATA : wa_result LIKE LINE OF t_result, wa_datatype LIKE LINE OF t_datatype, * wrk_amt TYPE p LENGTH 16 DECIMALS 2, * wrk_qty TYPE p LENGTH 16 DECIMALS 3, wrk_format_val TYPE rrtfmtvalue, wrk_actual_value TYPE rrtfmtvalue, wrk_actual_value2 TYPE rrtfmtvalue. * CLEAR : fields, q_variables, it_axis_info, it_cell_data, it_axis_data, it_txt_symbols. REFRESH : fields, q_variables, it_axis_info, it_cell_data, it_axis_data, it_txt_symbols . ********************************************************************** * Fetch Data from Customization and retreive BI Query date into int. tables ********************************************************************** * Fetch BI Query ID, View id, RFC Destination from Customization PERFORM get_alert_cat_details USING i_category CHANGING st_mfw_bi t_return[]. flg_error = 'X'. "By default, we set error flag as X. Only on success, this is cleared.

IF NOT st_mfw_bi-queryname IS INITIAL OR NOT st_mfw_bi-viewid IS INITIAL . CLEAR : return. REFRESH return. CALL FUNCTION 'RRW3_GET_QUERY_VIEW_DATA' DESTINATION st_mfw_bi-rfcdest EXPORTING i_infoprovider = st_mfw_bi-infoprov i_query = st_mfw_bi-queryname i_view_id = st_mfw_bi-viewid i_t_parameter = q_variables IMPORTING e_axis_info = it_axis_info e_cell_data = it_cell_data e_axis_data = it_axis_data e_txt_symbols = it_txt_symbols EXCEPTIONS no_applicable_data = 1 invalid_variable_values = 2 no_authority =3 abort =4 invalid_input =5 invalid_view =6 OTHERS = 7. CASE sy-subrc . WHEN 0 . Query details fetched Successfully. Proceed. CLEAR flg_error. WHEN 1 . BI Query error. No applicable data PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '100' '' '' '' '' CHANGING t_return[]. WHEN 2 . BI Query error. Invalid variable values PERFORM error_message USING

'E' '/OBIZ/MFW_MSG' '101' '' '' '' '' CHANGING t_return[]. WHEN 3 . BI Query error. No Authority PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '102' '' '' '' '' CHANGING t_return[]. WHEN 4 . BI Query error. Abort PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '103' '' '' '' '' CHANGING t_return[]. WHEN 5 . BI Query error. Invalid input PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '104' '' '' '' '' CHANGING t_return[].

WHEN 6 . BI Query error. Invalid View PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '105' '' '' '' '' CHANGING t_return[]. WHEN OTHERS . * BI Query error. Unknown error PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '106' '' '' '' '' CHANGING t_return[]. ENDCASE . ELSE . * Enter a Query or View name to proceed. PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '107' '' '' '' '' CHANGING t_return[]. ENDIF . * IF flg_error IS INITIAL. "Only if Query details are found successfully * Get no. of Key figures CLEAR: lcount, wa_axis, wa_axis_info. READ TABLE it_axis_data INTO wa_axis WITH KEY axis = c_kf. "'000' IF sy-subrc EQ 0.

CLEAR wrk_no_of_keyf. LOOP AT wa_axis-set INTO wa_set. AT NEW tuple_ordinal. wrk_no_of_keyf = wrk_no_of_keyf + 1. ENDAT. ENDLOOP. CLEAR wa_set. ENDIF. CLEAR : wa_iobj_detail, it_obj_details, wa_axis_info. REFRESH: it_obj_details. * Find no. of Characteristics and Char. details READ TABLE it_axis_info INTO wa_axis_info WITH KEY axis = c_ch. "'001' IF sy-subrc EQ 0. * Get no. of characteristics CLEAR wrk_no_of_chars . wrk_no_of_chars = LINES( wa_axis_info-chars ). * Get details of Characteristics CLEAR wa_chars. REFRESH it_tmp_char. wa_axis_info-chars[] is an int. table containing each characteristics with technical name. Moving each characteristic to it_tmp_char. Including sub attributes of char.(if any) LOOP AT wa_axis_info-chars INTO wa_chars. CLEAR wa_tmp_char. MOVE-CORRESPONDING wa_chars TO wa_tmp_char. INSERT wa_tmp_char INTO TABLE it_tmp_char. IF NOT wa_chars-attrinm[] IS INITIAL. LOOP AT wa_chars-attrinm INTO wa_attrinm. Moving attributes of the characteristic to it_tmp_char CLEAR: wa_tmp_char-chanm, wa_tmp_char-caption. MOVE : wa_attrinm-attrinm TO wa_tmp_char-chanm, wa_attrinm-caption TO wa_tmp_char-caption. INSERT wa_tmp_char INTO TABLE it_tmp_char. ENDLOOP. ENDIF. ENDLOOP. Loop through each characteristics to find the technical attributes of each field (whether CHAR, INT, etc.) so as to build the dynamic int. table LOOP AT it_tmp_char INTO wa_chars. CLEAR : off, moff, mlen. FIND c_us3 IN SECTION OFFSET off OF wa_chars-chanm. IF sy-subrc EQ 0.

* * *

* *

"FIND '___'

CLEAR : wrk_iset_iobjnm, wrk_e_iobjnm. MOVE wa_chars-chanm TO wrk_iset_iobjnm. CALL FUNCTION 'RSD_IOBJNM_GET_FROM_INFOSET' "DESTINATION st_mfw_bi-rfcdest EXPORTING i_iset_iobjnm = wrk_iset_iobjnm IMPORTING e_iobjnm = wrk_e_iobjnm EXCEPTIONS name_error = 1 no_field = 2 OTHERS = 3. IF sy-subrc <> 0. Error occured. ENDIF. CLEAR wa_chars-chanm. MOVE wrk_e_iobjnm TO wa_chars-chanm. ELSE. "'___' not found FIND c_us2 IN SECTION OFFSET off OF wa_chars-chanm MATCH OFFSET moff MATCH LENGTH mlen. IF sy-subrc EQ 0. off = moff + mlen. SHIFT wa_chars-chanm LEFT BY off PLACES. ENDIF . ENDIF . " two __ or three ___ CLEAR it_obj_return. REFRESH it_obj_return. CALL FUNCTION 'BAPI_IOBJ_GETDETAIL' DESTINATION st_mfw_bi-rfcdest EXPORTING version = rs_c_objvers-active infoobject = wa_chars-chanm IMPORTING details = wa_iobj_detail. IF NOT wa_iobj_detail IS INITIAL. APPEND wa_iobj_detail TO it_obj_details. CLEAR wa_iobj_detail. ELSE. MOVE : wa_chars-chanm TO wa_iobj_detail-infoobject, wa_chars-caption TO wa_iobj_detail-textlong. APPEND wa_iobj_detail TO it_obj_details. CLEAR wa_iobj_detail. ENDIF. CLEAR wa_iobj_detail . "FIND '__'

ENDLOOP. ENDIF. ********************************************************************** * Build field cat. for creating the dynamic internal table ********************************************************************** * it_obj_details contains technical details of only characteristics now. * Building field cat. for characteristics CLEAR : wa_fieldcat, wa_iobj_detail, it_fieldcat, wrk_col_pos. REFRESH it_fieldcat. LOOP AT it_obj_details INTO wa_iobj_detail. wa_fieldcat-fieldname = wa_iobj_detail-infoobject. IF wa_fieldcat-fieldname+0(1) EQ c_zer. "'0' SHIFT wa_fieldcat-fieldname LEFT BY 1 PLACES. ENDIF . wa_fieldcat-outputlen = wa_iobj_detail-outputlen. wa_fieldcat-datatype = wa_iobj_detail-datatp. wa_fieldcat-scrtext_l = wa_iobj_detail-textlong. * * * * For each characteristics field in Query, we need to add 2 columns in dynamic int. table. 1 for Plain value and 2nd for Formatted value. Plain value field name should begin with P_ and the original field name. Formatted value field name should begin with F_ and the original field name. MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_p wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_f wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. ADD 10 TO wa_fieldcat-outputlen. "Formatted values have larger length wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. * * For some characteristics, there is a caption. In such case, we need to add a separate column with fieldname beginning in C_ READ TABLE it_axis_data INTO wa_axis WITH KEY axis = c_ch. "'001' IF sy-subrc EQ 0. READ TABLE wa_axis-set INTO wa_set WITH KEY chanm = wa_iobj_detail-infoobject TRANSPORTING caption. IF sy-subrc EQ 0. IF NOT wa_set-caption IS INITIAL. flg_cap = 'X'. "Extra column for caption required ELSE. flg_cap = ''. "Extra column for caption NOT required

ENDIF. ENDIF. ENDIF. IF NOT flg_cap IS INITIAL. MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_c wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. wa_fieldcat-outputlen = 60. "Captions have length 60 always wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. ENDIF. CLEAR : wa_fieldcat, wa_iobj_detail, wa_set. ENDLOOP. * Building field cat. for key figures * Read data about Key figures CLEAR :n_counter, wa_axis. READ TABLE it_axis_data INTO wa_axis WITH KEY axis = c_kf. "'000'. IF sy-subrc EQ 0. CLEAR : wrk_tabix_kf, wa_kf.. * Loop through each Key figure heading in it_axis_data-000-set[] LOOP AT wa_axis-set INTO wa_set. AT NEW tuple_ordinal. * For key figure fields, we dont have any technical properties available * Hence, we fix the logic as character type length 50 to be generic for all key figures wa_fieldcat-outputlen = '50'. wa_fieldcat-datatype = 'CHAR'. ENDAT. CONCATENATE wa_fieldcat-scrtext_l wa_set-caption INTO wa_fieldcat-scrtext_l SEPARATED BY ` `. IF wa_fieldcat-fieldname IS INITIAL. MOVE wa_set-caption TO wa_fieldcat-fieldname. REPLACE ALL OCCURRENCES OF '.' IN wa_fieldcat-fieldname WITH space. CONDENSE wa_fieldcat-fieldname NO-GAPS. SET LOCALE LANGUAGE sy-langu. TRANSLATE wa_fieldcat-fieldname TO UPPER CASE. ENDIF. * wa_fieldcat-scrtext_l = wa_set-caption. AT END OF tuple_ordinal. SHIFT wa_fieldcat-scrtext_l LEFT DELETING LEADING ' '. For each key figure, we store fieldname and position in it_kf. This is later used to transfer the field contents to the fields by fldname ADD 1 TO wa_kf-line. wa_kf-fieldname = wa_fieldcat-fieldname. APPEND wa_kf TO it_kf.

* *

* * * *

* * * *

For each key figure field in Query, we need 2 columns in dynamic int. table 1 to store the Plain Value and 2nd to store the Formatted Value Fieldname for plain value begins with P_ Fieldname for formatted value begins with F_ MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_p wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. Formatted Value MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_f wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. ADD 10 TO wa_fieldcat-outputlen. "Formatted values have larger length wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. If the column is a currency or quantity field, we need to add a new column to store the currency key or quantity unit respectively. For this, we first check if currency key or quan. unit is entered in it_cell_data If entered, we need to add a new column ADD 1 TO wrk_tabix_kf. READ TABLE it_cell_data INTO wa_cell INDEX wrk_tabix_kf TRANSPORTING currency unit. IF sy-subrc EQ 0. IF NOT wa_cell-currency IS INITIAL. flg_ref = 'X'. "Extra column for reference curr/unit required ELSEIF NOT wa_cell-unit IS INITIAL. flg_ref = 'X'. "Extra column for reference curr/unit required ELSE. CLEAR flg_ref. "Extra column for reference curr/unit NOT required ENDIF. ENDIF. IF NOT flg_ref IS INITIAL. MOVE wa_fieldcat TO wa_fieldcat_tmp. CONCATENATE c_r wa_fieldcat_tmp-fieldname INTO wa_fieldcat_tmp-fieldname. ADD 1 TO wrk_col_pos. wa_fieldcat-outputlen = 5. "Currency key has length 5. Unit has 3 wa_fieldcat_tmp-col_pos = wrk_col_pos. APPEND wa_fieldcat_tmp TO it_fieldcat. ENDIF. CLEAR : wa_fieldcat, wa_cell. ENDAT. ENDLOOP. ENDIF. CLEAR: meta_data, wa_meta_data . REFRESH meta_data .

LOOP AT it_fieldcat INTO wa_fieldcat . MOVE-CORRESPONDING wa_fieldcat TO wa_meta_data . APPEND wa_meta_data TO meta_data . CLEAR: wa_meta_data, wa_fieldcat . ENDLOOP . ********************************************************************** * Create the dynamic internal table <ltable> ********************************************************************** SORT it_fieldcat BY fieldname. DELETE ADJACENT DUPLICATES FROM it_fieldcat COMPARING fieldname. SORT it_fieldcat BY col_pos. CLEAR: comp, comp_tab, wa_fieldcat. REFRESH comp_tab. LOOP AT it_fieldcat INTO wa_fieldcat. CLEAR op_len. op_len = wa_fieldcat-outputlen. comp-name = wa_fieldcat-fieldname. PERFORM get_data_type USING wa_fieldcat-datatype wa_fieldcat-outputlen CHANGING comp-type. APPEND comp TO comp_tab. CLEAR : wa_fieldcat, comp. ENDLOOP. CLEAR struct_type. CALL METHOD cl_abap_structdescr=>create EXPORTING p_components = comp_tab p_strict = cl_abap_structdescr=>false RECEIVING p_result = struct_type. CLEAR tab_type. CALL METHOD cl_abap_tabledescr=>create EXPORTING p_line_type = struct_type p_table_kind = cl_abap_tabledescr=>tablekind_std RECEIVING p_result = tab_type. CREATE DATA dref1 TYPE HANDLE tab_type. ASSIGN dref1->* TO <ltable>.

CREATE DATA dref TYPE HANDLE struct_type. ASSIGN dref->* TO <l_line>. * CLEAR : char_count, xcount, wa_axis, lcount. REFRESH it_tmp_set. * Looping through value of characteristics and moving to it_tmp_set LOOP AT it_axis_data INTO wa_axis WHERE axis = c_ch. "Characteristics = '001' LOOP AT wa_axis-set INTO wa_set. CLEAR wa_tmp_set . MOVE-CORRESPONDING wa_set TO wa_tmp_set . INSERT wa_tmp_set INTO TABLE it_tmp_set. IF NOT wa_set-attributes[] IS INITIAL . LOOP AT wa_set-attributes INTO wa_dattrinm . CLEAR: wa_tmp_set-chanm , wa_tmp_set-chavl, wa_tmp_set-chavl_ext, wa_tmp_set-caption. MOVE: wa_dattrinm-attrinm TO wa_tmp_set-chanm, wa_dattrinm-attrivl TO wa_tmp_set-chavl, wa_dattrinm-attrivl TO wa_tmp_set-chavl_ext, wa_dattrinm-caption TO wa_tmp_set-caption. INSERT wa_tmp_set INTO TABLE it_tmp_set. ENDLOOP. ENDIF. ENDLOOP. ENDLOOP. ********************************************************************** * Move the values of characteristics and key figures to final int. table <ltable> ********************************************************************** LOOP AT it_tmp_set INTO wa_set. AT NEW tuple_ordinal. IF lcount GT 0. lcount = lcount - 1. ENDIF. CLEAR <l_line>. ENDAT. CLEAR off. CLEAR : off, moff, mlen. FIND c_us3 IN SECTION OFFSET off OF " FIND '___' wa_set-chanm. IF sy-subrc EQ 0. CLEAR : wrk_iset_iobjnm , wrk_e_iobjnm. MOVE wa_set-chanm TO wrk_iset_iobjnm. CALL FUNCTION 'RSD_IOBJNM_GET_FROM_INFOSET' "DESTINATION st_mfw_bi-rfcdest EXPORTING i_iset_iobjnm = wrk_iset_iobjnm IMPORTING

e_iobjnm = wrk_e_iobjnm EXCEPTIONS name_error = 1 no_field = 2 OTHERS = 3. CALL FUNCTION 'RSD_IOBJNM_GET_FROM_INFOSET' EXPORTING i_iset_iobjnm = wrk_iset_iobjnm IMPORTING e_iobjnm = wrk_e_iobjnm EXCEPTIONS name_error = 1 no_field = 2 OTHERS = 3. IF sy-subrc <> 0. MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4. ENDIF.

* *

CLEAR wa_set-chanm. MOVE wrk_e_iobjnm TO wa_set-chanm. ELSE. FIND c_us2 IN SECTION OFFSET off OF "FIND '__' wa_set-chanm MATCH OFFSET moff MATCH LENGTH mlen. IF sy-subrc EQ 0. off = moff + mlen. SHIFT wa_set-chanm LEFT BY off PLACES. ENDIF. ENDIF. " check three _ or two _ IF wa_set-chanm+0(1) EQ '0' . SHIFT wa_set-chanm LEFT BY 1 PLACES. ENDIF. Move the plain value and formatted value to <l_line>. Plain value MOVE-CORRESPONDING wa_set TO wa_set_tmp. CONCATENATE c_p wa_set_tmp-chanm INTO wa_set_tmp-chanm. ASSIGN COMPONENT wa_set_tmp-chanm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_set_tmp-chavl. Formatted value MOVE-CORRESPONDING wa_set TO wa_set_tmp. CONCATENATE c_f wa_set_tmp-chanm INTO wa_set_tmp-chanm. ASSIGN COMPONENT wa_set_tmp-chanm OF STRUCTURE <l_line> TO <l_field>.

* *

<l_field> = wa_set_tmp-chavl_ext. Caption IF NOT wa_set-caption IS INITIAL. MOVE-CORRESPONDING wa_set TO wa_set_tmp. CONCATENATE c_c wa_set_tmp-chanm INTO wa_set_tmp-chanm. ASSIGN COMPONENT wa_set_tmp-chanm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_set_tmp-caption. ENDIF. After the end of characteristics of each row, add the key figures of that row Each row has a unique tuple_ordinal AT END OF tuple_ordinal. CLEAR: xcount, char_count, n_counter. lcount = lcount + 1. LOOP AT it_cell_data INTO wa_cell FROM lcount. n_counter = n_counter + 1. IF n_counter GT wrk_no_of_keyf. EXIT. ENDIF. Retreive field name of key figures from it_kf to assign values from wa_cell READ TABLE it_kf INTO wa_kf WITH KEY line = n_counter. IF sy-subrc EQ 0. Plain value CONCATENATE c_p wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_cell-value. Formatted Value CLEAR : wrk_fldnm. CONCATENATE c_f wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_cell-formatted_value. wrk_format_val = wa_cell-formatted_value. Currency key or unit (if any) CLEAR : wrk_fldnm. IF NOT wa_cell-currency IS INITIAL. CONCATENATE c_r wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_cell-currency. CONCATENATE c_p wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. The current field is a currency amount field. Plain value needs to be re-written with the actual value. For this we split the formatted value at space and get the correct amount

* * *

* * *

* * *

SPLIT wrk_format_val AT space INTO wrk_actual_value wrk_actual_value2. <l_field> = wrk_actual_value. ELSEIF NOT wa_cell-unit IS INITIAL. CONCATENATE c_r wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. <l_field> = wa_cell-unit. CONCATENATE c_p wa_kf-fieldname INTO wrk_fldnm. ASSIGN COMPONENT wrk_fldnm OF STRUCTURE <l_line> TO <l_field>. The current field is a quantity field. Plain value needs to be re-written with actual value. For this we split the formatted value at space and get the correct amount SPLIT wrk_format_val AT space INTO wrk_actual_value wrk_actual_value2. <l_field> = wrk_actual_value. ENDIF. ENDIF. ENDLOOP. lcount = lcount + wrk_no_of_keyf. INSERT <l_line> INTO TABLE <ltable>. ENDAT. ENDLOOP.

********************************************************************** * Move the data and field properties from <ltable> to key/value pair table T_RESULT ********************************************************************** * Move the item-level information from <ltable> to T_RESULT[]. wrk_fields = LINES( it_fieldcat ). "No. of fields/columns in internal table LOOP AT <ltable> ASSIGNING <l_line>. wrk_lineno = sy-tabix. LOOP AT it_fieldcat INTO wa_fieldcat. CLEAR wa_result. IF sy-tabix EQ wrk_fields. * If this is the last field in the row, mark this as X wa_result-alm_last_field = 'X'. ENDIF. ASSIGN COMPONENT wa_fieldcat-fieldname OF STRUCTURE <l_line> TO <l_field>. wa_result-alm_pname = 'ITEM'. wa_result-alm_kind = 'T'. "Table wa_result-alm_component = wa_fieldcat-fieldname. wa_result-alm_value = <l_field>. wa_result-alm_tab_itm_no = wrk_lineno. APPEND wa_result TO t_result. ENDLOOP. ENDLOOP. * Moving meta data of item fields to T_DATATYPE. Information about fields

LOOP AT meta_data INTO wa_meta_data. CLEAR wa_datatype. wa_datatype-alm_pname = 'ITEM'. wa_datatype-alm_kind = 'T'. "Table wa_datatype-alm_component = wa_meta_data-fieldname. "Field name wa_datatype-datatype = wa_meta_data-datatype. "Field type wa_datatype-leng = wa_meta_data-outputlen. "Field length * wa_datatype-DECIMALS =. wa_datatype-ddtext = wa_meta_data-scrtext_l. "Field label * wa_datatype-REQUIRED =. * wa_datatype-ZINPUT =. APPEND wa_datatype TO t_datatype. ENDLOOP. * Move the header level information from IT_TXT_SYMBOLS to T_RESULT[]. LOOP AT it_txt_symbols INTO wa_symbols. * Moving values to T_RESULT CLEAR wa_result. wa_result-alm_pname = 'HEADER'. wa_result-alm_kind = 'E'. "Export wa_result-alm_component = wa_symbols-sym_name. "Field name wa_result-alm_value = wa_symbols-sym_value. "Field value APPEND wa_result TO t_result. * Moving field information of header fields to T_DATATYPE CLEAR wa_datatype. wa_datatype-alm_pname = 'HEADER'. wa_datatype-alm_kind = 'E'. "Exporting wa_datatype-alm_component = wa_symbols-sym_name. "Field name wa_datatype-datatype = 'CHAR'. wa_datatype-leng = wa_symbols-sym_outputlen. "Field length * wa_datatype-DECIMALS =. wa_datatype-ddtext = wa_symbols-sym_caption. "Field label APPEND wa_datatype TO t_datatype. ENDLOOP. ENDIF. "flg_error IS INITIAL ENDFUNCTION. *&---------------------------------------------------------------------* *& Form get_alert_cat_details *&---------------------------------------------------------------------* * Fetch all details like BI Query Name, View ID, RFC Destination * from OptiSuite customization based on Alert category input *----------------------------------------------------------------------* FORM get_alert_cat_details USING p_category TYPE salrtdcat CHANGING p_stmfw_bi TYPE /obiz/mfw_bi p_it_return TYPE /obiz/mfw_tt_msg. * Selecting the query name, view id and other details from Customization table SELECT SINGLE *

FROM /obiz/mfw_bi INTO p_stmfw_bi WHERE alm_category = p_category. IF sy-subrc <> 0. * Alert category is not maintained in OptiSuite MFW BI Customization PERFORM error_message USING 'E' '/OBIZ/MFW_MSG' '108' '' '' '' '' CHANGING p_it_return[]. ENDIF. ENDFORM. "get_alert_cat_details *&---------------------------------------------------------------------* *& Form error_message *&---------------------------------------------------------------------* * Generic subroutine to fill messages in return int. table t_return *----------------------------------------------------------------------* * -->US_MSGTY text * -->US_MSGID text * -->US_MSGNO text * -->US_MSGV1 text * -->US_MSGV2 text * -->US_MSGV3 text * -->US_MSGV4 text * -->US_RETURN text *----------------------------------------------------------------------* FORM error_message USING p_msgty TYPE bapireturn-type p_msgid TYPE sy-msgid p_msgno TYPE sy-msgno p_msgv1 TYPE any p_msgv2 TYPE any p_msgv3 TYPE any p_msgv4 TYPE any CHANGING it_return TYPE /obiz/mfw_tt_msg.

DATA: wa_bapiret TYPE bapiret2, wa_return TYPE /obiz/mfw_st_msg, wrk_msgv1 TYPE sy-msgv1, wrk_msgv2 TYPE sy-msgv2, wrk_msgv3 TYPE sy-msgv3, wrk_msgv4 TYPE sy-msgv4.

wrk_msgv1 = p_msgv1. wrk_msgv2 = p_msgv2. wrk_msgv3 = p_msgv3. wrk_msgv4 = p_msgv4. CLEAR wa_bapiret. CALL FUNCTION 'BALW_BAPIRETURN_GET2' EXPORTING type = p_msgty cl = p_msgid number = p_msgno par1 = wrk_msgv1 par2 = wrk_msgv2 par3 = wrk_msgv3 par4 = wrk_msgv4 IMPORTING return = wa_bapiret. wa_return-alm_type = wa_bapiret-type. wa_return-alm_id = wa_bapiret-id. wa_return-alm_number = wa_bapiret-number. wa_return-alm_message = wa_bapiret-message. wa_return-alm_log_no = wa_bapiret-log_no. wa_return-alm_log_msg_no = wa_bapiret-log_msg_no. wa_return-alm_message_v1 = wa_bapiret-message_v1. wa_return-alm_message_v2 = wa_bapiret-message_v2. wa_return-alm_message_v3 = wa_bapiret-message_v3. wa_return-alm_message_v4 = wa_bapiret-message_v4. APPEND wa_return TO it_return . ENDFORM. "error_message *&---------------------------------------------------------------------* *& Form get_data_type *&---------------------------------------------------------------------* * Get the ABAP Data type (C,N,D,T,X) from the * DD type (CHAR, NUMC, DATS) etc. *----------------------------------------------------------------------* * -->P_FCAT_DATATYPE DD Data type * -->P_COMP_TYPE ABAP Component type *----------------------------------------------------------------------* FORM get_data_type USING p_fcat_datatype TYPE lvc_s_fcat-datatype p_fcat_outputlen TYPE lvc_s_fcat-outputlen CHANGING p_comp_type TYPE REF TO cl_abap_datadescr. DATA : wrk_abaptype TYPE dd03l-inttype, wrk_abtyp_int TYPE dd03l-inttype, wrk_length TYPE i.

* When calling below methods, we need length in an INT4 variable wrk_length = p_fcat_outputlen.

CALL FUNCTION 'DD_DDTYPE_TO_ABAPTYPE' EXPORTING ddtype = p_fcat_datatype IMPORTING abtype = wrk_abaptype abtype_int = wrk_abtyp_int EXCEPTIONS illegal_value = 1 OTHERS = 2. IF sy-subrc <> 0. * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO * WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4. ENDIF. * CASE wrk_abaptype. CASE wrk_abtyp_int. WHEN 'N'. TRY. CALL METHOD cl_abap_elemdescr=>get_n EXPORTING p_length = wrk_length RECEIVING p_result = p_comp_type. CATCH cx_parameter_invalid_range . ENDTRY. WHEN 'C'. TRY. CALL METHOD cl_abap_elemdescr=>get_c EXPORTING p_length = wrk_length RECEIVING p_result = p_comp_type. CATCH cx_parameter_invalid_range . ENDTRY. WHEN 'P'. TRY. CALL METHOD cl_abap_elemdescr=>get_p EXPORTING p_length = wrk_length p_decimals = 2 RECEIVING p_result = p_comp_type.

CATCH cx_parameter_invalid_range . ENDTRY. WHEN 'D'. CALL METHOD cl_abap_elemdescr=>get_d RECEIVING p_result = p_comp_type. WHEN 'T'. CALL METHOD cl_abap_elemdescr=>get_t RECEIVING p_result = p_comp_type. WHEN 'I'. CALL METHOD cl_abap_elemdescr=>get_i RECEIVING p_result = p_comp_type. WHEN 'X'. TRY. CALL METHOD cl_abap_elemdescr=>get_x EXPORTING p_length = wrk_length RECEIVING p_result = p_comp_type. CATCH cx_parameter_invalid_range . ENDTRY. WHEN 'F'. CALL METHOD cl_abap_elemdescr=>get_f RECEIVING p_result = p_comp_type. WHEN OTHERS. If unknown, create character TRY. CALL METHOD cl_abap_elemdescr=>get_c EXPORTING p_length = wrk_length RECEIVING p_result = p_comp_type. CATCH cx_parameter_invalid_range . ENDTRY. ENDCASE.

ENDFORM.

"get_data_type