Step by Step Process To Run BEX Report in Background
Step by Step Process To Run BEX Report in Background
Report in Background
Applies to:
SAP BW 3.x.
Summary
This paper describes step by step process of implementing of a generic tool
and how to run BEX query in background using that tool. It is accomplished
through a Custom ABAP Program, which can be used to run any BEX query
restricted by selection variant in background. The output is stored in a
delimited text File in a specified application server directory.
Table of Contents
Requirement.....................................................................................................3
How BEX Query Run in Foreground.........................................................3
How this tool works..........................................................................................5
Step by step process........................................................................................5
Step 1: Run BEX Query..........................................................................5
Step 2: Give the value in Selection screen.............................................5
Step 3: Save the Variant.........................................................................6
Step 4: Run the wrapper program...........................................................6
Step 5: Give Query Name.......................................................................6
Step 6: Give Variant................................................................................7
Step 7: Give File Path.............................................................................7
Step 8: Execute the Program in Background..........................................8
Step 9: Check the Log.............................................................................8
Step 10: Download the File...................................................................10
Limitation.......................................................................................................10
Appendix........................................................................................................10
Related Content..............................................................................................23
Disclaimer and Liability Notice........................................................................24
Requirement
BEX Query Analyzer is the tool used to analyze ad hoc query results in MS
Excel. BEX Query Analyzer can be used to run ad hoc queries and open BEX
Query Designer to create and modify ad hoc queries. BEX Query Analyzer
opens in MS Excel and provides its own toolbar and Business Explorer menu
to perform query analysis.
Proposed Tool can be used in below situation: Those environments, where Excel 2003 or below is installed for BEX
reporting, which is having a limitation to display only 65 K rows.
Run a BEX-Query in Batch-Mode (periodically and automatically) and
download output in a directory, which can be read form another system.
If the query is performed on detail level data and no further drill down is
required on the output. Only Static information is required.
As an alternate of Open Hub.
If the query gives shortage of memory dump or exceeding the time limit
dump due to high volume of data.
Give the value for the selection field in the selection screen
Limitation:The only supported file type is delimited Text file. However, program can be
twisted to save the output in other format.
APPENDIX:REPORT ZBWR_BEX_QUERY
line-size 1023 message-id ZBW_ALL.
************************************************************************
*
Types Declarations
************************************************************************
TYPE-POOLS: rsr, rzi0, rrx1, rrms, rsbbs, rrkh, rro01, rsdd,
rrx2, rsdm4, vrm.
TYPES: BEGIN OF g_s_col_width,
column TYPE rrx1_s_grid-x,
width TYPE i,
END OF g_s_col_width,
g_t_col_widths TYPE g_s_col_width OCCURS 0.
tables : varid.
************************************************************************
*
Constants Decalaration
************************************************************************
Constants: c_x type c value 'X',
c_m type c value 'M',
c_w type c value 'W',
c_t type c value 'T',
c_n type c value 'R',
c_r type c value 'R',
c_s type c value 'S'.
************************************************************************
*
Variable Declarations
************************************************************************
data: v_string(65000) type c.
DATA: g_th_dat_n
TYPE rrx1_th_dat_n,
g_th_txt_n
TYPE rrx1_th_txt_n,
g_gentime
TYPE rsr_s_rkb1d-gentime,
g_s_grid_layout TYPE rrx1_s_grid_layout,
g_t_grid
TYPE rrx1_t_grid,
g_t_ranges
TYPE rrx1_t_ranges,
g_t_hry_types TYPE rrx1_t_hry_types,
g_t_ranges_out TYPE rrx1_t_ranges,
g_s_ranges
TYPE rrx1_s_ranges,
g_dflt_req_lines TYPE i,
g_t_mesg
TYPE rrx1_t_mesg,
g_t_menu
TYPE rrx1_t_menu,
g_fieldname(20) TYPE c,
g_t_repdir
LIKE rsrrepdir OCCURS 10,
g_s_repkey
LIKE rszcompkey,
g_handle
LIKE rrx_misc-handle,
g_handle2
LIKE rrx_misc-handle,
g_handle_int LIKE rrx_grid-x,
g_t_var
LIKE rrx_var OCCURS 0,
g_t_var2
LIKE rrx_var OCCURS 0,
g_t_msg
LIKE rrx_mesg OCCURS 0,
g_t_msg2
LIKE rrx_mesg OCCURS 0,
g_x
LIKE rrx_grid-x,
g_y
LIKE rrx_grid-y,
g_subrc
LIKE sy-subrc,
g_ucomm
LIKE sy-ucomm,
g_cmdid
TYPE rrx_menu-cmdid
value 'STRT', "ID of Excel context menu
g_t_dim
TYPE rrx1_t_dim,
g_t_atr
TYPE rrx1_t_atr,
g_t_mem
TYPE rrx1_t_mem,
g_t_con
TYPE rrx1_t_con,
g_t_fac
TYPE rrx1_t_fac,
g_t_cel
TYPE rrx1_t_cel,
g_s_prptys
TYPE rrx1_s_prptys,
g_t_prptys
TYPE rrx1_t_prptys,
g_s_debugflags TYPE rsr_s_debugflags,
g_t_col_widths TYPE g_t_col_widths,
g_bbs_receiver TYPE rsbbsreceiver,
g_t_genuniid TYPE w3html OCCURS 0,
g_iobjnm
TYPE rs_char30,
g_row
TYPE rsint4,
g_row_hide
TYPE rsint4,
g_start_row
TYPE rsint4,
g_col
TYPE rsint4,
g_cancel
TYPE rs_bool,
g_ok(20)
TYPE c,
g_chavl
TYPE rsd_chavl,
g_r_e
TYPE REF TO cx_root,
g_cmd_count
TYPE i.
DATA: g_txt1(50) TYPE c,
g_txt2(50) TYPE c,
g_txt3(50) TYPE c,
g_txt4(50) TYPE c,
g_txt5(50) TYPE c,
g_txt6(50) TYPE c,
g_txt7(50) TYPE c,
g_txt8(50) TYPE c,
g_txt9(50) TYPE c,
g_txt10(50) TYPE c,
g_txt11(50) TYPE c,
g_txt12(50) TYPE c,
g_txt13(50) TYPE c,
g_txt14(50) TYPE c,
g_txt15(50) TYPE c,
g_txt16(50) TYPE c,
g_txt17(50) TYPE c,
g_txt18(50) TYPE c,
g_txt19(50) TYPE c,
g_txt20(50) TYPE c,
g_txt21(50) TYPE c,
g_txt22(50) TYPE c,
g_txt23(50) TYPE c,
g_txt24(50) TYPE c,
g_txt25(50) TYPE c,
g_txt26(50) TYPE c,
g_txt27(50) TYPE c,
g_txt28(50) TYPE c,
g_txt29(50) TYPE c,
g_txt30(50) TYPE c,
g_txt31(50) TYPE c,
g_txt32(50) TYPE c,
g_txt33(50) TYPE c,
g_txt34(50) TYPE c,
g_txt35(50) TYPE c,
g_txt36(50) TYPE c,
g_txt37(50)
g_txt38(50)
g_txt39(50)
g_txt40(50)
g_txt41(50)
g_txt42(50)
g_txt43(50)
g_txt44(50)
g_txt45(50)
g_txt46(50)
g_txt47(50)
g_txt48(50)
g_txt49(50)
g_txt50(50)
g_txt51(50)
g_txt52(50)
g_txt53(50)
g_txt54(50)
g_txt55(50)
g_txt56(50)
g_txt57(50)
g_txt58(50)
g_txt59(50)
g_txt60(50)
g_txt61(50)
g_txt62(50)
g_txt63(50)
g_txt64(50)
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c,
TYPE c.
************************************************************************
*
Declaration of work areas
************************************************************************
DATA: BEGIN OF w_session,
reportuid TYPE rscrmrepuid,
sessionid TYPE rscrmsession,
END OF w_session.
data : wa_infocube like RSZCOMPKEY-infocube.
************************************************************************
*
Declaration of Selection Screen
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK BLK1 WITH FRAME TITLE TEXT-000.
*&---------------------------------------------------------------------*
*&
Form sub_opensession
*&---------------------------------------------------------------------*
*
text
*----------------------------------------------------------------------*
FORM sub_getdata .
* open the output file for data download, if not raise error
OPEN DATASET P_OFILE FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC <> 0.
MESSAGE E000(zz) WITH 'File Could not be Open'.
endif.
* generate the report for multiple variant values.
loop at s_varnt.
refresh: g_t_ranges,g_t_dim, g_t_mem, g_t_cel,g_t_prptys,
g_t_atr,g_t_grid,g_t_con,g_t_fac,g_t_var.
clear v_RSR_S_RKB1D.
*getting the handle
CALL FUNCTION 'RRX_REPORT_OPEN'
EXPORTING
i_genuniid
= p_genuid
IMPORTING
e_handle
= g_handle
EXCEPTIONS
open_failed
=1
invalid_genuniid = 2
msg_init_failed = 3
inherited_error = 4
x_message
=5
OTHERS
= 6.
*To hide the popup of selection screen of the selected query
CALL FUNCTION 'RRC_VARIABLES_START'
EXPORTING
I_HANDLE
= g_handle
I_SELSCRN
= RSR_C_SELSCRN-INACT
* I_VARIANT
= p_varnt
I_VARIANT
= s_varnt-low " low value of variant
I_PMODE
=''
I_NEW_VARIANT
= RS_C_FALSE
IMPORTING
E_S_RKB1D
= v_RSR_S_RKB1D.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'Problem in getting value of variant'(003).
ENDIF.
*getting the BEX query results
CALL FUNCTION 'RRX_GRID_CMD_PROCESS'
EXPORTING
i_handle
= g_handle
i_cmdid
= g_cmdid
i_iobjnm
= g_iobjnm
IMPORTING
e_max_x
= g_x
e_max_y
= g_y
TABLES
i_t_ranges
= g_t_ranges
e_t_dim
= g_t_dim
e_t_mem
= g_t_mem
e_t_cel
= g_t_cel
c_t_prptys
= g_t_prptys
e_t_atr
= g_t_atr
e_t_grid
= g_t_grid
e_t_ranges
= g_t_ranges
e_t_con
= g_t_con
e_t_fac
= g_t_fac
e_t_var
= g_t_var
EXCEPTIONS
inherited_error = 1
no_record_found = 2
terminated_by_user = 3
no_processing
=4
no_change
=5
dbcl_nosupport = 6
no_authorization = 7
x_message
=8
screen_canceled = 9
launch_url
= 10
OTHERS
= 11.
.
IF SY-SUBRC <> 0.
MESSAGE E000 WITH 'Problem in getting BEx query results'(004).
ENDIF.
perform sub_report_genarate. " generate report
CALL FUNCTION 'RRX_REPORT_CLOSE'
EXPORTING
I_HANDLE
= g_handle.
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
endloop.
*&--------------------------------------------------------------------*
*&
Form sub_determine_col_widths
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->C_T_GRID text
*
-->C_T_COL_WIDtext
*---------------------------------------------------------------------*
FORM sub_determine_col_widths
CHANGING c_t_grid
TYPE rrx1_t_grid
c_t_col_widths TYPE g_t_col_widths.
DATA: l_s_grid
TYPE rrx1_s_grid,
l_s_grid_last TYPE rrx1_s_grid,
l_s_col_width TYPE g_s_col_width,
l_len
TYPE i,
l_maxwidth TYPE i VALUE 25.
"MST
SORT c_t_grid BY x.
LOOP AT c_t_grid INTO l_s_grid.
AT NEW x.
CLEAR: l_s_grid_last, l_s_col_width.
l_s_col_width-column = l_s_grid-x.
ENDAT.
l_len = strlen( l_s_grid-data ).
* Lnge wird abhngig vom mwkz erweitert
MST
CASE l_s_grid-mwkz.
WHEN c_m.
IF l_s_grid-y NE 1.
"Keine Zahlen in Zeile 1
l_len = l_len + 5.
ENDIF.
WHEN C_w.
IF l_s_grid-y NE 1.
"Keine Zahlen in Zeile 1
l_len = l_len + 4.
ENDIF.
WHEN OTHERS.
l_len = l_len + 0.
ENDCASE.
* Ende einfgen
IF l_len GT l_s_col_width-width.
IF l_len GE l_maxwidth.
l_s_col_width-width = l_maxwidth.
ELSE.
l_s_col_width-width = l_len.
ENDIF.
ENDIF.
AT END OF x.
APPEND l_s_col_width TO c_t_col_widths.
ENDAT.
l_s_grid_last = l_s_grid.
ENDLOOP.
ENDFORM.
" sub_DETERMINE_COL_WIDTHS
*&---------------------------------------------------------------------*
*&
Form WRITE_GRID
*&---------------------------------------------------------------------*
FORM sub_write_grid CHANGING c_t_grid TYPE rrx1_t_grid.
DATA: l_s_grid
TYPE rrx1_s_grid,
l_s_grid2 TYPE rrx1_s_grid,
l_s_grid_last TYPE rrx1_s_grid,
l_tabix
TYPE i.
DATA: l_s_col_width TYPE g_s_col_width,
l_width
TYPE i,
l_position TYPE i,
l_x
TYPE i,
l_y
TYPE i,
l_max_x
TYPE i,
l_max_y
TYPE i,
l_help_position TYPE i,
l_cell_type TYPE c,
l_cell_text(50) TYPE c,
" MST Lnge unschn
l_cell_add(4) TYPE c.
" MST
g_start_row = sy-linno.
CLEAR: g_t_ranges[].
SORT c_t_grid BY y x.
LOOP AT c_t_grid INTO l_s_grid.
IF l_s_grid-y > l_max_y.
l_max_y = l_s_grid-y.
ENDIF.
IF l_s_grid-x > l_max_x.
l_max_x = l_s_grid-x.
ENDIF.
ENDLOOP.
l_tabix = 1.
READ TABLE c_t_grid INTO l_s_grid2 INDEX 1.
DO l_max_y TIMES.
l_y = sy-index.
DO l_max_x TIMES.
l_x = sy-index.
WHILE l_y > l_s_grid2-y
OR ( l_y = l_s_grid2-y
AND l_x > l_s_grid2-x ).
ADD 1 TO l_tabix.
READ TABLE c_t_grid INTO l_s_grid2 INDEX l_tabix.
IF sy-subrc NE 0.
EXIT.
ENDIF.
ENDWHILE.
IF l_s_grid2-y = l_y AND l_s_grid2-x = l_x.
l_s_grid = l_s_grid2.
ELSE.
CLEAR: l_s_grid.
l_s_grid-x = l_x.
l_s_grid-y = l_y.
l_s_grid-content = 'NN'.
ENDIF.
IF l_s_grid_last-y < l_s_grid-y.
g_row_hide = l_s_grid_last-y.
HIDE g_row_hide.
CLEAR l_position.
NEW-LINE.
ENDIF.
READ TABLE g_t_col_widths INTO l_s_col_width INDEX l_s_grid-x.
l_width = l_s_col_width-width.
l_position = l_position + l_width.
* format
* Ausgabeattribute in Abhngigkeit vom Cell-style setzen.
l_help_position = l_position + 20.
*
CHECK l_help_position LT sy-linsz.
IF l_s_grid-content NE l_s_grid_last-content.
PERFORM sub_set_format_attributes USING l_s_grid-content.
ENDIF.
l_cell_type = l_s_grid-content+1(1).
* Eingefgt zur Anzeige von Whrung/Menge.
CLEAR l_cell_add.
CASE l_s_grid-mwkz.
WHEN c_m.
IF l_s_grid-y NE 1.
"keine Zahlen in Zeile 1
l_cell_add = l_s_grid-unit.
ENDIF.
WHEN c_w.
IF l_s_grid-y NE 1.
"keine Zahlen in Zeile 1
l_cell_add = l_s_grid-currency.
ENDIF.
WHEN OTHERS.
CLEAR l_cell_add.
ENDCASE.
ENDFORM.
" sub_WRITE_GRID
*&--------------------------------------------------------------------*
*&
Form set_format_attributes
*&--------------------------------------------------------------------*
*
text
*---------------------------------------------------------------------*
*
-->I_CONTENT text
*---------------------------------------------------------------------*
FORM sub_set_format_attributes
USING i_content
TYPE rrx1_s_grid-content.
DATA: l_color
l_intensified
l_inverse
l_linetype
l_itemtype
TYPE c,
TYPE rs_bool,
TYPE rs_bool,
TYPE c,
TYPE c.
l_linetype = i_content+1(1).
l_itemtype = i_content+0(1).
CASE l_itemtype.
WHEN c_n.
CASE l_linetype.
WHEN c_t. l_color = 3.
CASE l_inverse.
WHEN rs_c_true.
WHEN rs_c_false.
ENDCASE.
CASE l_intensified.
WHEN rs_c_true.
WHEN rs_c_false.
ENDCASE.
CASE i_content+2(2).
WHEN '01'. l_color = 5.
WHEN '02'. l_color = 5.
WHEN '03'. l_color = 5.
WHEN '04'. l_color = 7.
WHEN '05'. l_color = 7.
WHEN '06'. l_color = 7.
WHEN '07'. l_color = 6.
WHEN '08'. l_color = 6.
WHEN '09'. l_color = 6.
ENDCASE.
CASE l_color.
WHEN 0. FORMAT COLOR COL_BACKGROUND.
WHEN 1. FORMAT COLOR COL_HEADING.
WHEN 2. FORMAT COLOR COL_NORMAL.
WHEN 3. FORMAT COLOR COL_TOTAL.
WHEN 4. FORMAT COLOR COL_KEY.
WHEN 5. FORMAT COLOR COL_POSITIVE.
WHEN 6. FORMAT COLOR COL_NEGATIVE.
WHEN 7. FORMAT COLOR COL_GROUP.
ENDCASE.
ENDFORM.
" sub_GET_FORMAT_ATTRIBUTES
*---------------------------------------------------------------------*
*
FORM sub_write_cell_col
*---------------------------------------------------------------------*
*
........
*
*---------------------------------------------------------------------*
* --> I_WIDTH
*
* --> I_COL
*
* --> L_TEXT
*
*---------------------------------------------------------------------*
"sub_write_cell_col
Related Content
RUN BEX QUERY
BEX In Background
Run BEX queries in background or batch