Use a user-exit to download standard queries

Use a user-exit to download standard queries

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

    Requires Free Membership to View

    When you register, you will start receiving targeted emails from my award-winning team of editorial writers. Our goal is to keep you informed on the hottest topics and biggest challenges faced by SAP professionals today.

    Hannah Smalltree, Editorial Director

    By submitting your registration information to SearchSAP.com you agree to receive email communications from TechTarget and TechTarget partners. We encourage you to read our Privacy Policy which contains important disclosures about how we collect and use your registration and other information. If you reside outside of the United States, by submitting this registration information you consent to having your personal data transferred to and processed in the United States. Your use of SearchSAP.com is governed by our Terms of Use. You may contact us at webmaster@TechTarget.com.


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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.