Convert XML page into Internal Table
Hi,
I'm not sure if this post belongs here or not, but here goes.
I have a requirement to read in data from a xml page and save the contents into a ABAP internal table.
At the moment, I have extracted the contents of the XML page into a string using the IF_HTTP_CLIENT->RESPONSE->GET_CDATA method.
Now I underatand that SAP has XSLT documents that can be used to transform XML documents into ABAP Data Structures.
Can someone explain to me how this works? I have looked in SAP Help about the XSLT Editor, but it still looks like double dutch to me (no offence to the dutch people out there!).
Thanks,
Pat.
You can use either XSLT programming or Simple Transformation to do that job. check out the following weblogs.
<a href="/people/tobias.trapp/blog/2005/05/04/xml-processing-in-abap-part-1">XML processing in ABAP Part 1</a>
<a href="/people/tobias.trapp/blog/2005/05/17/xml-processing-in-abap-part-2">XML processing in ABAP Part 2</a>
<a href="/people/tobias.trapp/blog/2005/05/20/xml-processing-in-abap-part-3">XML processing in ABAP Part 3</a>
<a href="/people/tobias.trapp/blog/2005/05/27/xml-processing-in-abap-part-4">XML processing in ABAP Part 4</a>
<a href="/people/tobias.trapp/blog/2005/06/15/xml-processing-in-abap--part-5">XML processing in ABAP Part 5</a>
Regards
Raja
Similar Messages
-
How to convert xml file into internal table in ABAP Mapping.
Hi All,
I am trying with ABAP mapping. I have one scenario in which I'm using below xml file as a sender from my FTP server.
<?xml version="1.0" encoding="UTF-8" ?>
- <ns0:MTO_ABAP_MAPPING xmlns:ns0="http://Capgemini/Mumbai/sarsingh">
<BookingCode>2KY34R</BookingCode>
- <Passenger>
<Name>SARVESH</Name>
<Address>THANE</Address>
</Passenger>
- <Passenger>
<Name>RAJESH</Name>
<Address>POWAI</Address>
</Passenger>
- <Passenger>
<Name>CARRON</Name>
<Address>JUHU</Address>
</Passenger>
- <Flight>
<Date>03/03/07</Date>
<AirlineID>UA</AirlineID>
<FlightNumber>125</FlightNumber>
<From>LAS</From>
<To>SFO</To>
</Flight>
</ns0:MTO_ABAP_MAPPING>
AT the receiver side I wnat to concatenate the NAME & ADDRESS.
I tried Robert Eijpe's weblog (/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml-file-into-an-abap-table-using-sap-dom-approach)
but couldnt succeed to convert the xml file into internal table perfectly.
Can anybody help on this.
Thanks in advance!!
SarveshHi Sarvesh,
The pdf has details of ABAP mapping. The example given almost matches the xml file you want to be converted.
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/xi/3.0/how to use abap-mapping in xi 3.0.pdf
Just in case you have not seen this
regards
Vijaya -
Convert XML values to internal table
Hi Experts
How can i convert XML values to internal table . i am getting all the values into the string.
this is my example
<?xml version="1.0" encoding="UTF-8"?><TEST><ZTEST><DEPTNO>HEADOFFICE</DEPTNO><DNAME>IT</DNAME><LOC>HYD</LOC><MANDT>003</MANDT></ZTEST></TEST>
i did create internal table with 4 fields.
Please help.XML DOM Processing in ABAP part I - Convert an ABAP table into XML file using SAP DOM Approach.
-
Hi Friends,
See the followong code which converts xml data into itab.
*& Report ZTEST_XML1 *
REPORT ZTEST_XML1 .
*PURPOSE: This program transfers XML data into SAP internal table format
*The nodes in DOM can be stored as fields in SAP Internal table
type pool definitions
TYPE-POOLS: ixml. "iXML Library Types
type definitions
TYPES: BEGIN OF t_xml_line, "Structure for holding XML data
data(256) TYPE x,
END OF t_xml_line.
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, " XML Table of the structure
*t_xml_line
l_xml_line TYPE t_xml_line, " Record of structure t_xml_line
l_xml_table_size TYPE i. " XML table size
DATA: l_filename TYPE string. " String to hold filename
data: begin of i_final occurs 0,
pnumber(20),
pname(50),
pdes(70),
end of i_final.
PARAMETERS: pa_file TYPE char1024 DEFAULT 'C:\product.xml'.
Validation of XML file: Only DTD included in XML document is supported
PARAMETERS: pa_val TYPE char1 AS CHECKBOX.
start of selection
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( ).
Creating a Parser
l_parser = l_ixml->create_parser( stream_factory = l_streamfactory
istream = l_istream
document = l_document ).
Validate a document
IF pa_val = 'X'.
l_parser->set_validating( mode = if_ixml_parser=>co_validate ).
ENDIF.
Parse the stream
IF l_parser->parse( ) <> 0.
IF l_parser->num_errors( ) <> 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
text
<--P_L_XML_TABLE_SIZE text
<--P_L_XML_TABLE text
FORM get_xml_table CHANGING p_l_xml_table_size
p_l_xml_table.
Local variable declarations
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 file from the client's workstation
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = l_filename
filetype = 'BIN'
IMPORTING
filelength = l_xml_table_size
CHANGING
data_tab = l_xml_table
EXCEPTIONS
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.
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
text
-->P_L_DOCUMENT text
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.
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.
CASE node->get_type( ).
WHEN if_ixml_node=>co_node_element.
element node
name = node->get_name( ).
nodemap = node->get_attributes( ).
WRITE: / 'ELEMENT :'.
WRITE: AT indent name COLOR COL_POSITIVE INVERSE.
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 :'.
WRITE: AT indent value COLOR COL_GROUP INVERSE.
ENDCASE.
Advance to next node
node = iterator->get_next( ).
ENDWHILE.
*delete adjacent duplicates from i_final.
*loop at i_final.
*write:/ i_final-pnumber,i_final-pname,i_final-pdes.
*endloop.
*if not i_final[] is initial.
*modify ztestproduct from table i_final.
*endif.
ENDFORM. " process_dom
in the above code at line no: 268 there is a method:
value = node->get_value( ).in which actual data from XML file is coming.
So the varibale "Value" contains the data.
see line no: 270:
WRITE: AT indent value COLOR COL_GROUP INVERSE.
what ever values i am getting here i want to append to a Internal table ...
Can any body tell me how to do that?
i am sure of reward points.Hai Ravi
REPORT abc.
DATA
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
DATA : BEGIN OF itab OCCURS 0,
a(100) TYPE c,
END OF itab.
DATA: xml_out TYPE string .
DATA : BEGIN OF upl OCCURS 0,
f(255) TYPE c,
END OF upl.
DATA: xmlupl TYPE string .
FIRST PHASE
FIRST PHASE
FIRST PHASE
Fetch Data
SELECT * FROM t001 INTO TABLE t001.
XML
CALL TRANSFORMATION ('ID')
SOURCE tab = t001[]
RESULT XML xml_out.
Convert to TABLE
CALL FUNCTION 'HR_EFI_CONVERT_STRING_TO_TABLE'
EXPORTING
i_string = xml_out
i_tabline_length = 100
TABLES
et_table = itab.
Download
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
filetype = 'BIN'
filename = 'd:\xx.xml'
TABLES
data_tab = itab.
SECOND PHASE
SECOND PHASE
SECOND PHASE
BREAK-POINT.
REFRESH t001.
CLEAR t001.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = 'D:\XX.XML'
filetype = 'BIN'
TABLES
data_tab = upl.
LOOP AT upl.
CONCATENATE xmlupl upl-f INTO xmlupl.
ENDLOOP.
XML
CALL TRANSFORMATION ('ID')
SOURCE XML xmlupl
RESULT tab = t001[].
Regards
Sreeni -
Converting XML string to internal table
Hello everyone,
I am trying to convert an XML string to an internal table. The format of the XML string is as follows:
<node label="Compressors" NODE_ID="783" checked="1" expandStatus="false">
<node label="Nail guns" NODE_ID="78543" checked="1" expandStatus="false"/>
<node label="Spray guns" NODE_ID="855" checked="0" expandStatus="false"/>
<node label="Cleaning equipment" NODE_ID="9" checked="1" expandStatus="false"/>
</node>
What I need is an internal table with the fields NODE_ID and checked filled. The hierarchy here doesn't matter, so I just need an internal table of a structure with 2 fields. The whole XML is hierarchical and contains only the <node> tag, which can be self-closing or not with the attributes within the tag.
What is the best way to accomplish this?
Performance here is quite important too, as this XML can contain over 100,000 nodes.
Should it be done with an xpath expression, with a regex, with the iXML parser, an XSLT call transformation?
Any help is greatly appreciated!
Best regards,
VincentUse this FM to get into internal table
CALL FUNCTION 'ECATT_CONV_XSTRING_TO_STRING'
EXPORTING
im_xstring = zl_attcntx
IMPORTING
ex_string = zl_attcont.
SPLIT zl_attcont AT cl_abap_char_utilities=>newline INTO TABLE zit_legacy. -
To convert XML to ABAP internal table can we do it with DOM or we need XSLT
I have a requirement where I need to collect the data from XML file into an internal table.
I need to collect this data into an internal table as I should make use of this data and do Goods Receipt in SAP.
My XML file is very very complex and the child nodes in my XML file may occur ones or 10 times and change dynamically.
I want to know if XML to ABAP internal table is possible with DOM or does it need XSLT too.
I used the blog of Robert which uses DOM, but it I am unable to collect the data in internal table. The blog explains only how to wtite the out put to screen as element and value.
I want to know if XML to ABAP internal table is possible with DOM or do I need XSLT too? I am confused please help.
Any help will be highly appreciated.
Regards,
Jessica SamHello Jessica
Why not using the DOM itself for processing?
Below you see the post-processing coding which I use to add the interchange control number (ICN) into an EDI message (which at this stage is still an XML-EDI stream). This is done on SAP-XI yet on the ABAP stack so you could use this approach on your R/3 system as well.
method POSTPROCESSING.
* Post-Processing of outbound EDI invoices & dispatch advices
me->map_icn( ).
endmethod.
method MAP_ICN.
* define local data
DATA: lo_node TYPE REF TO if_ixml_node,
ld_name TYPE string,
ld_value TYPE string,
ld_error_code type MPG_ERRCODE,
** ld_control_number TYPE char13,
ld_rc TYPE i,
ld_msg TYPE string. " bapi_msg.
DATA: ld_interface TYPE string.
DATA: incode TYPE REF TO if_ixml_node_collection.
LOG-POINT ID zedi
SUBKEY mc_subkey_method_trace.
ld_error_code = md_clsname.
* Get next interchange control number (ICN)
me->md_next_number = me->get_next_number(
id_nrobj = me->md_nrobj " Object (SNRO)
id_nrnr = me->md_nrnr ). " Number Range
CALL METHOD zcl_edi_uk_counter=>calculate_modulo_n09
EXPORTING
id_input = me->md_next_number
receiving
rd_output = me->md_next_number.
* Build ICN according to naming conventions agreed with EDI customer
me->md_icn = me->generate_icn( me->md_next_number ).
ld_value = me->md_icn. " type conversion to string
CLEAR: incode,
lo_node.
incode = me->mo_document->get_elements_by_tag_name( mc_d_0020 ).
lo_node = incode->get_item( index = 0 ).
CALL METHOD lo_node->set_value
EXPORTING
value = ld_value
RECEIVING
rval = ld_rc.
IF ( ld_rc NE 0 ).
CONCATENATE 'Error [' mc_d_0020
']: Method SET_VALUE (IF_IXML_NODE)'
INTO ld_msg.
CONDENSE ld_msg.
me->mif_trace->trace2( message = ld_msg ).
RAISE EXCEPTION TYPE cx_mapping_fault
EXPORTING
* textid =
* previous =
error_code = ld_error_code
error_text = ld_msg.
** MESSAGE ld_msg TYPE 'A'.
ENDIF.
CLEAR: incode,
lo_node.
incode = me->mo_document->get_elements_by_tag_name( mc_d_0020_2 ). " element for ICN
lo_node = incode->get_item( index = 0 ).
CALL METHOD lo_node->set_value
EXPORTING
value = ld_value
RECEIVING
rval = ld_rc.
IF ( ld_rc NE 0 ).
CONCATENATE 'Error [' mc_d_0020_2
']: Method SET_VALUE (IF_IXML_NODE)'
INTO ld_msg.
CONDENSE ld_msg.
me->mif_trace->trace2( message = ld_msg ).
RAISE EXCEPTION TYPE cx_mapping_fault
EXPORTING
* textid =
* previous =
error_code = ld_error_code
error_text = ld_msg.
** MESSAGE ld_msg TYPE 'A'.
ENDIF.
* define local data
DATA: ls_record TYPE mpp_dynamic.
CLEAR: ls_record.
ls_record-namespace = mc_dynamic_namespace.
ls_record-name = mc_icn.
ls_record-value = ld_value.
mif_dynamic->add_record( ls_record ).
endmethod.
In your case you would need to do a DO...ENDDO loop until you parsed all required nodes.
NOTE: ME->MO_DOCUMENT is of TYPE REF TO IF_IXML_DOCUMENT.
Regards
Uwe -
Converting worbook data into internal table
Hi,
I'm using a FM 'RRMX_WORKBOOK_READ' to read data from a workbook in BI system. My requirement is to get the data into an internal table and I'm using the above FM for this purpose. But the above FM gives data in binary format.... Anbody has any idea how to convert this into internal table format.
Thanks,
Mahesh M.S.get the spool output in raw format using function module
data: it_raw type table of soli.
call function 'RSPO_RETURN_SPOOLJOB'
exporting
rqident = i_spool_nr
FIRST_LINE = 1
LAST_LINE = 1000000000000
desired_type = 'RAW'
IMPORTING
REAL_TYPE =
SP_LANG =
tables
buffer = it_raw
BUFFER_PDF =
exceptions
no_such_job = 1
job_contains_no_data = 2
selection_empty = 3
no_permission = 4
can_not_access = 5
read_error = 6
type_no_match = 7
others = 8.
if the required format is XLS add tabs to split the columns.
constants con_tab type c value cl_abap_char_utilities=>horizontal_tab.
if i_doctype = 'XLS'.
replace all occurrences of '|' in table t_attachment with con_tab.
endif.
Then use 'SO_DOCUMENT_SEND_API1' fucntion module to send XLS file as attachment -
Convert XML to SAP internal table
Hi gurus,
My program is suppose to get current exchange rate file from website and upload it in SAP.
by using FM 'HTTP_GET', im getting the data in XML format.My problem is..i have tried to use transformation but failed to
map it against XML data element..and i have tried to use CALL FUNCTION 'SCMS_TEXT_TO_XSTRING' and then CALL FUNCTION 'SMUM_XML_PARSE' but it returns initial value with error ''line 0 col 12-unexpected symbol: '>'' .
Below is an excerpt of my XML file:
..<xml version>
..<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
.. xmlns:o="urn:schemas-microsoft-com:office:office"
.. xmlns:x="urn:schemas- microsoft-com:office:excel"
.. xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet">
.. <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel"> <WindowHeight>10875</WindowHeight>........ <WindowWidth>13260</WindowWidth><WindowTopX>480</WindowTopX><WindowTopY>30</Wind
.. <Style ss:ID="Default" ss:Name="Normal">
.. <Alignment ss:Vertical="Bottom"/>
.. <Borders/>
.. <Font/>
.. <Interior/>
.. <NumberFormat/>
.. <Protection/>
.. </Style>
.. <Style ss:ID="BoldColumn">
.. <Font ss:FontName="Microsoft Sans Serif" x:Family="Swiss" ss:Bold="1"/>
.. <Worksheet ss:Name="Page1"><Table ss:StyleID="s21" > <Column ss:Width="130"/> <Column ss:Width="85"/> <Column .. ss:Width="85"/> <Column ss:Width="85"/> <Column ss:Widt
.. Cell><Cell ss:MergeAcross="1" ss:StyleID="BoldColumn"><Data ss:Type="String">Average Buying Rates</Data></Cell><Cell .. ss:MergeDown="1" ss:StyleID="BoldColumn"><Data ss:Type="Stri
.. ss:Type="Number">47.3732</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">47.5374</Data></Cell><Cell .. ss:StyleID="Decimal"><Data ss:Type="Number">48.2323</Data></Ce
.. " ><Data ss:Type="String">HONG KONG</Data></Cell><Cell ss:StyleID="StringLiteralCenter" ><Data .. .. ss:Type="String">HKD</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Numb
.. ss:Type="Number">22.8131</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">23.2595</Data></Cell>.. .. </Row><Row><Cell ss:StyleID="StringLiteral" ><Data ss:Type="String"
.. ss:StyleID="StringLiteralCenter" ><Data ss:Type="String">IDR</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">3.0395</Data></Cell><Cell ss:StyleID="Decimal"><Data
.. ecimal"><Data ss:Type="Number">30.6424</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral" ><Data .. ss:Type="String">AUSTRALIA</Data></Cell><Cell ss:StyleID="StringLiteralCe
.. ell ss:StyleID="Decimal"><Data ss:Type="Number">0.3392</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">0.3409</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Typ
.. StringLiteral" ><Data ss:Type="String">DENMARK</Data></Cell><Cell ss:StyleID="StringLiteralCenter" ><Data .. ss:Type="String">DKK</Data></Cell><Cell ss:StyleID="Decimal"><Data ss
.. ata ss:Type="Number">4.4550</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.6073</Data></Cell>.. </Row><Row></Row><Row></Row><Row><Cell ss:MergeAcross="4" ss:Style
.. s of 23 November 2010</Data></Cell></Row><Row></Row><Row><Cell ss:MergeAcross="4" .. ss:StyleID="BoldColumn_Left" ><Data ss:Type="String">2. Foreign Exchange Rates (THOMSON REUTE
.. ><Data ss:Type="String">ZAR</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.2735</Data></Cell>.. <Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.3125</Data></
.. ="Decimal"><Data ss:Type="Number">106.5459</Data></Cell><Cell ss:StyleID="Decimal"><Data .. ss:Type="Number">107.5164</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral" ><Da
.. a></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">4.6916</Data></Cell></Row><Row><Cell .. ss:StyleID="StringLiteral" ><Data ss:Type="String">BANGLADESH</Data></Cell><Cell
.. r">0.0074</Data></Cell></Row><Row><Cell ss:StyleID="StringLiteral" ><Data ss:Type="String">KENYA</Data></Cell><Cell .. ss:StyleID="StringLiteralCenter" ><Data ss:Type="String">KE
.. ><Cell ss:StyleID="StringLiteral" ><Data ss:Type="String">VIET NAM</Data></Cell><Cell ss:StyleID="StringLiteralCenter" >.. <Data ss:Type="String">VND</Data></Cell><Cell ss:StyleI
.. A</Data></Cell><Cell ss:StyleID="StringLiteralCenter" ><Data ss:Type="String">LKR</Data></Cell><Cell .. .. ss:StyleID="Decimal"><Data ss:Type="Number">0.2686</Data></Cell><Cell ss:St
.. String">OMR</Data></Cell><Cell ss:StyleID="Decimal"><Data ss:Type="Number">77.7094</Data></Cell><Cell
Please help me to translate my XML file into SAP format...i need it fixed urgently..
Edited by: Guest101 on Dec 28, 2010 12:11 PMIt has 2 part one is source code and another is the XML file
create an XML file with the data provided in the last 2.
then place it in a path mention the path in the below source.
1. Complete code for converting XML to internal table in SAP.
*& Report ZTST_PGM02
REPORT ZTST_PGM02.
Load iXML Lib.
type-pools: ixml.
class cl_ixml definition load.
data: G_IXML type ref to if_ixml.
data: STREAMFACTORY type ref to if_ixml_stream_factory.
data: ISTREAM type ref to if_ixml_istream.
data: DOCUMENT type ref to if_ixml_document.
data: PARSER type ref to if_ixml_parser.
data: LV_FILE_URL type rlgrap-filename.
You should provide the parameter for file name
LV_FILE_URL = 'D:\navps\input_xml.xml'.
types: begin of XML_LINE,
DATA(256) type x,
end of XML_LINE.
types: begin of TY_HEADER,
CUST_NAME(20) type c,
CARD_NO(20) type c,
TAX_AMOUNT(10) type c,
TOTAL_AMOUNT(10) type c,
end of TY_HEADER.
types: begin of TY_ITEM,
ITEM_NO(4) type n,
ITEM_ID(20) type c,
ITEM_TITLE(50) type c,
ITEM_QTY(10) type c,
ITEM_UPRICE(10) type c,
end of TY_ITEM.
data: GV_HEADER type TY_HEADER.
data: GT_ITEM type standard table of TY_ITEM with header line.
data: XML_TABLE type table of XML_LINE,
XML_TABLE_SIZE type i.
The next step is creating the main factory for the iXML library:
G_IXML = cl_ixml=>create( ).
Now Create Stream Factory
STREAMFACTORY = G_IXML->create_stream_factory( ).
upload a file from the client's workstation
call function 'WS_UPLOAD'
exporting
filename = LV_FILE_URL
filetype = 'BIN'
importing
filelength = XML_TABLE_SIZE
tables
data_tab = XML_TABLE
exceptions
others = 11.
wrap the table containing the file into a stream
ISTREAM = STREAMFACTORY->create_istream_itable( table = XML_TABLE
size = XML_TABLE_SIZE )
Get the file data as Stream
*istream = streamfactory->create_istream_uri( public_id = lv_file_url
system_id = lv_file_url ).
Create XML Document instance
DOCUMENT = G_IXML->create_document( ).
Create parser Object
PARSER = G_IXML->create_parser( stream_factory = STREAMFACTORY
ISTREAM = istream
DOCUMENT = document ).
Parse an XML document into a DOM tree
*parser->parse( ).
Parsing Error Processing
if PARSER->parse( ) ne 0.
if 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 = PARSER->num_errors( ).
write: COUNT, ' parse errors have occured:'.
INDEX = 0.
while INDEX < COUNT.
PARSEERROR = 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.
Close the stream since it #s not needed anymore
call method ISTREAM->close( ).
clear ISTREAM.
Now try to make it look good
data : lv_size type sytabix,
lv_ret_code type sysubrc.
data: lo_xml_document type ref to cl_xml_document.
field-symbols: <fs_xml_data> type any table.
lo_xml_document = document.
call method lo_xml_document->get_as_table
importing
table = <fs_xml_data>
size = lv_size
retcode = lv_ret_code
*data: items type ref to if_ixml_node_collection.
*items = document->get_elements_by_tag_name( name = 'Item' ).
*data: iterator type ref to if_ixml_node_iterator,
node type ref to if_ixml_node.
*iterator = document->create_iterator( ).
*node = iterator->get_next( ).
*while not node is initial.
do something with the node
node = iterator->get_next( ).
*endwhile.
DATA : GV_NODE type ref to if_ixml_node.
DATA : GV_NODETEXT type STRING.
data: GV_FIRST_TIME.
GV_FIRST_TIME = 'X'.
GV_NODE = DOCUMENT.
GT_ITEM-item_no = 1.
perform GET_DATA tables GT_ITEM
using GV_NODE
changing GV_HEADER.
Last item is still not added.
append GT_ITEM.
write : GV_HEADER-cust_name,
GV_HEADER-card_no,
GV_HEADER-tax_amount,
GV_HEADER-total_amount.
loop at GT_ITEM.
write /:.
write : GT_ITEM-item_no,
GT_ITEM-item_id,
GT_ITEM-item_title,
GT_ITEM-item_qty,
GT_ITEM-item_uprice.
endloop.
FORM Get_data *
form get_data tables YT_ITEM structure GT_ITEM
using value(x_node) type ref to if_ixml_node
changing Y_HEADER type TY_HEADER.
data: INDENT type i.
data: PTEXT type ref to if_ixml_text.
data: STRING type string.
data: TEMP_STRING(100).
case X_NODE->get_type( ).
when if_ixml_node=>co_node_element.
STRING = X_NODE->get_name( ).
GV_NODETEXT = STRING.
when if_ixml_node=>co_node_text.
PTEXT ?= X_NODE->query_interface( IXML_IID_TEXT ).
if PTEXT->ws_only( ) is initial.
STRING = X_NODE->get_value( ).
case GV_NODETEXT.
when 'Customer'.
clear GV_HEADER.
when 'Name'.
move STRING to GV_HEADER-cust_name.
when 'Cardnum'.
move STRING to GV_HEADER-card_no.
when 'Tax'.
move STRING to GV_HEADER-tax_amount.
when 'Total'.
move STRING to GV_HEADER-total_amount.
Iteam details
when 'ID'.
move STRING to GT_ITEM-item_id.
when 'Title'.
move STRING to TEMP_STRING.
move TEMP_STRING to GT_ITEM-item_title.
when 'Quantity'.
move STRING to GT_ITEM-item_qty.
when 'UnitPrice'.
move STRING to GT_ITEM-item_uprice.
endcase.
endif.
endcase.
if GV_NODETEXT = 'Customer'.
clear GV_HEADER.
elseif GV_NODETEXT = 'Item'.
if GV_FIRST_TIME ne 'X'.
append GT_ITEM.
clear : gt_item.
GT_ITEM-item_no = gt_item-item_no + 1.
endif.
GV_FIRST_TIME = ' '.
endif.
Get the next child
X_NODE = x_node->get_first_child( ).
Recurse
while not X_NODE is initial.
perform GET_DATA tables GT_ITEM
using X_NODE
changing GV_HEADER.
X_NODE = x_node->get_next( ).
endwhile.
endform.
Create an XML file with the following DATA given below and place it in the path mentioned above source code.
2. XML File DATA. You create an XML File in this format to test the same.
<?xml version="1.0" encoding="ISO-8859-1" standalone="yes" ?>
- <Order>
- <Customer>
<Name>Bill Buckram</Name>
<Cardnum>234 234 234 234</Cardnum>
</Customer>
- <Manifest>
- <Item>
<ID>209</ID>
<Title>Duke: A Biography of the Java Evangelist</Title>
<Quantity>1</Quantity>
<UnitPrice>$10.75</UnitPrice>
</Item>
- <Item>
<ID>208</ID>
<Title>100% Pure: Making Cross Platform Deployment a Reality</Title>
<Quantity>1</Quantity>
<UnitPrice>$10.75</UnitPrice>
</Item>
- <Item>
<ID>204</ID>
<Title>Making the Transition from C++ to the Java(tm) Language</Title>
<Quantity>1</Quantity>
<UnitPrice>$10.75</UnitPrice>
</Item>
- <Item>
<ID>202</ID>
<Title>Web Servers for Fun and Profit</Title>
<Quantity>1</Quantity>
<UnitPrice>$10.75</UnitPrice>
</Item>
- <Item>
<ID>210</ID>
<Title>I Think Not: Dukes Likeness to the Federation Insignia</Title>
<Quantity>1</Quantity>
<UnitPrice>$10.75</UnitPrice>
</Item>
</Manifest>
- <Receipt>
<Subtotal>$53.75</Subtotal>
<Tax>$4.43</Tax>
<Total>$58.18</Total>
</Receipt>
</Order> -
Error converting CSV file into internal table
Hi,
I have to convert a large CSV file (>20.000 entries) into an internal table. I used FM GUI_UPLOAD to get a raw data table then convert this table using FM TEXT_CONVERT_CSV_TO_SAP.
But this does not seem to work properly: after 16.000 or so, the FM seems stuck as if in an endless loop.
Note that if I split the CSV file in several parts, the conversion runs successfully.
Is there any memory limit with this FM ?
Thanks,
FlorianFlorian Labrouche,
Instead of using two function modules, you can use 'TEXT_CONVERT_XLS_TO_SAP' function module once by specifying file name in that function module itself. It does not take much time.
Check the sample program.
report zvenkat-upload-xl no standard page heading.
"Declarations.
"types
types:
begin of t_bank_det,
pernr(8) type c,
bnksa(4) type c,
zlsch(1) type c,
bkplz(10) type c,
bkort(25) type c,
bankn(18) type c,
end of t_bank_det.
"work areas
data:
w_bank_det type t_bank_det.
"internal tables
data:
i_bank_det type table of t_bank_det.
" selection-screen
selection-screen begin of block b1 with frame title text_001.
parameters p_file type localfile.
selection-screen end of block b1.
"At selection-screen on value-request for p_file.
at selection-screen on value-request for p_file.
perform f4_help.
"Start-of-selection.
start-of-selection.
perform upload_data.
"End-of-selection.
end-of-selection.
perform display_data.
"Form f4_help
form f4_help .
data:
l_file_name like ibipparms-path .
call function 'F4_FILENAME'
exporting
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = 'P_FILE'
importing
file_name = l_file_name.
p_file = l_file_name.
endform. " f4_help
"Form upload_data
form upload_data .
type-pools:truxs.
data:li_tab_raw_data type truxs_t_text_data.
data:l_filename like rlgrap-filename.
l_filename = p_file.
call function 'TEXT_CONVERT_XLS_TO_SAP'
exporting
i_tab_raw_data = li_tab_raw_data
i_filename = l_filename
tables
i_tab_converted_data = i_bank_det
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.
endform. " upload_data
" Form display_data
form display_data .
data: char100 type char100.
loop at i_bank_det into w_bank_det .
if sy-tabix = 1.
write w_bank_det.
write / '------------------------------------------------------------'.
else.
write / w_bank_det.
endif.
endloop.
endform. " display_data
Regards,
Venkat.O -
Error in xml to abap internal table transformation using xslt_tool
Hi friends,
When i am trying to convert xml data into internal table it is going to dump because of empty elements. Can any body help to delete the empty tags from xml before processing through xslt_tool.
example
<Activity>
<ID>add12095</ID>
<Start>09/01/2014 12:01</Start>
<Type>3</Type>
<Code>99202</Code>
<Quantity>1</Quantity>
<Net>244</Net>
<Clinician>GD16130</Clinician>
<PriorAuthorizationID/> "empty tag
<Gross>294</Gross>
<PatientShare>50</PatientShare>
<PaymentAmount>244</PaymentAmount>
</Activity>
the empty element some times will come in the xml and some times not. so i made a check in xslt. when this empty element tag processed through that condition i am getting the dump. either i need to remove the condition or we should delete the empty tags before processing. Removing of if condition is not possible because that element may or may not come all the time.
Regards,
Rajesh.You can replace all empty tags using regular expression.
REPLACE ALL OCCURRENCES OF REGEX '<\w+/>' IN lv_xml WITH ''. -
Xml to abap internal table by using a dynamic internal table at runtime
Hi ,
I have a requirement to convert xml to abap internal table . But the requirement is that i need to create internal table according to the XML .
Ex : If my XML is :
<?xml version="1.0" ?>
- <flights>
- <airline code="AA" name="American Airlines">
- <flight number="0017">
<from airport="JFK">NEW YORK,US</from>
<to airport="SFO">SAN FRANCISCO,US</to>
<departure>110000</departure>
<arrival>140100</arrival>
<type>Scheduled</type>
</flight>
- <flight number="0064">
<from airport="SFO">SAN FRANCISCO,US</from>
<to airport="JFK">NEW YORK,US</to>
<departure>090000</departure>
<arrival>172100</arrival>
<type>Scheduled</type>
</flight>
</airline>
So after conversion my abap internal table shoul have fields as :
airline_code Name flight_number from_airport to_airport departure arrival type
and the field values should be corresponding field values .
Thanks in advance .
Regards .Hi Ujjwal,
use
CALL TRANSFORMATION
Study the online documentation and if required do some search for CALL TRANSFORMATION and/or XML PARSER
And, when coming back here with next question, tell us what searches you did with what results - please always follow the 'search before post' rule, thank you.
Regards,
Clemens -
Xml to ABAP internal table mapping and schema validation
Hi Experts,
I'm trying to get data from an xml file into internal tables in ABAP. My requirement is to validate xml against an xsd schema, how can i do it?
My other question is, if there are any possible ways to map the fields of a table so that once the xml file is read, the fields automatically get populated depending on the different elements and attributes in the xml file.
-joeHi,
check out :
http://help.sap.com/saphelp_nw70/helpdata/en/fd/9d734b389211d596a200a0c94260a5/frameset.htm
Terry -
How to get data of tabulated text file into internal table
hi all,
i want to get data from tabulated text file(notepad) into internal table. i searched in SCN and got lot of post regarding how to convert excel file into internal table but i didnt get posts regarding text file.
thanks
SAchintry:
DATA: BEGIN OF tabulator,
x(1) TYPE x VALUE '09',
END OF tabulator.
READ DATASET file INTO wa.
split wa at tabulator into table itab.
A. -
How to Convert internal table data into xml and xml data into internal tab
Hi Guys,
I have a requirement that i have to convert the internal table data into xml format and viceversa . for my requirement i came to know that i have to use Transformations concept. i done the converting the data from internal table into xml data by using standard Tranformations. My Question is
1) Can i use same Transformation to convert the xml data into abap internal table. if it is possible then how ???
2) Is it possible using the standard Transformation or I have to go for XSLT approach
Please help me out from this guys,
Thanks and Regards
KotiHi Koti,
This is possible. There is a link. With the help of this link you can convert ABAP data to XML and vice versa.
Link: http://www.heidoc.net/joomla/index.php?option=com_content&view=article&id=15:sapxslt&catid=22:sap-xslt&Itemid=31 -
Issue with uploading XML file from application server into internal table
i Need to fetch the XML file from the application server and place into internal table and i am getting error message while using the functional module SMUM_XML_PARSE and the error message is "line 1 col 1-unexpected symbol; expected '<', '</', entity reference, character data, CDATA section, processing instruction or comment" and could you please let me know how to resolve this issue?
TYPES: BEGIN OF T_XML,
raw(2000) TYPE C,
END OF T_XML.
DATA:GW_XML_TAB TYPE T_XML.
DATA: GI_XML_TAB TYPE TABLE OF T_XML INITIAL SIZE 0.
DATA:GI_STR TYPE STRING.
data: GV_XML_STRING TYPE XSTRING.
DATA: GI_XML_DATA TYPE TABLE OF SMUM_XMLTB INITIAL SIZE 0.
data:GI_RETURN TYPE STANDARD TABLE OF BAPIRET2.
OPEN DATASET LV_FILE1 FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF SY-SUBRC NE 0.
MESSAGE 'File does not exist' TYPE 'E'.
ELSE.
DO.
* Transfer the contents from the file to the work area of the internal table
READ DATASET LV_FILE1 INTO GW_XML_TAB.
IF SY-SUBRC EQ 0.
CONDENSE GW_XML_TAB.
* Append the contents of the work area to the internal table
APPEND GW_XML_TAB TO GI_XML_TAB.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
* Close the file after reading the data
CLOSE DATASET LV_FILE1.
IF NOT GI_XML_TAB IS INITIAL.
CONCATENATE LINES OF GI_XML_TAB INTO GI_STR SEPARATED BY SPACE.
ENDIF.
* The function module is used to convert string to xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = GI_STR
IMPORTING
BUFFER = GV_XML_STRING
EXCEPTIONS
FAILED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE 'Error in the XML file' TYPE 'E'.
ENDIF.
ENDIF.
IF GV_SUBRC = 0.
* Convert XML to internal table
CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
XML_INPUT = GV_XML_STRING
TABLES
XML_TABLE = GI_XML_DATA
RETURN = GI_RETURN.
ENDIF.
READ TABLE GI_RETURN TRANSPORTING NO FIELDS WITH KEY TYPE = 'E'.
IF SY-SUBRC EQ 0.
MESSAGE 'Error converting the input XML file' TYPE 'E'.
ELSE.
DELETE GI_XML_DATA WHERE TYPE <> 'V'.
REFRESH GI_RETURN.
ENDIF.Could you please tel me why the first 8 lines were removed, till <Soap:Body and also added the line <?xml version="1.0" encoding="UTF-8"?> in the beggining .
Becuase there will be lot of XML files will be coming from the Vendor daily and that should be uploaded in the application server and should update in the SAP tables based on the data in the XML file.
what information i need to give to vendor that do not add the first 8 lines in the XML file and add the line in the beggining <?xml version="1.0" encoding="UTF-8"?> ??????
Is there any other way we can do with out removing the lines?
Maybe you are looking for
-
Error in running Sample Application
When I run sample applications I get the following message in a command window: PANIC: YS::ERROR::ILLEGAL IN JspApp at line 239 of .\wrkctx.c abnormal program termination. Any idea what is wrong. I am running OAS 4.0.8.1 on Windows NT. Gajendra Siroh
-
How to set PSD as the default for Ctrl-S when saving a layered DNG for the first time?
Something has changed in my settings!! My Edit>Preferences>File Handling is checked to require Ask Before Saving Layered TIFF Files. Today I hit Ctrl-S with a layered DNG and it saved it as an Edit.tif What do I need to change so that the default on
-
ISE 1.2.1 - RADIUS service down after Promoting Secondary PAN
Hi Experts, I have currently a ISE deployment where I run a Dual Node construct (both 3495) ISE-1: PAN (Primary), MNT (Secondary), PSN ISE-2: PAN (Secondary), MNT (Primary), PSN When ISE-1 fails and ISE-2 is promoted to Primary PAN then the services
-
Breaking one track into several fluidly
I did a live recording all into one instrument track using the internal microphone on my Macbook. It sounds great, but I'm wanting to produce a CD from it and track each song individually. My problem, when I segment the show with garageband and then
-
Changing the LTS mapping in BMM layer to new Physical Alias table
Experts I need to change the source table mapping in my BMM layer to new physical tables aliases. I have finished BMM layer design (column name changes, business friendly names etc.) before actually creating the alias tables in the Physical layer and