Load XML-data from large file into plain table
We have to load data from an XML file to a relational table row by row.
The structure of the data is very simple:
<ROOT>
<repReport>
<KNZ>XY</KNZ>
<LA>test123</LA>
<Ident>AA20</Ident>
</repReport>
<repReport>
</repReport>
</ROOT>.
The table econtains the fields KNZ, LA, Ident, ...
If the file is small the following PL/SQL-code works fine:
CREATE OR REPLACE PROCEDURE Loadxml_Epd AS
fil BFILE ;
len INTEGER;
insrow INTEGER;
ctxHdl NUMBER;
buffer_c CLOB ;
amt NUMBER := dbms_lob.lobmaxsize;
src_offset NUMBER := 1 ;
dst_offset NUMBER := 1 ;
lang_ctx NUMBER := dbms_lob.default_lang_ctx;
warning NUMBER;
errNo NUMBER;
errMsg VARCHAR2(1999);
BEGIN
fil := BFILENAME('XML_DIR','200412MKBReport.xml');
DBMS_LOB.OPEN(fil, DBMS_LOB.LOB_READONLY);
len := DBMS_LOB.GETLENGTH(fil);
INSERT INTO INIT_CLOB(init) VALUES( EMPTY_CLOB())
RETURNING init INTO buffer_c;
dbms_lob.loadfromfile(buffer_c,fil, amt, dst_offset, src_offset);
ctxHdl := dbms_xmlsave.newContext ('SST_XML_EPD');
dbms_xmlsave.setRowTag (ctxHdl , 'repReport');
dbms_xmlsave.SetIgnoreCase(ctxHdl , 1);
dbms_xmlsave.SetSqlToXmlnameEscaping (ctxHdl , TRUE);
dbms_xmlsave.propagateOriginalException(ctxHdl , TRUE);
dbms_xmlsave.SetCommitBatch(ctxHdl , 1);
dbms_xmlsave.SetBatchSize(ctxHdl , 1);
insrow := DBMS_XMLSAVE.insertXML(ctxHdl,buffer_c);
DBMS_OUTPUT.PUT_LINE('Anzahl Sätze:' || TO_CHAR(insrow,'999999999'));
IF DBMS_LOB.ISOPEN(fil) = 1 THEN
DBMS_LOB.CLOSE(fil);
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE);
errMsg := SQLERRM;
DBMS_OUTPUT.PUT_LINE(SUBSTR(errMsg,1,2000));
IF DBMS_LOB.ISOPEN(fil) = 1 THEN
DBMS_LOB.CLOSE(fil);
END IF;
END;
But if the file is larger (50 MB in our case) this does not work. In various documents we found that we have to use another sort of XML-parser but we did not find any example how this is really done.
Does anybody have an example how to load this data that is as simple as our problem?
We have to load data from an XML file to a relational table row by row.
The structure of the data is very simple:
<ROOT>
<repReport>
<KNZ>XY</KNZ>
<LA>test123</LA>
<Ident>AA20</Ident>
</repReport>
<repReport>
</repReport>
</ROOT>.
The table econtains the fields KNZ, LA, Ident, ...
If the file is small the following PL/SQL-code works fine:
CREATE OR REPLACE PROCEDURE Loadxml_Epd AS
fil BFILE ;
len INTEGER;
insrow INTEGER;
ctxHdl NUMBER;
buffer_c CLOB ;
amt NUMBER := dbms_lob.lobmaxsize;
src_offset NUMBER := 1 ;
dst_offset NUMBER := 1 ;
lang_ctx NUMBER := dbms_lob.default_lang_ctx;
warning NUMBER;
errNo NUMBER;
errMsg VARCHAR2(1999);
BEGIN
fil := BFILENAME('XML_DIR','200412MKBReport.xml');
DBMS_LOB.OPEN(fil, DBMS_LOB.LOB_READONLY);
len := DBMS_LOB.GETLENGTH(fil);
INSERT INTO INIT_CLOB(init) VALUES( EMPTY_CLOB())
RETURNING init INTO buffer_c;
dbms_lob.loadfromfile(buffer_c,fil, amt, dst_offset, src_offset);
ctxHdl := dbms_xmlsave.newContext ('SST_XML_EPD');
dbms_xmlsave.setRowTag (ctxHdl , 'repReport');
dbms_xmlsave.SetIgnoreCase(ctxHdl , 1);
dbms_xmlsave.SetSqlToXmlnameEscaping (ctxHdl , TRUE);
dbms_xmlsave.propagateOriginalException(ctxHdl , TRUE);
dbms_xmlsave.SetCommitBatch(ctxHdl , 1);
dbms_xmlsave.SetBatchSize(ctxHdl , 1);
insrow := DBMS_XMLSAVE.insertXML(ctxHdl,buffer_c);
DBMS_OUTPUT.PUT_LINE('Anzahl Sätze:' || TO_CHAR(insrow,'999999999'));
IF DBMS_LOB.ISOPEN(fil) = 1 THEN
DBMS_LOB.CLOSE(fil);
END IF;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLCODE);
errMsg := SQLERRM;
DBMS_OUTPUT.PUT_LINE(SUBSTR(errMsg,1,2000));
IF DBMS_LOB.ISOPEN(fil) = 1 THEN
DBMS_LOB.CLOSE(fil);
END IF;
END;
But if the file is larger (50 MB in our case) this does not work. In various documents we found that we have to use another sort of XML-parser but we did not find any example how this is really done.
Does anybody have an example how to load this data that is as simple as our problem?
Similar Messages
-
How to load the data from excel file into temprory table in Forms 11g?
Hi
How to Load the data from excel file(Extension is .CSV) into the temporary table of oracle in Forms11g.
My Forms Version is - Forms [64 Bit] Version 11.1.2.0.0 (Production)
Kindly Suggest the Solution.
Regards,
SachinDeclare
v_full_filename varchar2(500);
v_server_path varchar2(2000);
v_separator VARCHAR2(1);
v_filename VARCHAR2(400);
filename VARCHAR2 (100);
v_stop_load varchar2 (2000);
v_rec_error_log varchar2(4000);
v_error_log varchar2(4000);
ctr NUMBER (12);
cols NUMBER (2);
btn number;
RES BOOLEAN;
application ole2.obj_type;
workbooks ole2.obj_type;
workbook ole2.obj_type;
worksheets ole2.obj_type;
worksheet ole2.obj_type;
cell ole2.obj_type;
cellType ole2.OBJ_TYPE;
args ole2.obj_type;
PROCEDURE olearg
IS
args ole2.obj_type;
BEGIN
args := ole2.create_arglist;
ole2.add_arg (args, ctr);
ole2.add_arg (args, cols);
cell := ole2.get_obj_property (worksheet, 'Cells', args);
ole2.destroy_arglist (args);
END;
BEGIN
v_full_filename := client_get_file_name(directory_name => null
,file_name => null
,file_filter => 'Excel files (*.xls)|*.xls|'
||'Excel files (*.xlsx)|*.xlsx|'
,message => 'Choose Excel file'
,dialog_type => null
,select_file => null
If v_full_filename is not null Then
v_separator := WEBUTIL_CLIENTINFO.Get_file_Separator ;
v_filename := v_separator||v_full_filename ;
:LOAD_FILE_NAME := substr(v_filename,instr(v_filename,v_separator,-1) + 1);
RES := Webutil_File_Transfer.Client_To_AS(v_full_filename,"server_path"||substr(v_filename,instr(v_filename,v_separator,-1) + 1));
--Begin load data from EXCEL
BEGIN
filename := v_server_path||substr(v_filename,instr(v_filename,v_separator,-1) + 1); -- to pick the file
application := ole2.create_obj ('Excel.Application');
ole2.set_property (application, 'Visible', 'false');
workbooks := ole2.get_obj_property (application, 'Workbooks');
args := ole2.create_arglist;
ole2.add_arg (args, filename); -- file path and name
workbook := ole2.get_obj_property(workbooks,'Open',args);
ole2.destroy_arglist (args);
args := ole2.create_arglist;
ole2.add_arg (args, 'Sheet1');
worksheet := ole2.get_obj_property (workbook, 'Worksheets', args);
ole2.destroy_arglist (args);
ctr := 2; --row number
cols := 1; -- column number
go_block('xxx');
FIRST_RECORD;
LOOP
--Column 1 VALUE --------------------------------------------------------------------
olearg;
v_stop_load := ole2.get_char_property (cell, 'Text'); --cell value of the argument
:item1 := v_stop_load;
cols := cols + 1;
--Column 2 VALUE --------------------------------------------------------------------
olearg;
:item2 := ole2.get_char_property (cell, 'Text'); --cell value of the argument
cols := cols + 1;
--<and so on>
ole2.invoke (application, 'Quit');
ole2.RELEASE_OBJ (cell);
ole2.RELEASE_OBJ (worksheet);
ole2.RELEASE_OBJ (worksheets);
ole2.RELEASE_OBJ (workbook);
ole2.RELEASE_OBJ (workbooks);
ole2.RELEASE_OBJ (application);
END;
--End load data from EXCELPlease mark it as answered if you helped. -
Loading data from .csv file into Oracle Table
Hi,
I have a requirement where I need to populate data from .csv file into oracle table.
Is there any mechanism so that i can follow the same?
Any help will be fruitful.
Thanks and regardsYou can use Sql Loader or External tables for your requirement
Missed Karthick's post ...alredy there :)
Edited by: Rajneesh Kumar on Dec 4, 2008 10:54 AM -
How to load the data from excel file into table in oracle using UTL_FI
How to load the data from excel file into table in oracle
and from table to excel file
using UTL_FILE package
Please give me some exampleThis is something i tried in oracle apex
http://avdeo.com/2008/05/21/uploading-excel-sheet-using-oracle-application-express-apex/
Regards,
CKLP -
How to load the data from .csv file to oracle table???
Hi,
I am using oracle 10g , plsql developer. Can anyone help me in how to load the data from .csv file to oracle table. The table is already created with the required columns. The .csv file is having about 10lakh records. Is it possible to load 10lakh records. can any one please tell me how to proceed.
Thanks in advance981145 wrote:
Can you tell more about sql * loader??? how to know that utility is available for me or not??? I am using oracle 10g database and plsql developer???SQL*Loader is part of the Oracle client. If you have a developer installation you should normally have it on your client.
the command is
sqlldrType it and see if you have it installed.
Have a look also at the FAQ link posted by Marwin.
There are plenty of examples also on the web.
Regards.
Al -
Loading data from .csv file into existing table
Hi,
I have taken a look at several threads which talk about loading data from .csv file into existing /new table. Also checked out Vikas's application regarding the same. I am trying to explain my requirement with an example.
I have a .csv file and I want the data to be loaded into an existing table. The timesheet table columns are -
timesheet_entry_id,time_worked,timesheet_date,project_key .
The csv columns are :
project,utilization,project_key,timesheet_category,employee,timesheet_date , hours_worked etc.
What I needed to know is that before the csv data is loaded into the timesheet table is there any way of validating the project key ( which is the primary key of the projects table) with the projects table . I need to perform similar validations with other columns like customer_id from customers table. Basically the loading should be done after validating if the data exists in the parent table. Has anyone done this kind of loading through the APEX utility-data load.Or is there another method of accomplishing the same.
Does Vikas's application do what the utility does ( i am assuming that the code being from 2005 the utility was not incorporated in APEX at that time). Any helpful advise is greatly appreciated.
Thanks,
AnjaliHi Anjali,
Take a look at these threads which might outline different ways to do it -
File Browse, File Upload
Loading CSV file using external table
Loading a CSV file into a table
you can create hidden items in the page to validate previous records before insert data.
Hope this helps,
M Tajuddin
http://tajuddin.whitepagesbd.com -
How to transfer data from excel files into z-tables
Please help me with a code which transfers data from excel file to z-table.
Thanks in advance
ShuvirHi Daniel,
Export Data
Purpose
Use this procedure to export SAP data to a local file such as Microsoft Excel.
Menu Path
Use the following menu path to begin this process:
· SystemèListèSaveèLocal File
Helpful Hints
When reviewing fields, R = Required, O = Optional and C = Conditional.
Procedure
1. Start the transaction using the menu path or transaction code.
Whatever Data You Want to Export
2. Select SystemèListèSaveèLocal File. This works well for any data in SAP. This is the only option for the top-level (first page) of a report.
In a drill-down view within a report the Local File button on the toolbar may be used and has the same options.
Choose File Format
3. Click .
4. Click to continue. If prompted for a format after choosing Spreadsheet, select Excel Table to get an Excel file that can be modified more easily.
Choose File Save Location Step 1
5. Click to the right of the Directory field to choose a different location.
Choose File Save Location Step 2
6. Click or browse your computer to locate the directory where you want to save your file.
7. Complete the following field:
· File name:
You must add the proper file extension to the name of your file (.xls for Excel, .rtf for Rich Text, .html for HTML). The file extension tells your computer what program to open the file with. If you do not have the file extension at the end, you may not be able to open it.
8. Click to continue.
Generate File in Location and Format Selected
9. Click to create the file in the location and format selected. In this example the file was named "example.xls" and saved on the desktop.
Result
You have completed the export process.
thanks
karthik -
Upload data from flat file into internal table
Hi friends,
I want to upload the data from a flat file into internal table , but the problem is that all the columns in that flat file are seperated by "|" character instead of tabs.
Plz help me out.........HEllo,
DO like this.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILENAME
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X' " Check here
* HEADER_LENGTH = '1'
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_COJRNL
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
VAsanth -
Is it possible to store dat from word file into a table
Hi Experts,
I have an Office UI element on my web dynpro View. It is selected as MS Word. Now I want to save data from this word file to a table in SAP. Can we have a data element which can store such type of large data. Please suggest.
Regards,
Vaibhav Tiwari.>But we can't have a table attribute of this type
Actually you can. You can define a database column as RAW STRING. This is exactly the same as a XSTRING variable and in your SQL statement you just pass it an XSTRING. It will store the entire contents of the XSTRING as a single column in the database. Large size is not a problem. -
How to import data from CSV file into a table by using oracle forms
Hi,
I have a CSV file and i want to insert in oracle database in a table by using a button in oracle forms.
the user can select CSV file by using open dialog .
can any one help me to find method to make import and select file from the client machine ?
thx.1. create table blob
CREATE TABLE IB_LOVE
DOC BLOB,
CONTRACT_NO VARCHAR2(20 BYTE) NOT NULL
)2. use the code below to insert:
INSERT INTO ordmgmt.ib_love
(contract_no, doc
VALUES (:control.contract_no_input, NULL
lb$result :=
webutil_file_transfer.client_to_db (:b2.file_name, v_file_blob_name, v_col_blob_name,
'CONTRACT_NO = ' || :control.contract_no_input);
:SYSTEM.message_level := 25;
COMMIT;
:SYSTEM.message_level := 0;3. use the code below to download
if :control.CONTRACT_NO_INPUT is not null then
vboolean := webutil_file_transfer.DB_To_Client_With_Progress(
vfilename, --filename
'IB_LOVE', ---table of Blob item
'DOC', --Blob column name
'CONTRACT_NO = ' || :CONTROL.CONTRACT_NO_INPUT, ---where clause to retrieve the record
'Downloading from Database', --Progress Bar title
'Wait to Complete'); --Progress bar subtitle client_host('cmd /c start '||vfilename);
client_host('cmd /c start '||vfilename);
else
errmsg('Please choose contract no');
end if;4. use the code below to open file dialog
x:= WEBUTIL_FILE.FILE_OPEN_DIALOG ( 'c:\', '*.gif', '|*.gif|*.gif|', 'My Open Window' ) ;
:b2.FILE_NAME:=X; -
How to pass parameters to the Control file while loading the data from flat file to staging table
Thanks in advance
Hi ,
LOADDATA statement is required at the beginning of the control file.
INFILE: INFILE keyword is used to specify location of the datafile or datafiles.
INFILE* specifies that the data is found in the control file and not in an external file. INFILE ‘$FILE’, can be used to send the filepath and filename as a parameter when registered as a concurrent program.
INFILE ‘/home/vision/kap/import2.csv’ specifies the filepath and the filename.
Hope this will help you...... -
pls send ans for this
1b5595eb-fcfc-48cc-90d2-43ba913ea79f wrote:
pls send ans for this
use any text editor to eliminate the dot before loading -
How to Load the data from excel file(Extension is .CSV) into the temp.table
Hi
How to Load the data from excel file(Extension is .CSV) into the temporary table of oracle in Forms11g.
My Forms Version is - Forms [64 Bit] Version 11.1.2.0.0 (Production)
Kindly Suggest the Solution.
Regards,
SachinHello Sachin,
You can use the following metalink note:How to Read Data from an EXCEL Spreadsheet into a Form Using Webutil Client_OLE2 (Doc ID 813535.1) and modify it a little bit.
Instead of copy values into forms you can save them in your temporary table.
Kind regards,
Alex
If someone's helpful or correct please mark it accordingly. -
Loading transaction data from flat file to SNP order series objects
Hi,
I am an BW developer and i need to provide data to my SNP team.
Can you please let me know more about <b>loading transaction data (sales order, purchase order, etc.,) from external systems into order based SNP objects/structure</b>. there is a 3rd party tool called webconnect that gets data from external systems and can give data in flat file or in database tables what ever required format we want.
I know we can use BAPI's, but dont know how. can you please send any <b>sample ABAP program code that calls BAPI to read flat file and write to SNP order series objects</b>.
Please let me know ASAP, how to get data from flat file into SNP order based objects, with options and I will be very grateful.
thanks in advance
RahulHi,
Please go through the following links:
https://forums.sdn.sap.com/click.jspa?searchID=6094493&messageID=4180456
https://forums.sdn.sap.com/click.jspa?searchID=6094493&messageID=4040057
https://forums.sdn.sap.com/click.jspa?searchID=6094493&messageID=3832922
https://forums.sdn.sap.com/click.jspa?searchID=6094493&messageID=4067999
Hope this helps...
Regards,
Habeeb
Assign points if helpful..:) -
To read data from exel file into sap
hi all,
How to read data from exel file into the internal table in abap?
Regards,
sugeet.Hi Sugeet,
Use the following code.
DATA : BEGIN OF tbl_asset occurs 0,
anlkl LIKE anla-anlkl, " Asset Class
bukrs LIKE anla-bukrs, " Company Code
ranl1 LIKE ra02s-ranl1, " Asset #
txt50 LIKE anla-txt50, " Description 1
txa50 LIKE anla-txa50, " Description 2
sernr LIKE anla-sernr, " Serial #
invnr LIKE anla-invnr, " Inventory #
menge LIKE anla-menge, " Quantity
meins LIKE anla-meins, " Base UOM
inken LIKE anla-inken, " Inventory
END OF tbl_asset.
DATA : w_filename TYPE IBIPPARMS-path,
w_file TYPE string.
start-of-selection.
*popup for file path from user
CALL FUNCTION 'F4_FILENAME'
EXPORTING
PROGRAM_NAME = SYST-CPROG
DYNPRO_NUMBER = SYST-DYNNR
IMPORTING
FILE_NAME = w_filename .
MOVE w_filename TO w_file .
* upload data
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = w_file
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = tbl_asset
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
for HAS_FIELD_SEPARATOR Use
'X': Fields are separated by tabs.
SPACE: Fields are not separated by tabs. In this case, the table must contain only one column or all columns must be contained in the file in their entire length.
Hope it helps...
Lokesh
Pls. reward appropriate points
Maybe you are looking for
-
Runtime error in service order
Hi everyone, When I try to create a service order I get the following runtime error. Has anyone any idea how I can solve the problem? Thanks in advance Björn
-
How to use math symbols in Pages
How can I find math symbols in Pages? Do I need additional Software or is there a possibility as in Microsoft Word?
-
One production client in one server
Hi friends, i have proposal to install two production clients in one single server (single database). What is sap recommendation, what is the advantage and disadvantage. Please let me know sap recommendation in this issue. ***Please provide sap d
-
Java.lang.ClassNotFound Exception whenever I include .send()
Everything runs fine, but when I add the .send(message); [it is in bold] I get a java.lang.ClassNotFound Exception. It still compiles, it just won't allow me to launch the program in the emulator. If I take that one piece of code out, everything runs
-
Videos have "blocked Plug Ins". I use 7yr. old MacBook
using MacBook(old) /"Blocked-Plug ins" on all videos/ down loaded Adobe Flash Player & installed... still not working. Please HELP