设为首页 收藏本站
查看: 556|回复: 0

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

[复制链接]

尚未签到

发表于 2015-9-18 11:51:59 | 显示全部楼层 |阅读模式
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               
                        1               
          KROJZL               
          TOMAS               
          M               
          CZ               
                        2               
          ANN               
          MARY               
          F               
          UK               
                        3               
          DOE               
          JOHN               
          M               
          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.
  
                   DSC0000.png           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   
     1,KROJZL,TOMAS,M,CZ
2,ANN,MARY,F,UK
3,DOE,JOHN,M,US

3.) Create control file specifying details for the import command
  Create new file and insert IMPORT DATA command that is having following syntax:





[IMPORT DATA]
INTO TABLE <schema>.<tablename> [(<field specs>)]
FROM <os_data_filename>
[RECORD DELIMITED BY '<eor>']
[FIELDS [DELIMITED BY '<eoc>']
[OPTIONALLY ENCLOSED BY '<moq>']]
[ERROR LOG <os_bad_filename>]

  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


IMPORT DATA
INTO TABLE S0004108322.USERS
FROM '/dropbox/S0004108322/USERS.CSV'
ERROR LOG '/dropbox/S0004108322/USERS.ERR'

  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:


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


CREATE COLUMN TABLE S0004108322.USERS (
UID INTEGER PRIMARY KEY,
LAST NVARCHAR(20) NOT NULL,
FIRST NVARCHAR(20) NOT NULL,
GENDER VARCHAR(1) NOT NULL,
COUNTRY VARCHAR(2) NOT NULL
)

  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.





IMPORT FROM <control_file>
WITH [THREADS <thread_num>] [BATCH <batch_size>]
WITH TABLE LOCK [WITHOUT TYPE CHECK]

  In our example we will use following statement:




SQL statement to initiate the import


IMPORT FROM '/dropbox/S0004108322/USERS.CTL'
  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>
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-115349-1-1.html 上篇帖子: SAP Finance (FI) Module Intro 下篇帖子: SAP财务会计结构 (转载)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表