Upload an XML file into the Internal table
Hi Guys,
I want to know, how to upload an xml file into the Internal table through ABAP programming
you just wanted to load the xml file into internal table (as a table of binary strings)or load the xml data mapped to itab row columns
for the first one you can simply use gui_upload
and for the second one you need to load the xml file using gui_upload and use XLST program to transform into an itab
Regards
Raja
Similar Messages
-
How to upload XML file into the internal table in Webdynpro ABAP ?
Hi Friends,
I am not able to upload the XML file into ABAP,can you please help me in solving this issue with the help of source code.
Regards
DineshHi Dinesh,
Try go through this program which I had developed earlier. It takes as input an XML file and then breaks it down into name-value pairs of an intrnal table. You need to pass an XML file as input to this program. (I had hard coded the path for my XML file in it. You need to replace it with 1 of your own or you can just delete it and use the browse button to selet the file on your PC)
Regards,
Uday
REPORT ZUDAY_XML no standard page heading.
" Internal table to store the XML file in binary mode
data: begin of it_xml occurs 1,
c(255) type x,
end of it_xml,
" Name-value pairs table rturned by FM SMUM_XML_PARSE
it_SMUM_XMLTB type SMUM_XMLTB occurs 0 with header line,
" Table returned by FM SMUM_XML_PARSE for error handling
it_bapiret2 type bapiret2 occurs 0 with header line.
" XSTRING variable to be used by FM SCMS_BINARY_TO_XSTRING to hold the XML file in XSTRING format
data: I_xstring type xstring,
" String variable to hold XML file path to pass to GUI_UPLOAD
I_file_path type string,
" Variable to store the size of the uploaded binary XML file
I_LENGTH TYPE I VALUE 0.
parameters: P_path type IBIPPARMS-PATH default 'C:\Documents and Settings\c5104398\Desktop\flights.xml'.
" Get the XML file path from the user
at selection-screen on value-request for P_path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
FILE_NAME = P_PATH. -
Collect data from a dynamic XML file into multiple internal tables
I need to convert the XML file into multiple internal tables. I tried many links and posts in SDN but still was facing difficulty in achieving this. Can some one tell me where I am going wrong.
My XML file is of the following type.It is very complex and the dynamice.
The following tags occur more than once in the XML file. The "I" and "L" tags and its child tags can occur ones or more than once for each XML file and it is not constant. i.e in one file they can occur 1 time and in another they can occur 100 times.
"I" and "L" are child tags of <C>
<I>
<J>10</J>
<K>EN</K>
</I>
<L>
<J>20</J>
<N>BB</N>
</L>
Tags <C> and <F> occur only ones for each XML file. <C> is the child tag of "A" and "F" is the child tag of <C>.
I need to collect <D>, <E> in one internal table ITAB.
I need to collect <G>, <H> in one internal table JTAB.
I need to collect <J>, <K> in one internal table KTAB.
I need to collect <J>, <N> in one internal table PTAB.
Below is the complete XML file.
?xml version="1.0" encoding="iso-8859-1" ?>
<A>
<B/>
<C>
<D>RED</D>
<E>999</E>
<F>
<G>TRACK</G>
<H>PACK</H>
</F>
<I>
<J>10</J>
<K>EN</K>
</I>
<I>
<J>20</J>
<K>TN</K>
</I>
<I>
<J>30</J>
<K>KN</K>
</I>
<L>
<J>10</J>
<N>AA</N>
</L>
<L>
<J>20</J>
<N>BB</N>
</L>
<L>
<J>30</J>
<N>CC</N>
</L>
</C>
</A>
With the help of SDN I am able to gather the values of <D> <E> in one internal table.
Now if I need to gather
<G>, <H> in one internal table JTAB.
<J>, <K> in one internal table KTAB.
<J>, <N> in one internal table PTAB.
I am unable to do. I am following XSLT transformation method. If some one has some suggestions. Please help.
Here is my ABAP program
TYPE-POOLS abap.
CONSTANTS gs_file TYPE string VALUE 'C:\TEMP\ABCD.xml'.
* This is the structure for the data from the XML file
TYPES: BEGIN OF ITAB,
D(10) TYPE C,
E(10) TYPE C,
END OF ITAB.
* Table for the XML content
DATA: gt_itab TYPE STANDARD TABLE OF char2048.
* Table and work ares for the data from the XML file
DATA: gt_ITAB TYPE STANDARD TABLE OF ts_ITAB,
gs_ITAB TYPE ts_ITAB.
* Result table that contains references
* of the internal tables to be filled
DATA: gt_result_xml TYPE abap_trans_resbind_tab,
gs_result_xml TYPE abap_trans_resbind.
* For error handling
DATA: gs_rif_ex TYPE REF TO cx_root,
gs_var_text TYPE string.
* Get the XML file from your client
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_itab1
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
* Fill the result table with a reference to the data table.
* Within the XSLT stylesheet, the data table can be accessed with
* "IITAB".
GET REFERENCE OF gt_shipment INTO gs_result_xml-value.
gs_result_xml-name = 'IITAB'.
APPEND gs_result_xml TO gt_result_xml.
* Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION zxslt
SOURCE XML gt_itab1
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
* Now let's see what we got from the file
LOOP AT gt_ITAB INTO gs_ITAB.
WRITE: / 'D:', gs_ITAB-D.
WRITE: / 'E :', gs_ITAB-E.
ENDLOOP.
Transformation
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<IITAB>
<xsl:apply-templates select="//C"/>
</IITAB>
</asx:values>
</asx:abap>
</xsl:template>
<item>
<D>
<xsl:value-of select="D"/>
</D>
<E>
<xsl:value-of select="E"/>
</E>
</item>
</xsl:template>
</xsl:transform>
Now the above pgm and transformation work well and I am able to extract data into the ITAB. Now what changes should I make in transformation and in pgm to collect
<G>, <H> in one internal table JTAB.
<J>, <K> in one internal table KTAB.
<J>, <N> in one internal table PTAB.
Please help..i am really tring hard to figure this out. I am found lot of threads addressing this issue but not my problem.
Kindly help.
Regards,
VSHi Rammohan,
Thanks for the effort!
But I don't need to use GUI upload because my functionality does not require to fetch data from presentation server.
Moreover, the split command advised by you contains separate fields...f1, f2, f3... and I cannot use it because I have 164 fields. I will have to split into 164 fields and assign the values back to 164 fields in the work area/header line.
Moreover I have about 10 such work areas. so the effort would be ten times the above effort! I want to avoid this! Please help!
I would be very grateful if you could provide an alternative solution.
Thanks once again,
Best Regards,
Vinod.V -
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. -
Upload an Excel file into an Internal Table
Hi,
I want to upload an Excel file into an internal table but it doesn't work. I'd appreciate if someone could tell me what is wrong.
My excel file has the following format:
Col1 Col2
Row1 1 2
Row2 2 3
Row3 3 4
And the report code is the following one:
REPORT ZFI_PROKON_PROCESOS.
DATA: BEGIN OF itab OCCURS 0,
num1(1),
num2(1).
DATA: END OF itab.
PARAMETERS: p_file LIKE rlgrap-filename obligatory.
AT SELECTION-SCREEN.
AT SELECTION-SCREEN on value-request for p_file.
call function 'KD_GET_FILENAME_ON_F4'
EXPORTING
static = 'X'
CHANGING
file_name = p_file.
START-OF-SELECTION.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
FILENAME = p_file
I_BEGIN_COL = 1
I_BEGIN_ROW = 1
I_END_COL = 2
I_END_ROW = 5
TABLES
INTERN = itab
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT itab.
WRITE: / itab-num1, 10 itab-num2.
ENDLOOP.
Thanks in advance,
GerardTry function module
ALSM_EXCEL_TO_INTERNAL_TABLE
call function 'ALSM_EXCEL_TO_INTERNAL_TABLE'
exporting
filename = p_path
i_begin_col = 1
i_begin_row = 2
i_end_col = 70
i_end_row = 10000
tables
intern = i_excel
exceptions
inconsistent_parameters = 1
upload_ole = 2
others = 3.
P_PATH is file name with path.
I_EXCEL is internal table to store data.
declaration is "i_excel like structure alsmex_tabline"
then loop at i_Excel and populate your table
for eg
loop at i_excel.
case i_excel-col.
when '0001'.
i_data-compcode = i_excel-value.
when '0002'.
i_data-rcpttyp = i_excel-value.
when '0003'.
i_data-pocimpro = i_excel-value.
when '0004'.
i_data-tranno = i_excel-value.
when '0005'.
i_data-msrpo = i_excel-value.
when '0006'.
i_data-mporel = i_excel-value.
endcase.
at end of row.
append i_data.
clear i_data.
endat.
endloop. -
CRM ABAP How to upload an Excel file into an internal table?
How to upload an Excel file using GUI_UPLOAD?? what should be the values of the parameters? The function modules ALSM_EXCEL_TO_INTERNAL_TABLE and KCD_EXCEL_OLE_TO_INT are not present in CRM. Please suggest me a way out!
Hi saurabh,
you can try the folowing sample..
and make modifications according to your requirement..
TYPE-POOLS: truxs.
DATA: i_text_data TYPE truxs_t_text_data,
v_filename_string TYPE string.
DATA: BEGIN OF itab OCCURS 0,
Name(30),
Phone(15),
Fax(500).
DATA: END OF itab.
PARAMETERS: p_file LIKE rlgrap-filename.
START-OF-SELECTION.
v_filename_string = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_filename_string
filetype = 'ASC'
has_field_separator = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
dat_mode = ''
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
data_tab = i_text_data
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.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
i_field_seperator = 'X'
* I_LINE_HEADER =
i_tab_raw_data = i_text_data
i_filename = p_file
TABLES
i_tab_converted_data = itab
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.
this is a sample code that uploads a excel file using GUI_UPLOAD, but uses another function module to convert that uploaded data into an internal table..
regards
satesh -
Approach to parse large number of XML files into the relational table.
We are exploring the option of XML DB for processing a large number of files coming same day.
The objective is to parse the XML file and store in multiple relational tables. Once in relational table we do not care about the XML file.
The file can not be stored on the file server and need to be stored in a table before parsing due to security issues. A third party system will send the file and will store it in the XML DB.
File size can be between 1MB to 50MB and high performance is very much expected other wise the solution will be tossed.
Although we do not have XSD, the XML file is well structured. We are on 11g Release 2.
Based on the reading this is what my approach.
1. CREATE TABLE XML_DATA
(xml_col XMLTYPE)
XMLTYPE xml_col STORE AS SECUREFILE BINARY XML;
2. Third party will store the data in XML_DATA table.
3. Create XMLINDEX on the unique XML element
4. Create views on XMLTYPE
CREATE OR REPLACE FORCE VIEW V_XML_DATA(
Stype,
Mtype,
MNAME,
OIDT
AS
SELECT x."Stype",
x."Mtype",
x."Mname",
x."OIDT"
FROM data_table t,
XMLTABLE (
'/SectionMain'
PASSING t.data
COLUMNS Stype VARCHAR2 (30) PATH 'Stype',
Mtype VARCHAR2 (3) PATH 'Mtype',
MNAME VARCHAR2 (30) PATH 'MNAME',
OIDT VARCHAR2 (30) PATH 'OID') x;
5. Bulk load the parse data in the staging table based on the index column.
Please comment on the above approach any suggestion that can improve the performance.
Thanks
AnuragTThanks for your response. It givies more confidence.
Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
TNS for Linux: Version 11.2.0.3.0 - Production
Example XML
<SectionMain>
<SectionState>Closed</SectionState>
<FunctionalState>CP FINISHED</FunctionalState>
<CreatedTime>2012-08</CreatedTime>
<Number>106</Number>
<SectionType>Reel</SectionType>
<MachineType>CP</MachineType>
<MachineName>CP_225</MachineName>
<OID>99dd48cf-fd1b-46cf-9983-0026c04963d2</OID>
</SectionMain>
<SectionEvent>
<SectionOID>99dd48cf-2</SectionOID>
<EventName>CP.CP_225.Shredder</EventName>
<OID>b3dd48cf-532d-4126-92d2</OID>
</SectionEvent>
<SectionAddData>
<SectionOID>99dd48cf2</SectionOID>
<AttributeName>ReelVersion</AttributeName>
<AttributeValue>4</AttributeValue>
<OID>b3dd48cf</OID>
</SectionAddData>
- <SectionAddData>
<SectionOID>99dd48cf-fd1b-46cf-9983</SectionOID>
<AttributeName>ReelNr</AttributeName>
<AttributeValue>38</AttributeValue>
<OID>b3dd48cf</OID>
<BNCounter>
<SectionID>99dd48cf-fd1b-46cf-9983-0026c04963d2</SectionID>
<Run>CPFirstRun</Run>
<SortingClass>84</SortingClass>
<OutputStacker>D2</OutputStacker>
<BNCounter>54605</BNCounter>
</BNCounter>
I was not aware of Virtual column but looks like we can use it and avoid creating views by just inserting directly into
the staging table using virtual column.
Suppose OID id is the unique identifier of each XML FILE and I created virtual column
CREATE TABLE po_Virtual OF XMLTYPE
XMLTYPE STORE AS BINARY XML
VIRTUAL COLUMNS
(OID_1 AS (XMLCAST(XMLQUERY('/SectionMain/OID'
PASSING OBJECT_VALUE RETURNING CONTENT)
AS VARCHAR2(30))));
1. My question is how then I will write this query by NOT USING COLMUN XML_COL
SELECT x."SECTIONTYPE",
x."MACHINETYPE",
x."MACHINENAME",
x."OIDT"
FROM po_Virtual t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionType VARCHAR2 (30) PATH 'SectionType',
MachineType VARCHAR2 (3) PATH 'MachineType',
MachineName VARCHAR2 (30) PATH 'MachineName',
OIDT VARCHAR2 (30) PATH 'OID') x;
2. Insetead of creating the view then Can I do
insert into STAGING_table_yyy ( col1 ,col2,col3,col4,
SELECT x."SECTIONTYPE",
x."MACHINETYPE",
x."MACHINENAME",
x."OIDT"
FROM xml_data t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionType VARCHAR2 (30) PATH 'SectionType',
MachineType VARCHAR2 (3) PATH 'MachineType',
MachineName VARCHAR2 (30) PATH 'MachineName',
OIDT VARCHAR2 (30) PATH 'OID') x
where oid_1 = '99dd48cf-fd1b-46cf-9983';<--VIRTUAL COLUMN
insert into STAGING_table_yyy ( col1 ,col2,col3
SELECT x."SectionOID",
x."EventName",
x."OIDT"
FROM xml_data t,
XMLTABLE (
'/SectionMain'
PASSING t.xml_col <--WHAT WILL PASSING HERE SINCE NO XML_COL
COLUMNS SectionOID PATH 'SectionOID',
EventName VARCHAR2 (30) PATH 'EventName',
OID VARCHAR2 (30) PATH 'OID',
) x
where oid_1 = '99dd48cf-fd1b-46cf-9983';<--VIRTUAL COLUMN
Same insert for other tables usind the OID_1 virtual coulmn
3. Finaly Once done how can I delete the XML document from XML.
If I am using virtual column then I beleive it will be easy
DELETE table po_Virtual where oid_1 = '99dd48cf-fd1b-46cf-9983';
But in case we can not use the Virtual column how we can delete the data
Thanks in advance
AnuragT -
I want to convert XML file into SAP Internal table
Hi Frndz,
My xml file is:
<?xml version="1.0" ?>
- <!-- Comments: START DATE :1/11/2002 11:26:14 PM
-->
- <!-- Comments: RFID Tags read by Mercury4 Copyright Praff@Anantara Solutions
-->
<RFIDs><ID>0x303030303030303035050000B5EC</ID><ID>0x300833B2DDD901403505000042E7</ID></RFIDs>
i want to take those 2 ID's in a internal table that id field is of 28 character type....
very urgent.
Thanks,
Arunprasad.Pclass cl_ixml definition load.
type-pools: ixml.
types: begin of t_xml_line,
data(256) type x,
end of t_xml_line,
begin of tsfixml,
data(1024) type c,
end of tsfixml.
data: l_ixml type ref to if_ixml,
l_streamfactory type ref to if_ixml_stream_factory,
l_parser type ref to if_ixml_parser,
l_istream type ref to if_ixml_istream,
l_document type ref to if_ixml_document,
l_node type ref to if_ixml_node,
l_xmldata type string.
data: l_elem type ref to if_ixml_element,
l_root_node type ref to if_ixml_node,
l_next_node type ref to if_ixml_node,
l_name type string,
l_iterator type ref to if_ixml_node_iterator.
data: l_xml_table type table of t_xml_line,
l_xml_line type t_xml_line,
l_xml_table_size type i.
data: l_filename type string.
parameters: pa_file type char1024 default
'C:\WINDOWS\Desktop\RFIDTags.xml'.
*Validation of XML file: Only DTD included in xml document is supported
parameters: pa_val type char1 as checkbox.
start-of-selection.
*Creating the main iXML factory
l_ixml = cl_ixml=>create( ).
*Creating a stream factory
l_streamfactory = l_ixml->create_stream_factory( ).
perform get_xml_table changing l_xml_table_size l_xml_table.
*wrap the table containing the file into a stream
l_istream = l_streamfactory->create_istream_itable( table = l_xml_table
size = l_xml_table_size ).
*Creating a document
l_document = l_ixml->create_document( ).
*Create a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
*Validate a document
if pa_val eq 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
endif.
*Parse the stream
if l_parser->parse( ) ne 0.
if l_parser->num_errors( ) ne 0.
data: parseerror type ref to if_ixml_parse_error,
str type string,
i type i,
count type i,
index type i.
count = l_parser->num_errors( ).
write: count, ' parse errors have occured:'.
index = 0.
while index < count.
parseerror = l_parser->get_error( index = index ).
i = parseerror->get_line( ).
write: 'line: ', i.
i = parseerror->get_column( ).
write: 'column: ', i.
str = parseerror->get_reason( ).
write: str.
index = index + 1.
endwhile.
endif.
endif.
*Process the document
if l_parser->is_dom_generating( ) eq 'X'.
perform process_dom using l_document.
endif.
*& Form get_xml_table
form get_xml_table changing l_xml_table_size type i
l_xml_table type standard table.
*Local variable declaration
data: l_len type i,
l_len2 type i,
l_tab type tsfixml,
l_content type string,
l_str1 type string,
c_conv TYPE REF TO cl_abap_conv_in_ce,
l_itab type table of string.
l_filename = pa_file.
*upload a file from the client's workstation
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = l_filename
FILETYPE = 'BIN'
IMPORTING
FILELENGTH = l_xml_table_size
HEADER =
TABLES
DATA_TAB = l_xml_table
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
*Writing the XML document to the screen
CLEAR l_str1.
LOOP AT l_xml_table INTO l_xml_line.
c_conv = cl_abap_conv_in_ce=>create( input = l_xml_line-data
replacement = space ).
c_conv->read( IMPORTING data = l_content len = l_len ).
CONCATENATE l_str1 l_content INTO l_str1.
ENDLOOP.
l_str1 = l_str1+0(l_xml_table_size).
SPLIT l_str1 AT cl_abap_char_utilities=>cr_lf INTO TABLE l_itab.
WRITE: /.
WRITE: /' XML File'.
WRITE: /.
LOOP AT l_itab INTO l_str1.
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>horizontal_tab
IN
l_str1 WITH space.
WRITE: / l_str1.
ENDLOOP.
WRITE: /.
endform. "get_xml_table
*& Form process_dom
form process_dom using document type ref to if_ixml_document.
data: node type ref to if_ixml_node,
iterator type ref to if_ixml_node_iterator,
nodemap type ref to if_ixml_named_node_map,
attr type ref to if_ixml_node,
name type string,
prefix type string,
value type string,
indent type i,
count type i,
index type i.
data: name2 type string,
name_root type string,
node_parent type ref to if_ixml_node,
node_root type ref to if_ixml_node,
num_children type i.
node ?= document.
check not node is initial.
uline.
write: /.
write: /' DOM-TREE'.
write: /.
if node is initial. exit. endif.
create a node iterator
iterator = node->create_iterator( ).
get current node
node = iterator->get_next( ).
loop over all nodes
while not node is initial.
indent = node->get_height( ) * 2.
indent = indent + 20.
num_children = node->num_children( ).
case node->get_type( ).
when if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
node_root = node->get_root( ).
name_root = node_root->get_name( ).
write: / 'ELEMENT :'.
write: at indent name color col_positive inverse.
write: 'NUM_CHILDREN:', num_children.
write: 'ROOT:', name_root.
node_parent = node->get_parent( ).
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
if not nodemap is initial.
*attributes
count = nodemap->get_length( ).
do count times.
index = sy-index - 1.
attr = nodemap->get_item( index ).
name = attr->get_name( ).
prefix = attr->get_namespace_prefix( ).
value = attr->get_value( ).
write: / 'ATTRIBUTE:'.
write: at indent name color col_heading inverse, '=',
value color col_total inverse.
enddo.
endif.
when if_ixml_node=>co_node_text or
if_ixml_node=>co_node_cdata_section.
*text node
value = node->get_value( ).
write: / 'VALUE :'.
node_parent = node->get_parent( ).
write: at indent value color col_group inverse.
name2 = node_parent->get_name( ).
write: 'NAME2: ' , name2.
endcase.
*advance to next node
node = iterator->get_next( ).
endwhile.
endform. "process_dom
Thanks,
Arunprasad.P -
Read data from xml files and populate internal table
Hi.
How to read data from xml files into internal tables?
Can u tell me the classes and methods to read xml data..
Can u explain it with a sample program...<pre>DATA itab_accontextdir TYPE TABLE OF ACCONTEXTDIR.
DATA struct_accontextdir LIKE LINE OF itab_accontextdir.
DATA l_o_error TYPE REF TO cx_root.
DATA: filename type string ,
xmldata type xstring .
DATA: mr TYPE REF TO if_mr_api.
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
WRITE xmldata.
TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.
LOOP AT itab_accontextdir INTO struct_accontextdir.
WRITE: / struct_accontextdir-context_id,
struct_accontextdir-context_name,
struct_accontextdir-context_type.
NEW-LINE.
ENDLOOP.</pre>
<br/>
Description:
In the above code snippet I am storing the data in an xml file(you know xml is used to store and transport data ) called 'xml_accontextdir.xml' that is uploaded into the MIME repository at path 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'.
The below API is used to read a file in MIME repo and convert it into a string that is stored in ' xmldata'. (This is just a raw data that is got by appending the each line of xml file).
mr = cl_mime_repository_api=>get_api( ).
mr->get( EXPORTING i_url = 'SAP/PUBLIC/BC/xml_files_accontext/xml_accontextdir.xml'
IMPORTING e_content = xmldata ).
Once the 'xmldata' string is available we use the tranformation to parse the xml string that we have got from the above API and convert it into the internal table.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE XML xmldata
RESULT shiva = itab_accontextdir.
CATCH cx_root INTO l_o_error.
ENDTRY.</pre>
Here the trasnsformation 'id ' is used to conververt the source xml 'xmldata' to resulting internal table itab_accontextdir, that have same structure as our xml file 'xml_accontextdir.xml'. In the RESULT root of the xml file has to be specified. (In my the root is 'shiva').
Things to be taken care:
One of the major problem that occurs when reading the xml file is 'format not compatible with the internal table' that you are reading into internal table. Iin order to get rid of this issue use one more tranformation to convert the data from the internal table into the xml file.
<pre>TRY.
CALL TRANSFORMATION id
SOURCE shiv = t_internal_tab
RESULT XML xml.
CATCH cx_root INTO l_o_error.
ENDTRY.
WRITE xml.
NEW-LINE.</pre>
<br/>
This is the same transformation that we used above but the differnce is that the SOURCE and RESULT parameters are changed the source is now the internal table and result is *xml *string. Use xml browser that is available with the ABAP workbench to read the xml string displayed with proper indentation. In this way we get the format of xml file to be used that is compatable with the given internal table.
Thank you, Hope this will help you!!!
Edited by: Shiva Prasad L on Jun 15, 2009 7:30 AM
Edited by: Shiva Prasad L on Jun 15, 2009 11:56 AM
Edited by: Shiva Prasad L on Jun 15, 2009 12:06 PM -
How do I import one xml file into 3 separate tables in db?
I need to utilize xslt to import one xml file into 3 separate tables: account, accountAddress, streetAddress
*Notice the missing values in middleName, accountType
sample xml
<account>
<firstName>Joe</firstName>
<middleName></middleName>
<lastName>Torre</lastName>
<accountAddress>
<streetAddress>
<addressLine>myAddressLine1</addressLine>
<addressLine>myAddressLine2</addressLine>
</streetAddress>
<city>myCity</city>
<state>myState</state>
<postalCode>mypostalCode</postalCode>
</accountAddress>
<accountId>A001</accountId>
<accountType></accountType>
<account>
I need the following 3 results in 3 separate xml files in order for me to upload into my 3 tables.
Result #1
<rowset>
<row>
<firstName>Joe</firstName>
<lastName>Torre</lastName>
<accountId>A001</accountId>
<row>
<rowset>
Result #2
<rowset>
<row>
<addressId>1</address>
<city>myCity</city>
<state>myState</state>
<postalCode>myPostalCode</postalCode>
<row>
<rowset>
Result #3
<rowset>
<row>
<addressId>1</addressId>
<addressLineSeq>1</addressLineSeq>
<addressLine>myAddressLine1</addressLine>
<row>
<row>
<addressId>1</addressId>
<addressLineSeq>2</addressLineSeq>
<addressLine>myAddressLine2</addressLine>
<row>
<rowset>Use XSU to store in multiple tables.
"XSU can only store data in a single table. You can store XML across tables, however, by using the Oracle XSLT processor to transform a document into multiple documents and inserting them separately. You can also define views over multiple tables and perform insertions into the views. If a view is non-updatable (because of complex joins), then you can use INSTEAD OF triggers over the views to perform the inserts."
http://download-west.oracle.com/docs/cd/B19306_01/appdev.102/b14252/adx_j_xsu.htm#i1007013 -
Reading XML file to ABAP internal table
Hi all,
Iam trying to convert a XLM file into abap internal table , am using XSLT transformation to parse the XML file and i am using "CALL METHOD cl_gui_frontend_services=>gui_upload" for reading the XML file.
below is the XML file.
===========================================================================
- <PIXBridge version="2.2" timestamp="2003-04-09T15:27:00">
- <PIX>
<TransactionType>605</TransactionType>
<TransactionCode>98</TransactionCode>
<TransactionNumber>6888965</TransactionNumber>
<SequenceNumber>40001</SequenceNumber>
- <SKUDefinition>
<Company>GZL</Company>
<Division>BMD</Division>
<Season />
<SeasonYear />
<Style>ORT002A</Style>
<StyleSuffix />
<Color>K13</Color>
<ColorSuffix />
<SecDimension />
<Quality />
<SizeRangeCode />
<SizeDesc>M</SizeDesc>
<SkuID>200140577</SkuID>
</SKUDefinition>
</PIX>
</PIXBridge>
=================================================================
and my Transformation code is as below
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<IPIX>
<xsl:apply-templates select="//PIX"/>
</IPIX>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="PIX">
<item>
<TRANSACTIONTYPE>
<xsl:value-of select="TransactionType"/>
</TRANSACTIONTYPE>
<TRANSACTIONCODE>
<xsl:value-of select="TransactionCode"/>
</TRANSACTIONCODE>
<TRANSACTIONNUMBER>
<xsl:value-of select="TransactionNumber"/>
</TRANSACTIONNUMBER>
<SEQUENCENUMBER>
<xsl:value-of select="SequenceNumber"/>
</SEQUENCENUMBER>
<SKUDEFINITION>
<COMPANY>
<xsl:value-of select="Company"/>
</COMPANY>
<DIVISION>
<xsl:value-of select="Division"/>
</DIVISION>
<SEASON/>
<SEASONYEAR/>
<STYLE>
<xsl:value-of select="Style"/>
</STYLE>
<STYLESUFFIX/>
<COLOR>
<xsl:value-of select="Color"/>
</COLOR>
<COLORSUFFIX/>
<SECDIMENSION/>
<QUANTITY/>
<SIZERANGECODE/>
<SIZEDESC>
<xsl:value-of select="SizeDesc"/>
</SIZEDESC>
<SKUID>
<xsl:value-of select="SkuID"/>
</SKUID>
</SKUDEFINITION>
</item>
</xsl:template>
When i run my program i am getting the values only till the sequence number part and im not getting any values that is read in between <SKUDEFINITION> ..... </SKUDEFINITION>
I need help to sort this , kindly help me in this.
regs,
rajaI am not able to get a clue out of that, can Get Durairaj Athavan Raja in to loop for sorting this out.
I made changes to my transformation program , but still not getting the output of the components inside the
<SKUDefinition> , but when i debug the transformation i can able to see the output values for those components but when i get the values in the result table im not getting values of those components.
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output encoding="iso-8859-1" indent="yes" method="xml" version="1.0"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
<asx:values>
<IPIX>
<xsl:apply-templates select="//PIX"/>
</IPIX>
</asx:values>
</asx:abap>
</xsl:template>
<xsl:template match="PIX">
<item>
<TRANSACTIONTYPE>
<xsl:value-of select="TransactionType"/>
</TRANSACTIONTYPE>
<TRANSACTIONCODE>
<xsl:value-of select="TransactionCode"/>
</TRANSACTIONCODE>
<TRANSACTIONNUMBER>
<xsl:value-of select="TransactionNumber"/>
</TRANSACTIONNUMBER>
<SEQUENCENUMBER>
<xsl:value-of select="SequenceNumber"/>
</SEQUENCENUMBER>
<xsl:for-each select="SKUDefinition">
<SKUDEFINITION>
<COMPANY>
<xsl:value-of select="Company"/>
</COMPANY>
<DIVISION>
<xsl:value-of select="Division"/>
</DIVISION>
<SEASON/>
<SEASONYEAR/>
<STYLE>
<xsl:value-of select="Style"/>
</STYLE>
<STYLESUFFIX/>
<COLOR>
<xsl:value-of select="Color"/>
</COLOR>
<COLORSUFFIX/>
<SECDIMENSION/>
<QUANTITY/>
<SIZERANGECODE/>
<SIZEDESC>
<xsl:value-of select="SizeDesc"/>
</SIZEDESC>
<SKUID>
<xsl:value-of select="SkuID"/>
</SKUID>
</SKUDEFINITION>
</xsl:for-each>
</item>
</xsl:template>
</xsl:transform>
==================
Below is my main program
===================
TYPE-POOLS abap.
CONSTANTS gs_file TYPE string VALUE 'C:\XMLABAP1.xml'.
This is the structure for the data from the XML file
TYPES: BEGIN OF ty_text,
TransactionType(3) type n,
TransactionCode(2) type n,
TransactionNumber(7) type n,
SequenceNumber(5) type n,
Company(3) type c,
Division(3) type c,
Season(3) type c,
SeasonYear(4) type c,
Style(8) type c,
Color(3) type c,
SecDimension(3) type c,
Quality(3) type n,
SizeRangeCode(2) type c,
SizeDesc(1) type c,
SkuID(10) type c,
END OF ty_text.
Table for the XML content
DATA: gt_itab TYPE STANDARD TABLE OF char2048.
data: xmlstr TYPE XSTRING.
Table and work ares for the data from the XML file
DATA: gt_person TYPE STANDARD TABLE OF ty_text,
gs_person TYPE ty_text.
Result table that contains references
of the internal tables to be filled
DATA: gt_result_xml TYPE abap_trans_resbind_tab,
gs_result_xml TYPE abap_trans_resbind.
For error handling
DATA: gs_rif_ex TYPE REF TO cx_root,
gs_var_text TYPE string.
Get the XML file from your client
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = gs_file
CHANGING
data_tab = gt_itab
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
not_supported_by_gui = 17
error_no_gui = 18
OTHERS = 19.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Fill the result table with a reference to the data table.
Within the XSLT stylesheet, the data table can be accessed with
"IPERSON".
GET REFERENCE OF gt_person INTO gs_result_xml-value.
gs_result_xml-name = 'IPIX'.
APPEND gs_result_xml TO gt_result_xml.
Perform the XSLT stylesheet
TRY.
CALL TRANSFORMATION ZAUM_MANH_SYNC_RPT
SOURCE XML XMLSTR
RESULT (gt_result_xml).
CATCH cx_root INTO gs_rif_ex.
gs_var_text = gs_rif_ex->get_text( ).
MESSAGE gs_var_text TYPE 'E'.
ENDTRY.
Now let's see what we got from the file
LOOP AT gt_person INTO gs_person.
WRITE: / 'Transaction Type:', gs_person-TransactionType.
WRITE: / 'Transaction Code :', gs_person-TransactionCode.
WRITE: / 'Transaction Number :', gs_person-TransactionNumber.
WRITE: / 'SequenceNumber :', gs_person-SequenceNumber.
WRITE: / 'Company : ', gs_person-Company.
WRITE : /.
ENDLOOP. "gt_person. -
How to upload an XML file into another system
Hi friends,
I have a requirement where I need to upload an XML file into one system
which has been downloaded using another system.
I have tried using the method ' cl_gui_frontend_services=>gui_upload'
to upload the file but it is going for dump.
I have used the method ' w_xml->import_from_file' also,
but it is also going for dump ,because both methods are using the same FM
' GUI_UPLOAD'.
Can any one suggest on this.
Regards,
Bhargavi.D"Here is the Explaination for uploading the XML Format file to sap " through ABAP Program ....
1. Basically you simply have to convert the XML file into the proper IDoc format. There are many ways to achieve this. One solution would be to convert it externally to SAP, e.g. via VB Script or with an XSLT transformation. Or you use the built in SAP functions for importing an IDoc from an XML stream.
2. Uploading a file is either done via GUI_UPLOAD or via the usual way of reading a file from the application server (Open dataset. Read dataset) But what do you mean by "send to external system"? Do you want to convert an IDoc into XML? Then you simply define an XML port with WE21 to send the IDoc out.
Here is an example of code that loads an XML from file and posts it as an IDoc. Please keep in mind that the XML has to be in its canonical format as described in the interface repository: ifr.sap.com (choose the template of the desired IDoc from there as an example).
data: data_tab type table of char1024.
data: XML_STREAM type string.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'D:test.xml'
* FILETYPE = 'ASC'
* HAS_FIELD_SEPARATOR = ' '
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* CODEPAGE = ' '
* IGNORE_CERR = ABAP_TRUE
* REPLACEMENT = '#'
* CHECK_BOM = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = DATA_TAB
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.
CALL FUNCTION 'CONVERT_TABLE_TO_STRING'
EXPORTING
I_TABLINE_LENGTH = '1024'
IMPORTING
E_STRING = XML_STREAM
TABLES
IT_TABLE = DATA_TAB[].
write: / xml_stream color col_total.
data: CONTENT_LENGTH type string.
data: CONTENT_TYPE type string.
data: REMOTE_ADDR type string.
CALL FUNCTION 'IDOC_INBOUND_XML_VIA_HTTP'
EXPORTING
XML_STREAM = XML_STREAM
CONTENT_LENGTH = content_type
CONTENT_TYPE = content_type
REMOTE_ADDR = remote_addr
EXCEPTIONS
NO_IDOCS_SAVED = 1
TAG_ERROR = 2
NO_DATA_RECEIVED = 3
NO_IDOCS_RECEIVED = 4
SEGMENT_ERROR = 5
IDOC_WAS_SEND_SECOND_TIME = 6
OTHERS = 7
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
write: / sy-subrc color COL_NEGATIVE.
ENDIF.
reward points if it is usefull.......
Girish -
How to Down load Data in Application server into the Internal Table
hi freinds,
iam having a file in the application server.
now i need to send the data in the file to the internal table.
is there any Function Module?
i need with out using the OPEN DATA SET and CLOSE DATA SET Keywords.
is there any possible?
Regard's,
Ranjith.Hi,
There is no other option for uploading the data from the application server to the internal table without using OPEN DATASET and CLOSE DATASET. Even if you find the FM internal logic in FM uses these keywords to read the data from Application server. -
A query while importing an XML file into a Database Table
Hi,
I am Creating an ODI Project to import an XML file into a Database Table.With the help of the following link
http://www.oracle.com/webfolder/technetwork/tutorials/obe/fmw/odi/odi_11g/odi_project_xml-to-table/odi_project_xml-to-table.htm
I am facing a problem while creating Physical Schema for the XML Source Model.
For the
Schema(Schema)
and
Schema(Work Schema) field they have selected GEO_D.
What is GEO_D here??
or
What I have to select here?
1) schema of the xml file (NB:-I havn't created any .xsd or .dtd file for my .xml file)
or
2)my target servers schema
Please tell me what I'll do??
Thanksand
Schema(Work Schema) field they have selected GEO_D.
What is GEO_D here??This is the schema name which is specified in the XML file .
What I have to select here?
1) schema of the xml file (NB:-I havn't created any .xsd or .dtd file for my .xml file)Yes
2)my target servers schema
Please tell me what I'll do??
Thanks -
How to import a XML file into the document?
Hai,
i had created a table using xml file....
Now i want to import that xml file tabel into the document...
Can any one tell me how to import the xml file into the document?
thanks
senthilHai...
this is senthil...
i'm beginner for creating adobe indesign plugins..
i want to import a html file in the document...
i want to create a table by using html tags and
that table will be imported into the document..
How shall i do it?
can any one plzz explain me?
Maybe you are looking for
-
dear guru, we are trying vendor ageing report in sap but the report format of report as per client requirement. T-Code: S_ALR_87012085. the limitation in this report is that it is coming very lenthy format and one vendor information is coming in one
-
Pdf not displayed correctly in preview
We have a new A) scanner (colortrac Ci40) and when we scan a pdf it is displayed in preview as if it is all wrinkled up. Only in prewiew and if imorted in vectorworks. (on both OSX 10.5 and 10.6) The same problem appears on a iPad. It is not displaye
-
Ipod nano won't turn on unless plugged in. ipod is never used but purchased in '08
I have an ipod Nano 4GB (3rd generation, I believe) purchased in March 2008. This has not been used since then until I took it out of original package last night. I plugged in to charge overnight and charging battery icon appeared. This morning while
-
Source is a File system and Target 2 SAP reciever system scenario??
Hi All Can you please guide me how to do the below scenario. sender is a FTP server , will pick the data from here . and RECIEVER there are two Business system (SAPI), BAPI is being used here for one is working fine , but how can i do it configure
-
Airport Speed issues after update
Hi, initially my machine was buggy after the update which never happens. I reinstalled from the Apple Site,instead of the software update, and the machine is running a little better. However, my Airport connection speed, using a Time Capsule running