Implement the user-exit to download the results of standard queries (SQ01) to application servers, while being...
By submitting your email address, you agree to receive emails regarding relevant topic offers from TechTarget and its partners. You can withdraw your consent at any time. Contact TechTarget at 275 Grove Street, Newton, MA.
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,
DATA: BEGIN OF ldata OCCURS 100.
INCLUDE STRUCTURE rsaqldata.
DATA: END OF ldata,
maxpos TYPE i.
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'.
LOOP AT datatab.
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.
maxpos = 0.
ldata+maxpos(1) = '#'.
maxpos = maxpos + 1.
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.
maxpos = 0.
concatenate ldata feld into ldata.
maxpos = maxpos + strlen( l_number ) + 1 + l_length.
CONCATENATE '<dir_name>' listtext(15) '.txt'
OPEN DATASET lv_file_name FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ldata.
TRANSFER ldata TO lv_file_name.
CLOSE DATASET lv_file_name.