2007 Mar 26 3:02 PM
Hello all,
Can any Plese tell Me,
How i will get text file with seperated by comma, from my internal table into local drive. i have used ws_download, gui_download.
Plese see example..
12,Rajesh
22,Kumar
in text file.
Thanks and Regard.
Rajesh.
2007 Mar 26 3:05 PM
Hi,
Please check the code below:
FORM upload_csv_file .
CLEAR gv_file.
gv_file = pa_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gv_file
filetype = 'ASC'
has_field_separator = gc_x
TABLES
data_tab = gt_dummy
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.
IF sy-subrc NE gc_zero_num.
MESSAGE e006.
ENDIF.
Check if the input file is blank
IF gt_dummy[] IS INITIAL.
MESSAGE i007.
LEAVE LIST-PROCESSING.
ENDIF.
To remove quotes in the table
LOOP AT gt_dummy INTO gs_dummy. "#EC CI_LOOP_INTO_WA
gv_tabix = sy-tabix.
DO.
IF gs_dummy CA '"'.
REPLACE '"' WITH '' INTO gs_dummy.
ELSE.
WRITE gs_dummy TO gs_dummy NO-GAP.
CONDENSE gs_dummy.
MODIFY gt_dummy INDEX gv_tabix FROM gs_dummy.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
Reading the file internal table to get Supplier Number.
READ TABLE gt_dummy INTO gs_dummy INDEX 1.
IF sy-subrc EQ gc_zero_num.
CLEAR:gs_wa,gv_str1,gv_str2.
SPLIT gs_dummy AT gc_y INTO: gv_str1 gv_str2, TABLE gt_itab.
ENDIF.
Reading the second string to get the supplier number.
READ TABLE gt_itab INTO gs_wa INDEX 2.
IF sy-subrc EQ gc_zero_num.
gs_header-lifnr = gs_wa.
ENDIF.
Conversion for Supplier Number.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = gs_header-lifnr
IMPORTING
output = gs_header-lifnr.
APPEND gs_header TO gt_header.
CLEAR: gs_header,gt_itab[].
Regards
Kannaiah
2007 Mar 26 6:38 PM
Hello Rajesh,
Unfortunately the GUI_DOWLOAD FM will only write a file (ASC) )with a
tab character as it's field separator. See the FM SAP documentation.
To accomplish your task I would use the CONCATENATE command to append all
of the fields that need to be in your output file into a single string type field, then write that string field to another itab and then download the itab of the string field.
Regards
Greg Kern
2007 Mar 26 6:58 PM
Hi,
Chekout this code:
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
DATA : file_name TYPE ibipparms-path,
l_filename TYPE string.
DATA: BEGIN OF lit_data OCCURS 0,
no(2) TYPE c,
name(10) TYPE c,
END OF lit_data.
DATA: BEGIN OF lit_table OCCURS 0,
no(2) TYPE c,
seperator(1) TYPE c VALUE ',',
name(10) TYPE c,
END OF lit_table.
lit_data-no = '12'.
lit_data-name = 'Rajesh'.
APPEND lit_data.
lit_data-no = '22'.
lit_data-name = 'Kumar'.
APPEND lit_data.
LOOP AT lit_data.
MOVE-CORRESPONDING lit_data TO lit_table.
APPEND lit_table.
ENDLOOP.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
file_name = file_name.
l_filename = file_name.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filename = l_filename
filetype = 'ASC'
TABLES
data_tab = lit_table.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
Let me know if you have any question.
Regards,
RS