‎2008 Apr 05 10:19 AM
I have a requirement to donload report in background job . for which i have used open dataset to store my output in application server on a particular path . now my output is stored in application server . Now as per user requirment
when user can use the download button on the screen
i have to read the data from application server and have to download it to the user system path mentioned . Please suggest how can i code this or the logic to proceed about this .
i tried to read this with open dataset in input mode but how can i code for the path in the application server . and how can i move forward please suggest.
Regards
Arun.
‎2008 Apr 05 10:50 AM
An option is the let the user enter the path from the application server and use this as a variable for
OPEN DATASET lv_dataset FOR INPUT ....
Read your data into in internal table with
do.
read datase into your work area.
append workarea to internal table.
enddo.
Next you will have to use method cl_frontend_services=>gui_download to download data from application server to frontend (desktop).
Another option would be to create logical filepaths using transaction FILE. You can then create a (logical) name for your filepath and assign in to the physical file path on the server.
‎2008 Apr 05 10:50 AM
An option is the let the user enter the path from the application server and use this as a variable for
OPEN DATASET lv_dataset FOR INPUT ....
Read your data into in internal table with
do.
read datase into your work area.
append workarea to internal table.
enddo.
Next you will have to use method cl_frontend_services=>gui_download to download data from application server to frontend (desktop).
Another option would be to create logical filepaths using transaction FILE. You can then create a (logical) name for your filepath and assign in to the physical file path on the server.
‎2008 Apr 05 10:59 AM
Hi Mickey ,
Thanks for the response but can you please explain me in more detail about transaction FILE . how effectively can i use it . actually let me explain my situation more clearly .
user 1 run the background job his file will be stored in application server as /path/user1.xls .
another user also can run it in background his will be stored as /path/user2 .xls .
now on next day user 2 will come he will push download button
on screen .
at this moment how can read from application server and which path will i use for open dataset how to handle it .
Regards
Arun
‎2008 Apr 05 11:30 AM
With transaction FILE you can create a logical name for you physical file path on the application server, for example:
Logical Filepath = MY_FILE_PATH.
You can then assign this name to the physical file path, which in your case would just be /path/.
If the number of users which are going to use this functionality, than it would even be an option to create a file path using a variable, This variable will then represent the user name for example. Something like this:
/path/user1/file.xls
and
/path/user2/file.xls
Don´t do this if you have for example 100 users, cause than you would have to create to many file paths on your servers.
So now, when the user wants to upload the data from the application server and download it locally, this should be done (depending on the name of the file of course, always the same??).
Click button download:
1. There is a function module you can use (don't know the exact name, and I don't have any system at hand right now to tell you), something like LOGICALPATHDETERMIN or DETERLOGPATH, not quite sure. This function module has as input amongst others the logical file path you defined in transaction FILE and the name of the file (userx.xls). As output the physical file path and file name will be given.
3. Use this variable (path and name) as for OPEN DATASET lv_path_and_name.
DO.
READ DATASET lv_patha_and_name FOR INPUT IN TEXT MODE ENCODING DEFAULT into workarea.
if sy-subrc is initial.
append workarea to internal table.
else.
exit.
endif.
ENDDO.
Use the internal table in method I've given you earlier.
So when a certain user logs on, you know its user name, which will be the name of the file also (or it's incorporated into your filepath). The user name will be the variable. Put this in a lv_filename together with the extension and you will have userx.xls. This is input for above mentioned function module which will give you the entire pyshical file path and name. This is your input for OPEN and READ DATASET.
Hope this makes sense. Good luck.
‎2008 Apr 05 10:58 AM
Hi Arun,
Check the below sample code
&---------------------------------------------------------------------
*& Report ZTESTPROGRAMFORDOWNLOAD
*&
&---------------------------------------------------------------------
*&
*&
&---------------------------------------------------------------------
report ztestprogramfordownload.
tables:zupload.
data:it_pa0002(200).
types: begin of ty_pa0002 ,
pernr like pa0002-pernr,
begda like pa0002-begda,
endda like pa0002-endda,
vorna like pa0002-vorna,
nachn like pa0002-nachn,
end of ty_pa0002.
data:begin of it_error occurs 0 ,
pernr like pa0000-pernr,
end of it_error .
data:it_final type standard table of ty_pa0002 with header line.
data:it_temp type standard table of ty_pa0002 with header line.
parameters:p_file like rlgrap-filename default 'F:\usr\sap\EC6\DVEBMGS00\work\entiraledu1'.
start-of-selection.
open dataset p_file for input in text mode encoding default.
do.
read dataset p_file into it_pa0002.
if sy-subrc = 0.
it_final-pernr = it_pa0002+0(8).
it_final-begda = it_pa0002+18(8).
it_final-endda = it_pa0002+36(8).
it_final-vorna = it_pa0002+54(40).
it_final-nachn = it_pa0002+104(40).
append it_final.
clear it_final.
else.
exit.
endif.
enddo.
if not it_final[] is initial.
sort it_final by pernr begda descending.
delete adjacent duplicates from it_final comparing pernr .
select pernr
begda
endda
vorna
nachn
from pa0002
into table it_temp
for all entries in it_final
where pernr = it_final-pernr.
endif.
loop at it_temp.
zupload-pernr = it_temp-pernr.
zupload-begda = it_temp-begda.
zupload-endda = it_temp-endda.
zupload-vorna = it_temp-vorna.
zupload-nachn = it_temp-nachn.
insert zupload.
clear it_temp.
clear zupload.
endloop.
close dataset p_file.Reward points if useful
Lakshmiraj
‎2008 Apr 05 10:59 AM
Hi,
Sample code for uploading file :
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
data: ld_filename type string ;
ld_filename = 'c:\demo.txt'.
call function 'GUI_DOWNLOAD'
exporting
filename = ld_filename
filetype = 'ASC'
tables
data_tab = IT_RECORD[]
exceptions
file_open_error = 1
file_write_error = 2
others = 3.
Hope this helps.
Regards
Sourabh Verma