---
title: "Upload a Comma Delimited CSV file that contains commas in data"
author: "huang850625"
date: "2011-09-23T17:22:53Z"
tags: []
categories: ["行业应用"]
slug: "upload-a-comma-delimited-csv-file-that-contains-commas-in-data"
draft: false
lastmod: "2011-09-23T17:24:20Z"
id: 1179202
url: "https://wabaper.iteye.com/blog/1179202"
---

source:http://wiki.sdn.sap.com/wiki/display/Snippets/Upload+a+Comma+Delimited+CSV+file+that+contains+commas+in+data Some Comma Delimited CSV files will contain commas in the data fields and this causes problems in loading the file into our system. I don't think there is a standard function module to do this but I will share a small code snippet which will save someone to re-invent the wheel. Here is a sample of the comma delimited CSV text file, you can copy below text then paste in notepad and save as c:\\Temp\\Book1.csv file. 10,Shafiq,"Sacramento, CA" 11,Willie,"New York, NY" 12,Conner,"Seattle, WA" Here is the sample program which will read this file and store in a table that will preserve the commas in the city field: \[b]Upload from Local PC:\[/b] \[code="java"] TYPES: BEGIN OF kcde\_intern\_struc. INCLUDE STRUCTURE kcde\_cells. TYPES: END OF kcde\_intern\_struc. DATA: l\_intern TYPE TABLE OF kcde\_intern\_struc WITH HEADER LINE. DATA: BEGIN OF it\_output OCCURS 0, id(10) TYPE c, name(20) TYPE c, location(20) TYPE c, END OF it\_output. DATA: wa\_output LIKE LINE OF it\_output. DATA: v\_index TYPE i. FIELD-SYMBOLS : . CALL FUNCTION 'KCD\_CSV\_FILE\_TO\_INTERN\_CONVERT' EXPORTING i\_filename = 'C:\\Temp\\Book1.csv' i\_separator = ',' TABLES e\_intern = l\_intern EXCEPTIONS upload\_csv = 1 upload\_filetype = 2. LOOP AT l\_intern. MOVE : l\_intern-col TO v\_index. ASSIGN COMPONENT v\_index OF STRUCTURE wa\_output TO . MOVE : l\_intern-value TO . AT END OF row. APPEND wa\_output TO it\_output. CLEAR wa\_output. ENDAT. ENDLOOP. \[/code] \[b]Upload from Unix Server\[/b] \[code="java"]DATA: BEGIN OF itab\_upload OCCURS 0, str(4096), END OF itab\_upload. DATA: l\_intern TYPE TABLE OF kcde\_intern\_struc WITH HEADER LINE. OPEN DATASET p\_path FOR INPUT ENCODING UTF-8 IN TEXT MODE. DO. READ DATASET p\_path INTO itab\_upload. IF sy-subrc NE 0. EXIT. ENDIF. APPEND itab\_upload. ENDDO. CLOSE DATASET p\_path. PERFORM separated\_to\_intern\_convert IN PROGRAM saplkcde TABLES itab\_upload l\_intern USING ','. LOOP AT l\_intern. MOVE : l\_intern-col TO v\_index. ASSIGN COMPONENT v\_index OF STRUCTURE wa\_output TO . MOVE : l\_intern-value TO . AT END OF row. APPEND wa\_output TO it\_output. CLEAR wa\_output. ENDAT. ENDLOOP. \[/code]