11-11-2005 12:54 PM
Hi all,
Greetings!
I got a requirement to download output data to the presentation server as a CSV format. Actually i am using <b>GUI_DOWNLOAD</b>function module for downloading the data to the presentation server. I found ASC,DAT,BIN options only avialble using GUI_DOWNLOAD. If i am wrong please correct me.
Please let me know how to do this scenariao.
Thanking you
warm regards
Chand
11-11-2005 12:57 PM
Chand,
Go with 'ASC' in FILETYPE.
Thanks
Kam
Note: Allot points if the posting is worth
11-11-2005 1:05 PM
Use 'ASC' and try to give ur field sep in WRITE_FIELD_SEPARATOR.
Or alternatively u can append Comma inbetween ur records in ur internal table and download directly.
11-11-2005 1:05 PM
Hi
check this it may help you.
CALL FUNCTION 'GUI_DOWNLOAD'
exporting
filetype = 'ASC'
filename = 'C:DOWNLOAD.TXT'
reward points for helpfull and close the thread if your question is solved.
regards,
venu.
11-11-2005 1:16 PM
Hi
CSV file is ASCII (ASC) file, you should only put ';' as separator for your fields.
This is an example to insert the separtor:
CLASS FILE DEFINITION.
class-methods: insert_separator_char
importing
separator type string
record_in type any
exporting
record_out type string.
ENDCLASS.
class file implementation.
method insert_separator_char.
field-symbols: <fs_field> type any.
data: wa_string(10000) type c.
data: len_separ type i,
len_field type i,
len_string type i.
len_separ = strlen( separator ).
do.
assign component sy-index of structure record_in to <fs_field>.
if sy-subrc <> 0. exit. endif.
describe field <fs_field> length len_field in character mode.
write: <fs_field> to wa_string+len_string(len_field).
len_string = len_string + len_field.
write: separator(len_separ) to wa_string+len_string.
len_string = len_string + len_separ.
enddo.
len_string = strlen( wa_string ).
move wa_string(len_string) to record_out.
endmethod. "INSERT_SEPARATOR_CHAR
ENDCLASS.
DATA: BEGIN OF ITAB OCCURS 0,
FIELD1 LIKE ...
FIELD2 LIKE ....
FIELD3 LIKE .....
END OF ITAB.
DATA: BEGIN OF T_FILE OCCURS 0,
RECORD TYPE STRING
END OF T_FILE.
Write the record for CSV format:
LOOP AT ITAB.
CALL METHOD FILE=>INSERT_SEPARATOR_CHAR
EXPORTING
separator = ';'
record_in = itab
IMporting
record_out = T_FILE.
APPEND T_FILE.
ENDLOOP.
Here call fm GUI_DOWNLOAD for T_FILE
Max
11-13-2005 11:49 AM
Hi all,
Thankx for all your valuable suggestions.
Thanks max.
You mean to say after i am getting my final internal table contents then i will have to call this <b>CALL METHOD FILE=>INSERT_SEPARATOR_CHAR</b>OR Before also i will need to insert all the code what u sent to me like <b>CLASS FILE DEFINITION.</b>,,,,,,,<b>ENDCLASS</b>.
Please suggest me in this case. I will close this.
Thanking you
Best Regards
chand
11-13-2005 12:56 PM
Hi Chand
I've developed in a my Z-INCLUDE some routines to manage file (opening, closing....), I used OO Abap to develop them but you can use Abap if you want: it's the same.
Anyway I think your program has two main parts: one to load the data in an internal (file) table and one to download this table into your file.
Part of code to upload the data in file table:
A flat structure as file record
DATA: BEGIN OF FILE_RECORD,
FIELD1 ....
FIELD2 ....
FIELD2 ....
END OF FILE-RECORD.
Internal table to download the data into file
DATA: BEGIN OF FILE_DATA OCCURS 0,
RECORD TYPE STRING,
END OF FILE_DATA.
Fill the structure with data to transfer to file:
CLEAR FILE_RECORD.
FILE_RECORD-FIELD1 = .....
FILE_RECORD-FIELD2 = .....
..........................
FILE_RECORD-FIELDN = .....
Before appending the record to file table, insert
the simicolon
CALL METHOD FILE=>INSERT_SEPARATOR_CHAR
EXPORTING
SEPARATOR = ';'
RECORD_IN = FILE_RECORD
IMPORTING
RECORD_OUT = FILE_DATA.
As I wrote above, you can use ABAP creating a FORM:
PERFOM INSERT_SEPARATOR_CHAR USING ';'
FILE_RECORD
SPACE
FILE_DATA.
Append new record:
APPEND FILE_DATA.
After appending all record, create the file:
FILENAME = 'C:\MY_CSVFILE.CSV'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = FILENAME
TABLES
DATA_TAB = FILE_DATA
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
.
That's import is the code you insert in the routine to insert the semicolon between the fields.
So if you want to use OO Abap you have to create an your own class to create the method.
After the data declaration define the class. The class definition need two part: the definition and the implementation.
Here you indicate what your class can do
CLASS FILE DEFINITION.
PUBLIC SECTION.
CALL-METHOD: INSERT_SEPARATOR_CHAR
IMPORTING
SEPARATOR TYPE STRING
RECORD_IN TYPE ANY
NO_GAPS TYPE C DEFAULT SPACE
EXPORTING
RECORD_OUT TYPE STRING.
ENDCLASS.
Here yuo define how your class can work
CLASS LC_FILE IMPLEMENTATION.
METHOD INSERT_SEPARATOR_CHAR.
FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.
DATA: WA_STRING(10000) TYPE C.
DATA: LEN_SEPAR TYPE I,
LEN_FIELD TYPE I,
LEN_STRING TYPE I.
LEN_SEPAR = STRLEN( SEPARATOR ).
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE RECORD_IN
TO <FS_FIELD>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD.
WRITE: <FS_FIELD> TO WA_STRING+LEN_STRING
(LEN_FIELD).
LEN_STRING = LEN_STRING + LEN_FIELD.
WRITE: SEPARATOR(LEN_SEPAR) TO
WA_STRING+LEN_STRING.
IF NOT NO_GAPS IS INITIAL.
CONDENSE WA_STRING NO-GAPS.
LEN_STRING = STRLEN( WA_STRING ).
ELSE.
LEN_STRING = LEN_STRING + LEN_SEPAR.
ENDIF.
ENDDO.
LEN_STRING = STRLEN( WA_STRING ).
MOVE WA_STRING(LEN_STRING) TO RECORD_OUT.
ENDMETHOD.
ENDCLASS.
But if you aren't use to use OO Abap, you can create the routine as form, insert the code of method in this routine and you'll obtnain the same result:
FORM INSERT_SEPARATOR_CHAR
USING SEPARATOR TYPE STRING
RECORD_IN TYPE ANY
NO_GAPS TYPE C
RECORD_OUT TYPE STRING.
FIELD-SYMBOLS: <FS_FIELD> TYPE ANY.
DATA: WA_STRING(10000) TYPE C.
DATA: LEN_SEPAR TYPE I,
LEN_FIELD TYPE I,
LEN_STRING TYPE I.
LEN_SEPAR = STRLEN( SEPARATOR ).
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE RECORD_IN
TO <FS_FIELD>.
IF SY-SUBRC <> 0. EXIT. ENDIF.
DESCRIBE FIELD <FS_FIELD> LENGTH LEN_FIELD.
WRITE: <FS_FIELD> TO WA_STRING+LEN_STRING
(LEN_FIELD).
LEN_STRING = LEN_STRING + LEN_FIELD.
WRITE: SEPARATOR(LEN_SEPAR) TO
WA_STRING+LEN_STRING.
IF NOT NO_GAPS IS INITIAL.
CONDENSE WA_STRING NO-GAPS.
LEN_STRING = STRLEN( WA_STRING ).
ELSE.
LEN_STRING = LEN_STRING + LEN_SEPAR.
ENDIF.
ENDDO.
LEN_STRING = STRLEN( WA_STRING ).
MOVE WA_STRING(LEN_STRING) TO RECORD_OUT.
ENDFORM.
Max
Message was edited by: max bianchi