2007 Jul 12 10:22 AM
Hi All,
I am downloading some data into a text file using GUI_DOWNLOAD FM.
Is there any way that i can add a header line on top of the file? In excel file, it is possible, but how do i do it for a *.txt file?
Regards
Abhijith H
2007 Jul 12 10:32 AM
hi..
add filetype also
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = f_name " a variable to hold file name
filetype = 'ASC'
Try changing the file type to DAT. Also make sure HAS_FIELD_SEPARATOR parameter is checked
<b>Reward points if useful</b>
Regards
ashu
2007 Jul 12 10:36 AM
Hello,
Check this.
* Headings: TEXT-U01 ... TEXT-U28
DO 28 TIMES.
CLEAR: L_F_INDEX,L_F_NAME,L_F_HEADERS.
L_F_INDEX = SY-INDEX.
CONCATENATE 'TEXT-U' L_F_INDEX INTO L_F_NAME.
ASSIGN (L_F_NAME) TO <FS_HEADER>.
L_F_HEADERS = <FS_HEADER>.
APPEND L_F_HEADERS TO L_T_HEADERS.
ENDDO.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
FILENAME = SP_FILE
FILETYPE = 'DAT'
TABLES
DATA_TAB = L_T_OUT
FIELDNAMES = L_T_HEADERS " Check Here
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_WRITE_ERROR = 2
INVALID_FILESIZE = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
Vasanth
2007 Jul 12 10:43 AM
Hi Abhijit,
You can follow the following approach:-
Let your data is in ITAB which u want to download to front end.
1) Create a data set using OPEN DATASET
2)Transfer text DATASET.
3) LOOP AT ITAB.
TRANSFER ITAB to DATASET.
ENDLOOP.
Now your data with header is in Application Server.
4) Now you use the transaction CG3Y and transfer data from App. Server to Presentation Server.
Reward points if helpful.
Regards
Srikanta Gope.
srikanta.gope@tcs.com
2007 Jul 12 10:46 AM
Hi Abhijith,
The below code is to download a CSV txt file. If u want u can get the excel file also by just changing the extension from .txt to .exl Try in the way given below. U will be able to insert the required header too and get the excel file also.
&----
*& Form gui_download
&----
Called to download the data selected
----
FORM gui_download.
*--Local data declaration
DATA : l_count TYPE i,
l_filename TYPE string.
FIELD-SYMBOLS: <fs_download>.
*--Count the number of fields
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE wa_inputtab TO <fs_download>.
IF sy-subrc <> 0.
EXIT.
ELSE.
l_count = l_count + 1.
ENDIF.
ENDDO.
CLEAR wa_inputtab.
*--Inserting the fields to the internal table in the required format
LOOP AT inputtab INTO wa_inputtab.
DO l_count TIMES. " Adding the delimiter in required places
ASSIGN COMPONENT sy-index OF STRUCTURE wa_inputtab TO
<fs_download>.
CONCATENATE wa_csv_output ',' <fs_download> INTO wa_csv_output.
ENDDO.
SHIFT wa_csv_output.
APPEND wa_csv_output TO itab_csv_output.
CLEAR wa_csv_output.
ENDLOOP.
*--Inserting the header to the internal table.
CONCATENATE 'DTAFF#' 'DTPRAC' 'DTPPP' 'DTREP' 'DTCURR' 'DTNATL'
'DTLAMT' 'DTFMD' 'DT$AMT' 'DTUNIT' 'DTRATE'
INTO wa_csv_output SEPARATED BY ','.
INSERT wa_csv_output INTO itab_csv_output INDEX 1.
IF NOT itab_csv_output[] IS INITIAL.
*--Download Data
l_filename = p_output.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = itab_csv_output
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
Reward if useful,
Cheers,
Sharadendu