[转载]导入CSV文件到SAP HANA中(Importing CSV files into SAP HANA)

简介:

Procedure

SAP HANA is offering possibility to import content of CSV file into database table. This procedure is having several steps.

Required steps will be illustrated on following example. Goal is to create table USERS in SAP HANA database and populate is with following data:

UID LAST 
FIRST 
GENDER 
COUNTRY 

KROJZL 
TOMAS 

CZ 

ANN 
MARY 

UK 

DOE 
JOHN 

US 

1.) Planning of the import

At the beginning you should take some time to read through whole procedure and answer yourself questions like:

  • Which working directory you will use
  • In which schema you will create the table

In our example we will use working directory /dropbox/S0004108322 and we will create table USERS in schema S0004108322.

2.) Prepare CSV file containing the data you will be importing

You can use spreadsheet editor to export the data or you can produce the file manually.

Ensure that there are no empty lines (especially at the end of file) as these will lead to error during import of the file.

In our example we will create file USERS.CSV with following content.

USERS.CSV

  

3.) Create control file specifying details for the import command

Create new file and insert IMPORT DATA command that is having following syntax:


  

Detail explanation of syntax is described in SAP HANA SQL Reference Guide on page 119: https://service.sap.com/~sapidb/011000358700000604922011

In order to import our CSV file we will create following control file:

USERS.CTL

  

Notice that we intentionally skipped unnecessary optional parts of the command (like RECORD DELIMITED BY, FIELD DELIMITED BY and OPTIONALLY ENCLOSED BY). We do not need them because we are using default values (records are separated by ',' character and each record is on separate row).

Directories and file names on Linux operating system are case sensitive. Ensure that you used proper case for both working directory and referenced CSV file name.

4.) Upload prepared files on SAP HANA server

Either create files directly on HANA server or use FTP, SFTP or other approach to upload files to HANA server.

In case that you are working on SAP HANA sandbox system provided by SAP HANA Developer Center you can use following approach:

On HANA server run following query: SELECT * FROM SYSTEM.FTP_SERVER. You will be returned FTP hostname, user and password - do not share the user or password anywhere. 
Then you can use FTP application to connect from your notebook to target hostname (ftp.sapdevcenter.com). Be sure to configure FTP to login using obtained user and password.

Create new directory with user name you are having in SAP HANA to keep files organized and upload your files.

You might not be able to see the files you uploaded. If this is the case then you need to use your FTP application to adjust directory permissions.

Our example is illustrated by image below: 
ftp.png

5.) Create target tables in SAP HANA database

If target table does not exit you need to create it before executing the import.

This can be done either graphically or using SQL Editor. In our example we will create table using SQL statement CREATE TABLE.

SQL command to create table USERS

  

Detail explanation of syntax is described in SAP HANA SQL Reference Guide on page 85: https://service.sap.com/~sapidb/01100035870000060492201

6.) Execute the import

As last step you need to execute the import. Open SQL Editor and use IMPORT FROM statement to start the import.


  

In our example we will use following statement:

SQL statement to initiate the import

  

Detail explanation of syntax is described in SAP HANA SQL Reference Guide on page 119: https://service.sap.com/~sapidb/01100035870000060492201

You should see the result that statement was successfully executed and amount of affected rows is 0. This is expected result.

7.) Checking result of import

Review the content of error log file. Location of error log file is defined in control file (see step 3 of this procedure).

In our example we will need to use FTP client to see the error file. It is located in same directory where we uploaded CSV and CTL files - /S0004108322/USERS.ERR

Import was successful in case that error log file is empty.

8.) Checking content of target table

Use Open Content or Open Data Preview functions to check the data stored in table.

Alternatively you can execute following query in SQL Editor to calculate amount table rows: SELECT COUNT(*) FROM <schema>.<tablename>

专注于企业信息化,最近对股票数据分析较为感兴趣,可免费分享股票个股主力资金实时变化趋势分析工具,股票交流QQ群:457394862
分类:  SAP HANA

本文转自沧海-重庆博客园博客,原文链接:http://www.cnblogs.com/omygod/archive/2013/06/04/3117992.html,如需转载请自行联系原作者
目录
相关文章
|
16天前
|
开发者 数据处理 数据管理
SAP HANA 的不同类型
SAP HANA 的不同类型
34 9
SAP HANA 的不同类型
|
16天前
|
SQL 数据库 索引
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
17 1
关于 SAP ABAP REPOSRC 数据库表在 HANA 中的 DDL Definition
|
1月前
|
Linux 开发工具 开发者
关于 SAP HANA 开发那些事
关于 SAP HANA 开发那些事
22 0
|
2月前
|
Web App开发 JSON JavaScript
SAP UI5 应用程序小技巧 - 一键将 JSON 对象导出成本地 json 文件
SAP UI5 应用程序小技巧 - 一键将 JSON 对象导出成本地 json 文件
25 0
|
3月前
|
SQL 存储 数据可视化
SAP HANA 内存数据库不同类型的视图的应用场景介绍
SAP HANA 内存数据库不同类型的视图的应用场景介绍
52 0
|
6月前
|
供应链 数据挖掘 BI
什么是 SAP S/4HANA 的 VDM Layering Architecture 的 VDM Composite View
什么是 SAP S/4HANA 的 VDM Layering Architecture 的 VDM Composite View
37 0
|
6月前
|
供应链 数据挖掘 BI
什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Dimension View
什么是 SAP S/4HANA 的 VDM Layering Architecture 的 CDS Dimension View
36 0
|
16天前
|
数据库 存储 监控
什么是 SAP HANA 内存数据库 的 Delta Storage
什么是 SAP HANA 内存数据库 的 Delta Storage
16 0
什么是 SAP HANA 内存数据库 的 Delta Storage
|
12天前
|
Java BI API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
12 0
|
16天前
|
数据库 SQL 应用服务中间件
SAP ABAP CDS View 和 HANA CDS View 相同点和不同点辨析
SAP ABAP CDS View 和 HANA CDS View 相同点和不同点辨析
17 0
SAP ABAP CDS View 和 HANA CDS View 相同点和不同点辨析