Use a user-exit to download standard queries

Learn how to use a user-exit to download the results of standard queries to the application server.

Implement the user-exit to download the results of standard queries (SQ01) to application servers, while being run in a background.

The code to implement the user-exit is as below. First create a project through Xn CMOD say ZSQFILE, then use the enhancement assignment to include SQUE0001 SAP Query: Private data file.

Further implement the user exit EXIT_RSAQEXCE_001 in the component section.

Include ZXQUEU01 can have following code. Please change the <dir_name> to replace with your shared directory (Directory that you should be able to see / configure through Xn AL11).

Activate the user- exit. Now Run SQ01 (Background or foreground) and select 'Private file' (and not File Store) on the selction screen. It will download the results in a file on folder as specified in the code as <dir_name>.

Understand that a parameter can't be provided for file name, it will be downloaded as the description name of the query <.txt>. As it is, it will create a hash separated file -- but separator can be changed as required.

*&  Include           ZXQUEU01                                         *

DATA : lv_file_name LIKE rlgrap-filename.
DATA : empty(1),
fcnt TYPE i,
fpos TYPE i,
cfpos TYPE i,
feld(1000).
DATA: BEGIN OF ldata OCCURS 100.
INCLUDE STRUCTURE rsaqldata.
DATA: END OF ldata,
maxpos TYPE i.
FIELD-SYMBOLS: <feld>,
<cfeld>.
DATA: l_pos TYPE i.
data: l_length type i,
l_number(3) type n,
l_pos_f type i.
constants: bufferlength type i value 1024.
constants: lc_tab type X value '09'.
REFRESH ldata.
LOOP AT datatab.
CLEAR ldata.
maxpos = 0.
fcnt = 0.
LOOP AT listdesc WHERE lid = list_id.
fcnt = fcnt + 1.
IF fcnt <> 1.
l_pos = maxpos + 1.
IF l_pos > bufferlength.
APPEND ldata.
CLEAR ldata.
maxpos = 0.
ENDIF.
ldata+maxpos(1) = '#'.
maxpos = maxpos + 1.
ENDIF.
fpos = listdesc-flpos.
ASSIGN COMPONENT fpos OF STRUCTURE datatab TO <feld>.
WRITE <feld> TO feld.
SHIFT feld LEFT DELETING LEADING space.
l_length = strlen( feld ).
l_number = l_length.
l_pos_f = maxpos + l_length + 1.
if l_pos > bufferlength.
append ldata.
clear ldata.
maxpos = 0.
endif.
concatenate ldata feld into ldata.
maxpos = maxpos + strlen( l_number ) + 1 + l_length.
ENDLOOP.
APPEND ldata.
CLEAR ldata.
ENDLOOP.
CONCATENATE '<dir_name>' listtext(15) '.txt'
INTO lv_file_name.
OPEN DATASET lv_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ldata.
TRANSFER ldata TO lv_file_name.
ENDLOOP.
CLOSE DATASET lv_file_name.
This was first published in March 2005

Dig deeper on SAP Web applications

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchManufacturingERP

SearchOracle

SearchDataManagement

SearchAWS

SearchBusinessAnalytics

SearchCRM

SearchContentManagement

SearchFinancialApplications

Close