- 浏览: 174446 次
- 性别:
- 来自: 成都
文章分类
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:
Upload from Local PC:
Upload from Unix Server
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:
Upload from Local PC:
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 : <fs>. 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 <fs>. MOVE : l_intern-value TO <fs>. AT END OF row. APPEND wa_output TO it_output. CLEAR wa_output. ENDAT. ENDLOOP.
Upload from Unix Server
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 <fs>. MOVE : l_intern-value TO <fs>. AT END OF row. APPEND wa_output TO it_output. CLEAR wa_output. ENDAT. ENDLOOP.
发表评论
-
DISABLE button(FCODE) from the GUI-Status
2014-08-04 15:54 6331. Goto-> Attributes->Pus ... -
Handy SAP function module to automate user events
2013-11-28 09:49 752*Begin-Auto triggers ENTER comm ... -
set Billing block to blank for Sals Order
2013-04-17 15:16 820FM: SD_WF_ORDER_DEL_BILLING_BLO ... -
set Billing block to blank for Sals Order
2013-04-17 15:16 745FM: SD_WF_ORDER_DEL_BILLING_BLO ... -
Unpermitted combination of business object BUS2032 and sales doc. category H
2013-01-25 14:20 4135Q: create New Sales Order using ... -
Function Module: get all users who have specific role
2013-01-25 14:16 679CALL FUNCTION 'RSRA_USERS_O ... -
Create a SELECT-OPTIONS in a module pool screen
2012-03-07 15:35 1028source:http://abap-explorer.blo ... -
Converting OTF data from script to Spool Request
2012-03-06 17:25 0source:http://forums.sdn.sap.co ... -
Calculate the days, months and years between 2 dates.
2012-02-21 16:14 836FORM compute_2date_diff. DAT ... -
Retrieving Domain fixed values
2012-02-16 11:13 812source:http://www.saptechnical. ... -
If 1 equals 2, what’s the purpose?
2012-02-16 10:59 837source:http://sapport.blogspot. ... -
get status name for batch input session
2012-01-31 14:47 924Line 601 in program SAPMSBDC_CC ... -
create zip folder with cl_abap_zip
2011-12-05 18:11 1210REPORT ztest. DATA: gv_file ... -
MIRO
2011-11-29 10:39 2066from: http://help-sap.blogspot. ... -
Create Vendor or Customer_master Data
2011-11-23 16:22 2920To Create or Change Vendor_mast ... -
Pay attention to the following points when using append structures
2011-10-27 13:43 1311You cannot create append str ... -
Help Views
2011-10-20 10:46 739source:http://help.sap.com/saph ... -
What is the Different Types and Usage of Views
2011-10-19 23:06 849source:http://www.sap-img.com/a ... -
What is the difference between SET SCREEN and CALL SCREEN ?
2011-09-19 21:50 764source:http://www.saptechies.co ... -
cl_gui_frontend_services=>file_open_dialog
2011-09-09 09:21 1420CALL METHOD cl_gui_frontend_ser ...
相关推荐
在IT领域,尤其是在编程中,处理数据文件是常见的任务之一,CSV(Comma Separated Values)格式因其简单、通用而广泛使用。本话题主要聚焦于使用VC++在Visual Studio 2010环境下,以多字节字符集模式读取和写入CSV...
CSV(Comma Separated Values)文件是一种常见的数据存储格式,广泛用于数据交换和数据分析。它以纯文本形式存储表格数据,每一行代表一个记录,每个记录由若干个字段组成,字段之间通过逗号分隔。在编程领域,尤其...
CSV(Comma Separated Values)文件是一种常见的数据存储格式,广泛用于数据交换,尤其是在数据分析、统计和编程领域。Python作为一种强大的脚本语言,内置了处理CSV文件的强大工具,如`csv`模块和`pandas`库,使得...
csv_data = read_csv(csv_file) json_data = read_json(json_file) process_data(csv_data, json_data) if __name__ == '__main__': main() ``` 本文介绍了基于Python语言的CSV文件和JSON数据处理程序设计。...
通过Kaggle的HR数据集分析身边的小伙伴们为什么要离职,并基于数据集中的特征制定一个评分卡模型来预测会不会离职。 数据集解释 总览:该HR数据集收集了15000份数据,其中3571人离职,离职率23.8%。...
CSV(Comma Separated Values)文件因其简单易读的特性而成为批量数据上传的首选格式。然而,在实际操作过程中,不少用户遇到CSV文件上传失败的问题,这不仅影响工作效率,也可能导致数据丢失或错误。本文旨在深入...
CSV(Comma-Separated Values)格式是一种通用的文本文件格式,常用于存储表格数据,数据以逗号分隔,非常适合用于数据分析和数据交换。 在介绍如何导出数据之前,文档首先声明了这些应用示例不具有约束力,且不...
标题 "kc_house_data.csv.zip" 暗示我们正在处理一个关于房价预测的数据集,它被压缩在CSV格式的文件中。CSV(Comma Separated Values)是一种常见的数据存储格式,便于数据分析和处理。这个数据集是专为Jupyter ...
CSV(Comma Separated Values)是一种常见的数据交换格式,广泛应用于数据导入和导出,特别是在数据分析、数据库管理和电子表格处理中。CSV文件以其简单、通用的特性,成为了跨平台和跨应用程序之间交换数据的标准。...
在IT行业中,CSV(Comma Separated Values)文件是一种广泛使用的数据存储格式,因其简洁、通用和易于处理的特性而受到青睐。本示例“csv_example.rar”专注于在Windows操作系统环境下,通过编程语言来读取CSV文件。...
CSV(Comma Separated Values)是一种常见的数据存储格式,它以逗号分隔各个字段,便于数据交换和处理。在Python中,处理CSV文件是非常常见的任务,尤其在数据分析、数据导入导出等领域。本篇文章将深入探讨如何使用...
From there, the examples mirror the sqlite3 examples, including creating a database and table, loading data in a CSV input file into a database table, updat‐ ing records in a table using a CSV input...
在IT领域,尤其是在数据分析、数据处理或软件开发中,CSV(Comma Separated Values)文件是一种常见的数据存储格式。CSV文件以逗号分隔每一列数据,方便在各种应用程序之间交换数据。C++作为一种强大的系统级编程...
CSV(Comma Separated Values)文件是一种常见的数据存储格式,广泛用于数据交换和导入导出。这个压缩包“csv.rar”包含与CSV文件操作相关的资源,适用于C、C#和C++三种编程语言,主要涉及读取CSV文件并将其内容显示...
首先,"bank-data.csv"文件是一个CSV(Comma Separated Values)格式的文件,这种格式广泛应用于数据存储和交换,因为它简单、易于读写,并且可以被大多数数据分析软件和编程语言轻松处理。CSV文件以逗号分隔各个...
CSV(Comma Separated Values)是一种常见的数据存储格式,用于交换结构化数据。它以纯文本形式存储表格数据,每一行代表一个记录,列之间用逗号分隔。在这个主题中,我们将深入探讨如何利用Python处理CSV文件,包括...
$file = fopen('data.csv', 'r'); // 打开CSV文件 while (($data = fgetcsv($file)) !== FALSE) { // $data现在是一个包含CSV行数据的数组 echo "Name: {$data[0]}, Age: {$data[1]}, City: {$data[2]}\n"; } ...
CSV(Comma Separated Values)文件是一种常见的数据存储格式,广泛用于数据交换和数据分析。它以纯文本形式存储表格数据,每一行代表一个记录,每个字段由逗号分隔。在编程领域,处理CSV文件是常见的任务,尤其在...
在IT行业中,数据处理是一项至关重要的任务,而Python作为一种强大的编程语言,因其简洁的语法和丰富的库支持,常被用于处理各种数据格式,包括CSV(Comma Separated Values)文件。CSV文件是一种常见的数据存储格式...