‎2006 Jul 25 10:48 AM
how to upload flat file in CSV(comma seperated) format into sap internal table
‎2006 Jul 25 10:51 AM
Use GUI_UPLOAD program to upload data into a flat type internal table.
Then use spilt statement to get the csv file into correspoding fields of an itab.
data: begin of itab occurs 0,
field(500),
end of itab.
data: begin of itab_new occurs 0,
field1(10),
field2(20),
field3(25),
field4(06),
end of itab.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = filename
FILETYPE = file_type
TABLES
DATA_TAB = itab
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.
loop at itab.
split itab at ',' into itab_new-field1 itab_new-field2
itab_new-field3 itab_new-field4.
append itab_new.
Clear itab_new.
endloop.
‎2006 Jul 25 10:52 AM
HelLo,
Like this
Data: begin of itab occurs 0,
data(2000),
end of itab.
Call ws_upload or GUI_UPLOAD
Then split your data into your final internal table.
loop at itab.
split itab-data at ',' into itab1-f1, itab1-f2.
endloop.
Regards,
Naimesh
‎2006 Jul 25 10:56 AM
Check the code,
REPORT ZCSV.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: p_ifile TYPE dxfile-filename.
SELECTION-SCREEN END OF BLOCK B1.
DATA : BEGIN OF itab OCCURS 0,
str TYPE string,
END OF itab,
DATA : L_FILE TYPE STRING.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_IFILE.
PERFORM HELP_INPUT_FILE.
START-OF-SELECTION.
CLEAR L_FILE.
l_file = p_ifile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
TABLES
data_tab = itab
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.
FORM HELP_INPUT_FILE .
DATA: LT_FILE_TABLE TYPE FILETABLE,
LA_FILE_TABLE LIKE LINE OF LT_FILE_TABLE,
L_RC TYPE I,
L_PCDSN TYPE CFFILE-FILENAME.
REFRESH LT_FILE_TABLE.
CLEAR LA_FILE_TABLE.
CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG
CHANGING
FILE_TABLE = LT_FILE_TABLE
RC = L_RC.
READ TABLE LT_FILE_TABLE INTO LA_FILE_TABLE INDEX 1.
L_PCDSN = LA_FILE_TABLE-FILENAME.
MOVE L_PCDSN TO P_IFILE.
ENDFORM. " help_input_file
Loop at itab.
write : itab-str.
endloop.
‎2006 Jul 25 11:01 AM
Hi Maruthi,
Welcome to SDN,
Please try the following FM
<b>SAP_CONVERT_TO_CSV_FORMAT</b>
Hope this will solve ur problem.
TYPE-POOLS:TRUXS.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN
LIKE VBAP-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.
DATA:
ITAB1 TYPE TRUXS_T_TEXT_DATA.
SELECT VBELN POSNR UP TO
10 ROWS FROM VBAP INTO TABLE ITAB.
CALL FUNCTION
'SAP_CONVERT_TO_CSV_FORMAT'
EXPORTING
I_FIELD_SEPERATOR = ';'
TABLES
I_TAB_SAP_DATA = ITAB
CHANGING
I_TAB_CONVERTED_DATA = ITAB1
EXCEPTIONS
CONVERSION_FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO WITH SY-MSGV1
SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:TEMPtest.txt'
TABLES
DATA_TAB = ITAB1
EXCEPTIONS
OTHERS = 1.
Regards ,
Ranjit .
Please Mark the Hlpful Answer.
Message was edited by: Ranjit Thakur
‎2006 Jul 25 11:14 AM
Hi,
i got this idea, but i want in single shot. I mean using function module or changing parameters of the Gui_upload.
Thanks.
‎2006 Jul 25 11:17 AM
Use the FM 'GUI_UPLOAD' and the contents of your file will be stored in the internal table in the single shot.You just have to pass the File name and the internal table name in which you want to store the data.Go through my code.
Just pass the path of the file 'C:\ABC.CSV' in place of l_file in the FM GUI_UPLOAD in my code.
Message was edited by: mukesh kumar
‎2006 Jul 25 11:22 AM
Hii Maruthi ,
Other way could be ..
open CSV fiel in Excel,
save the file as .XLS and
use FM
CALL FUNCTION <b>'ALSM_EXCEL_TO_INTERNAL_TABLE'</b>
EXPORTING
filename = p_inp " file name
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 65536
TABLES
intern = l_t_excel
EXCEPTIONS
inconsistent_parameters = 1
upload_ole = 2
OTHERS = 3.Revert back for more help
Regards
Naresh