How to load .csv file into an abap table
Hi,
Pls provide me with a sample code on how to load a .csv file (with column header and rows of data) into a table in sap.
Thank you!
Moderator Message: A google search would yield faster results, so search!
Edited by: Suhas Saha on Jan 16, 2012 5:30 PM
Hi,
Using GUI_upload convert file to internal table data.
Using the below statement separate header and data from CSV.
Read t_itab into wa_titab index 1.
delete t_itab from wa_itab.
Create an internal table with the structure same as 'CSV' file and use the below statement to separate.
loop at t_itab into wa_itab.
split wa_itab-rec at ',' into var1 var2 var3.
wa_output-v1 = var1.
wa_output-v2 = var2.
wa_output-v3 = var3.
append wa_output to t_output.
endloop.
Edited by: syamsundr on Jan 16, 2012 11:54 AM
Similar Messages
-
How to load CSV files into HANA
1.- Create an CSV file with your data
2.- Copy the file to dropbox/yourname inside the HANA box
3.- Create a table in HANA with the structure of your file
4.- create the control file BBB with the following information:
import data
into table XXX."YYY"
from 'ZZZ.csv'
record delimited by '\n'
fields delimited by ','
optionally enclosed by '"'
error log 'Text_Tables.err'
Where XXX is your schema, YYY is your HANA Table and ZZZ is your file
5.- Open an Script File and write the following:
LOAD FROM '/filer/dropbox/yourname/BBB.ctl';
where BBB is the name of your control file
Greetings,
Blag.With the recent upgrade to the HANA SP3...the method to upload files to HANA has been slightly changed...so here's the updated tutorial:
1.- Create an CSV file with your data
2.- Copy the file to the HANA Dev Center
3.- Open a FTP connection to ftp.sapdevcenter.com
(You can find the user name and password by doing a select to SYSTEM.FTP_SERVER)
and....*Don't paste the Username or password here or any other place!*
4.- Create a folder with your name on the FTP site and copy the file there
4.- Create a table in HANA with the structure of your file
5.- create the control file BBB with the following information:
import data
into table XXX."YYY"
from 'ZZZ.csv'
record delimited by '\n'
fields delimited by ','
optionally enclosed by '"'
error log 'Text_Tables.err'
Where XXX is your schema, YYY is your HANA Table and ZZZ is your file
5.- Open an Script File and write the following:
IMPORT FROM '/dropbox/yourname/BBB.ctl';
where BBB is the name of your control file
I just test it and it works...if it doesn't work for you, please let me know
Greetings,
Blag. -
*** Question How to load a file into BI-Integrated Planning and use WAD 7.0
Hi, I created an manual DTP upload to my planning infocube and it works fine. The transformation rules convert 0CALMONTH into the relevant Calendar and Fiscal characteristics. So all of my Time Characteristics are fine, both Calendar and Fiscal.
However, When using the "How to load a file into BI-Integrated Planning and use WAD 7.0" solution, only the Calendar Characteristics are populated and not the Fiscal. The upload application somehow knows to populate the 0CALMONTH2, 0CALQUART1, 0CALQUARTER, and 0CALYEAR.
How can I get the upload to populate my Fiscal Period Characteristics?
Would it be best to modify the "Upload Application, or can I write a planning function to update the fiscal characteristics, or some other way?
Thanks!My planning data is being uploaded via the SDN Planning File Upload Solution. What I did was end up modifiying the upload class ZCL_RSPLF_FILE_UPLOAD Method EXECUTE.
I added the following code if anyone is interested.
*{ INSERT BWDK902323 1
THIS SECTION OF CODE POPULATES THE FISCAL PERIOD CHARACTERISTICS
USING THE FISCAL YEAR VARIANT 'NK' AND THE CALENDAR MONTH/YEAR
FIELD-SYMBOLS <0FISCVARNT> TYPE /BI0/OIFISCVARNT. " Fiscal Year Variant
FIELD-SYMBOLS <0FISCYEAR> TYPE /BI0/OIFISCYEAR. " Fiscal Year
FIELD-SYMBOLS <0FISCPER> TYPE /BI0/OIFISCPER. " Fiscal Year/Period
FIELD-SYMBOLS <0FISCPER3> TYPE /BI0/OIFISCPER3. " Posting Period
FIELD-SYMBOLS <0CALMONTH> TYPE /BI0/OICALMONTH. " Calendar Month/Year
ASSIGN COMPONENT '0CALMONTH' OF STRUCTURE <L_S_DATA> TO <0CALMONTH>.
ASSIGN COMPONENT '0FISCPER' OF STRUCTURE <L_S_DATA> TO <0FISCPER>.
ASSIGN COMPONENT '0FISCVARNT' OF STRUCTURE <L_S_DATA> TO <0FISCVARNT>.
ASSIGN COMPONENT '0FISCPER3' OF STRUCTURE <L_S_DATA> TO <0FISCPER3>.
ASSIGN COMPONENT '0FISCYEAR' OF STRUCTURE <L_S_DATA> TO <0FISCYEAR>.
<0FISCVARNT> = 'NK'.
CALL FUNCTION 'FISCPER_FROM_CALMONTH_CALC'
EXPORTING
IV_CALMONTH = <0CALMONTH>
IV_PERIV = <0FISCVARNT>
IMPORTING
EV_FISCPER3 = <0FISCPER3>
EV_FISCPER = <0FISCPER>
EV_FISCYEAR = <0FISCYEAR>.
*} INSERT -
Uregnt - How to Load Flat File into BW-BPS using Web Browser
Hello,
We have followed the 'How to Load Flat File into BW-BPS using Web Browser' guide to build BSP web front-end to upload flat file. Everything works great but we have a requirement to populate the Planning Area Variables based on BSP drop down list with values. Does anyone know how to do this? We have the BSP coded with drop down list all we need to do now is populate variables. We can populate the variables through the planning level (hardcoded) but we need to populate them through the web interface.
Thanks,
GaryHello Gary,
We have acheived the desired result by not too a clean method but it works for us.
What we have done is, we have the link to load file in a page where the variables can be input. The user would then have the option to choose the link to load a file for the layout in that page.
By entering the variable values in the page, we are able to read the variables for the file input directly in the load program.
Maybe this approach might help.
Sunil -
How to load flat file into BW BPS
hi,
how to load flat file into BW BPS ?Have a read through this;
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/biw/g-i/how%20to%20load%20a%20flat%20file%20into%20bw-bps%20using%20a%20web%20browser.pdf -
Upload a .CSV File into an Internal table
Hi,
What are the parameters to be filled into the Function Modules "GUI_UPLOAD" and "ALSM_EXCEL_TO_INTERNAL_TABLE" to Upload a .CSV File into an internal table.
Please send a sample code to support this....
Regards,
Aadhi.Hi,
Check the below code.
TYPE-POOLS: truxs.
TYPES:
BEGIN OF ty_line,
vbeln LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
END OF ty_line.
*data: ty_Lines TYPE STANDARD TABLE of ty_Line WITH DEFAULT KEY.
DATA: itab TYPE STANDARD TABLE OF ty_line WITH DEFAULT KEY.
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 = 'd:\TEMP\test1.txt'
TABLES
data_tab = itab1
EXCEPTIONS
OTHERS = 1.
IF sy-subrc eq 0.
WRITE: 'Data downloaded successfully'.
ENDIF.
DATA: BEGIN OF IEXCEL OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA: END OF IEXCEL.
PARAMETERS: FILENM LIKE rlgrap-filename MEMORY ID M01,
NOHEADER AS CHECKBOX.
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = FILENM
i_begin_col = 1
i_begin_row = 1
i_end_col = 100
i_end_row = 30000
tables
intern = IEXCEL
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3.
if sy-subrc <> 0.
WRITE: / 'EXCEL UPLOAD FAILED ', FILENM, SY-SUBRC.
endif. -
Uploading CSV file into Webdynpro abap application
Hi all,
Please let me know the process of uploading .csv file in Webdynpro(ABAP) using FILE_UPLOAD UI element.
Thanks
SubathraHi,
you can use the following code ..........
assumiing the file cointain tow colums name and age
TYPES :
BEGIN OF str_itab,
name(10) TYPE c,
age(10) TYPE c,
END OF str_itab. DATA : t_table1 TYPE STANDARD TABLE OF str_itab,
i_data TYPE STANDARD TABLE OF string,
lo_nd_sflight TYPE REF TO if_wd_context_node,
lo_el_sflight TYPE REF TO if_wd_context_element,
l_string TYPE string,
fs_table TYPE str_itab,
l_xstring TYPE xstring,
fields TYPE string_table,
lv_field TYPE string. DATA : t_table TYPE if_main=>elements_data_tab,
data_table TYPE if_main=>elements_data_tab.
get single attribute
wd_context->get_attribute( EXPORTING name = `DATASOURCE` IMPORTING value = l_xstring ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
in_xstring = l_xstring
IMPORTING
out_string = l_string.
SPLIT l_string AT cl_abap_char_utilities=>newline INTO TABLE i_data.
Bind With table Element. LOOP AT i_data INTO l_string.
SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
READ TABLE fields INTO lv_field INDEX 1.
fs_table-name = lv_field.
READ TABLE fields INTO lv_field INDEX 2.
fs_table-age = lv_field. APPEND fs_table TO t_table1.
ENDLOOP.
lo_nd_sflight = wd_context->get_child_node( 'DATA_TAB' ).
lo_nd_sflight->bind_table( t_table1 ).
Thanks,
Shaik Shadulla.
Edited by: shaik shadulla on Jul 16, 2009 3:27 PM -
Issue loading CSV file into HANA
Hi,
From last couples of weeks i am trying to load my CSV file into HANA Table, but i am unable to succeed.
I am getting error "Cannot open Control file, /dropbox/P1005343/CRM_OBJ_ID.CTL". I have followed each and every step in SDN, still I could not load data into my HANA table.
FTP: /dropbox/P1005343
SQL Command:
IMPORT FROM '/dropbox/P1005343/crm_obj_id.ctl'
Error:
Could not execute 'IMPORT FROM '/dropbox/P1005343/crm_obj_id.ctl''
SAP DBTech JDBC: [2]: general error: Cannot open Control file, /dropbox/P1005343/crm_obj_id.ctl
Please help me on this
Regards,
PraneethHi All,
I have successfully loaded the file into HANA database in folder P443348 but while importing file, I am getting the following error message such as
SAP DBTECH JDBC: [2] (at 13) : general error: Cannot open Control file, "/P443348/shop_facts.ctl"
This is happening while I am executing the following import statement
IMPORT FROM '/P443348/shop_facts.ctl';
I have tried several options including changing the permissions of the folders and files to no success. As of now my folder has full access, which is 777
Any help would be greatly appreciated so that I can proceed further
Thanks
Vamsidhar -
How to convert csv files into java bean objects?
Hi,
I have a CSV file, I want to store the data availabale in that csv file into java bean, I am new to this csv files how can I convert CSV files into java beans.
Please help me.
Adavanced Thanks,
MahendraYou can use the java.io API to read (and write) files. Use BufferedReader to read the CSV file line by line. Use String#split() to split each line into an array of parts which were separated by comma (or semicolon). If necessary run some escaping of quotes. Finally collect all parts in a two-dimensional List of Strings or a List of Javabeans.
java.io API: [http://www.google.com/search?q=java.io+javase+api+site:sun.com]
java.io tutorial: [http://www.google.com/search?q=java.io+tutorial+site:sun.com]
Basic CSV parser/formatter example: [http://balusc.blogspot.com/2006/06/parse-csv-upload.html] -
Load CSV file into single CLOB
Hello Oracler,
is there a good way to load a csv file into PL/SQL a Clob variable ?
Iljahttp://download.oracle.com/docs/cd/B19306_01/appdev.102/b14258/d_lob.htm#i998978
-
Import a CSV-file into a new table?
hi, im trying to import a csv file into a new tabel, but i just cant make it work :-O. what are the steps to do that? im using sql developer version1.1.2.25.
thanks for helping :-)We do not support CSV import at this stage, we only support XLS import.
Regards
Sue -
How to load csv file in oracle table
Hi,
i have csv files to which i want to load the csv file data and table structure in oracle. my csv files on the window machine but database is runing on ibm aix.so how to do it please any one can help me about. thanks a lot in advance
i know th syntax below
$sqlldr userid=username/password control=<filename> log=<log filename>Hello,
Yes, with SQL*Loader you can do it.
But first you have to create a Table into your database with columns and datatype matching
the content of you "csv" file.
Then, you'll have to prepare a control file and use the option fields terminated by "," as it's
a "csv" format.
Then, you could execute your statement.
Please, find enclosed a link with some example about SQL*Loader and "csv" file:
[http://www.orafaq.com/wiki/SQL*Loader_FAQ]
Hope this help.
Best regards,
Jean-Valentin -
How to load PDF files into oracle database and display them in APEX
Hi All,
We have a requirement for loading the Loading PDF files (lots of PDf files) to the oracle database and then display the PDF files in the Oracel APEX report.
So that User can view the PDF files. Our current APEX verison is 3.2..
Please let me know how to implement it and where to find the sample application!
Thanks in advanced!
JaneThanks Tony for your quick response!
We need to load a lot of PDfs (history + current).
I have a questions about the SQL loader. I am trying to insert a pdf file into a table by following the oracle loading sample:
http://download.oracle.com/docs/cd/B10501_01/text.920/a96518/aload.htm
Example Data File: loader2.dat
This file contains the data to be loaded into each row of the table, articles_formatted.
Each line contains a comma separated list of the fields to be loaded in articles_formatted. The last field of every line names the file to be loaded in to the text column:
Ben Kanobi, plaintext,Kawasaki news article,../sample_docs/kawasaki.txt,
But i don't know to where should I put my pdf file on the server.
for example:
,../sample_docs/kawasaki.txt,
Where is the file 'kawasaki.txt'??
I try my local path, it didn't work. like c:\temp.
then I loaded teh PDf file into our server(/findev20/olmtest/orafin/11.5.7/olmtestcomn/temp) , and In my data file. I put the path
1, pdf_emp1,../findev20/olmtest/orafin/11.5.7/olmtestcomn/temp
but I got the error: the system can not find the file specified.
Where should I put the PDf files on the server and how to specify the path in the data file?
Thanks!
Jane -
Load CSV file into a table when a button is clicked by the user
Hello,
Can anyone please help me out with this issue, I have a form where in a user comes and uploads a CSV file and clicks a button, when the button is clicked - it should load the CSV file data into the database table for the corresponding columns.
Can anyone please suggest me a possible solution or an approach.
Thanks,
Orton
Edited by: orton607 on May 5, 2010 2:00 PMthanks fro replying.
I have tried your changes but its not working. One more question is that I am having one column which contains commas, when I tried to load the file its failing. I think its the problem with commas. So I have changed the code to use the replace function for that column, then also its not working. Can anyone please suggest a possible approach. Below is my source code for your reference.
DECLARE
v_blob_data BLOB;
v_blob_len NUMBER;
v_position NUMBER;
v_raw_chunk RAW(10000);
v_char CHAR(1);
c_chunk_len NUMBER := 1;
v_line VARCHAR2 (32767):= NULL;
v_data_array wwv_flow_global.vc_arr2;
v_rows NUMBER;
v_sr_no NUMBER := 1;
l_cnt BINARY_INTEGER := 0;
l_stepid NUMBER := 10;
BEGIN
delete from sample_tbl;
-- Read data from wwv_flow_files</span>
select blob_content into v_blob_data from wwv_flow_files
where last_updated = (select max(last_updated) from wwv_flow_files where UPDATED_BY = :APP_USER)
and id = (select max(id) from wwv_flow_files where updated_by = :APP_USER);
v_blob_len := dbms_lob.getlength(v_blob_data);
v_position := 1;
-- Read and convert binary to char</span>
WHILE ( v_position <= v_blob_len ) LOOP
v_raw_chunk := dbms_lob.substr(v_blob_data,c_chunk_len,v_position);
v_char := chr(hex_to_decimal(rawtohex(v_raw_chunk)));
v_line := v_line || v_char;
v_position := v_position + c_chunk_len;
-- When a whole line is retrieved </span>
IF v_char = CHR(10) THEN
-- Convert comma to : to use wwv_flow_utilities </span>
v_line := REPLACE (v_line, ',', ':');
-- Convert each column separated by : into array of data </span>
v_data_array := wwv_flow_utilities.string_to_table (v_line);
-- Insert data into target table </span>
EXECUTE IMMEDIATE 'insert into sample_tbl(col1..col12)
values (:1,:2,:3,:4,:5,:6,:7,:8,:9,:10,:11,:12)'
USING
v_sr_no,
v_data_array(1),
v_data_array(2),
v_data_array(3),
v_data_array(4),
v_data_array(5),
v_data_array(6),
v_data_array(7),
v_data_array(8),
REPLACE(v_data_array(9), ':', ','),
to_date(v_data_array(10),'MM/DD/YYYY'),
v_data_array(11);
-- Clear out
v_line := NULL;
v_sr_no := v_sr_no + 1;
l_cnt := l_cnt + SQL%ROWCOUNT;
END IF;
END LOOP;
COMMIT;
l_stepid := 20;
IF l_cnt = 0 THEN
apex_application.g_print_success_message := apex_application.g_print_success_message || ' Please select a file to upload ' ;
ELSE
apex_application.g_print_success_message := apex_application.g_print_success_message || 'File uploaded and processed ' || l_cnt || ' record(s) successfully.';
END IF;
l_stepid := 30;
EXCEPTION WHEN OTHERS THEN
ROLLBACK;
apex_application.g_print_success_message := apex_application.g_print_success_message || 'Failed to upload the file. '||REGEXP_REPLACE(SQLERRM,'[('')(<)(>)(,)(;)(:)(")('')]{1,}', '') ;
END;
Below is the function which I am using to convert hex to decimal
create or replace function hex_to_decimal( p_hex_str in varchar2 ) return number
is
v_dec number;
v_hex varchar2(16) := '0123456789ABCDEF';
begin
v_dec := 0;
for indx in 1 .. length(p_hex_str)
loop
v_dec := v_dec * 16 + instr(v_hex,upper(substr(p_hex_str,indx,1)))-1;
end loop;
return v_dec;
end hex_to_decimal;
thanks,
Orton -
How to load rm file into ordAudio column?
Hello everybody,
I made many attempts trying to insert aa.mp3(3.63Mb) and bb.rm(3.58Mb) file into ORDSYS.ordAudio column respectively with the same way.
the result is: aa.mp3 was inserted successfully, but the bb.rm was not. It showed the error message: "java.sql.SQLException:ORA-01401:inserted value too large for column"
Why? How can I insert *.rm into the ordAudio column?
main code are grateful.>
>
1.tonight, I made another trying to insert aa.mp3(3.63Mb) and bb.rm(3.58Mb) file into ORDSYS.ordAudio column respectively with the same way.
the result is: aa.mp3 was inserted successfully, but the bb.rm was not. It showed the error message: "java.sql.SQLException:ORA-01401:inserted value too large for column"
And the main code is as following:
private final static String EMPTY_AUDIO = "ordsys.ordaudio.init()"; //declare the EMPTY_AUDIO
stmt = (OraclePreparedStatement)conn.prepareStatement( //
"insert into TAB_NOAUDIT_AUDIO(NOAU_AU_SERIALNUMBER,"+
"NOAU_AU_TYPE,NOAU_AU_KEYWORD,NOAU_AU_FILENAME,"+
"NOAU_AU_MEDIA)"+
" values (?,?,?,?," + EMPTY_AUDIO +")" );
stmt.setString( 1, id );
stmt.setString( 2, filetype );
stmt.setString( 3, new String(keyword.getBytes("ISO8859-1")) );
stmt.setString( 4, new String(filename.getBytes("ISO8859-1")) );
// System.out.println("after 4th set..()!!");
stmt.executeUpdate();
stmt.close();
//load the audio media file into table
stmt=(OraclePreparedStatement)conn.prepareStatement(
"select NOAU_AU_MEDIA from TAB_NOAUDIT_AUDIO where NOAU_AU_SERIALNUMBER = ? for update" );
stmt.setString( 1, id );
rset = (OracleResultSet)stmt.executeQuery();
while(rset.next()) {
media = (OrdAudio)rset.getCustomDatum( 1, OrdAudio.getFactory());
File file = new File(filepath);
FileInputStream fStream = new FileInputStream(file);
media.loadDataFromInputStream(fStream);
// System.out.println("after aumedia.loadDataFromInputStream()!!");
fStream.close();
I don't know why the error occured?
Whether the rm file format is not recognized by ORDSYS.ordAudio or not?
How can i do next?
The error you get has nothing to do with the size of the media data. The error you are getting has to do with another field somewhere I think. The error you say has nothing to do with media data, but regular SQL.
It all depends on where the error is... Do you get the error on the media.loadDataFromInputStream(fStream);? I suspect, you are getting the error on the insert. and that id or filetype are too big for the column.
Could you tell me where the problem occurs? On the first insert? on the update?? I really can't debug with the amount of information here.
In general, for debugging problems, you need to break it down smaller to find the errror.
Pleas break down your insert to find the problem.
2.Would you mind telling me more detail step or code for copying ordAudio data from table
to another table with the same ORDSYS.ordAudio column property?
One media column to another would simply be
select sound into soundvar from oldtable where .....
insert into newtable(newsound) values (soundvar) where ...;
If from a lob....
select lob into lobvar from....
soundvar.source.localdata := lob;
soundvar.setlocal();
soundvar.setProperties();
Larry
Larry
Maybe you are looking for
-
Agent Commission Payment via Rebate settlement or any other
Hi Gurus, In our scenario: My client business is 90% through Agents (i.e both Domestic and Exports). Client wants to settle the commission 1. immediately after the invoice 2. monthly 3. quarterly. Could you please throw light immediately to address t
-
Hi All, I have an issue where i need to change the header name of the fields. I cannot find the header names such as planned start time, planned end time, planned group. But when i execute the program it appears. Kindly help me find the same in the b
-
Accounting transaction category RMWQRMWQ000000100000 is not defined.
Hi Friends I am getting the message while rejecting ASSET after checking in Quality inspection in QA11 T code. Accounting transaction category RMWQRMWQ it is asking FI-AA settings. Accounting transaction category RMWQRMWQ000000100000 is not defined.
-
Unable to read the libraries while running the form
Hi, I have a problem while I run my forms9i application. I had to change the default path of the libraries for my forms9i. I have set the libraries path as c:\9iLibraries in the registry under forms90_path. Also I set the "Start in" Property in the p
-
Power view reports in sharepoint 2013 :
How can i add alert and subscription for the power view report in sharepoint 2013 ?. and please let me know the difference beetween the performance point service and power view report. Please response fast.