How to parse XML for internal table
hi guys, I would like to know how to parse xml for an internal table. I explain myself.
Let's say you have a purchase order form where you have header data & items data. In my interactive form, the user can change the purchase order quantity at the item level. When I received back the pdf completed by mail, I need to parse the xml and get the po qty that has been entered.
This is how I do to get header data from my form
lr_ixml_node = lr_ixml_document->find_from_name( name = ''EBELN ).
lv_ebeln = lr_ixml_node->get_value( ).
How do we do to get the table body??
Should I used the same method (find_from_name) and passing the depth parameter inside a do/enddo?
thanks
Alexandre Giguere
Alexandre,
Here is an example. Suppose your internal table is called 'ITEMS'.
lr_node = lr_document->find_from_name('ITEMS').
lv_num_of_children = lr_node->num_children( ).
lr_nodechild = lr_node->get_first_child( ).
do lv_num_of_children times.
lv_num_of_attributes = lr_nodechild->num_children( ).
lr_childchild = lr_nodechild->get_first_child( ).
do lv_num_of_attributes times.
lv_value = lr_childchild->get_value( ).
case sy-index.
when 1.
wa_item-field1 = lv_value
when 2.
wa_item-field2 = lv_value.
endcase.
lr_childchild = lr_childchild->get_next( ).
enddo.
append wa_item to lt_item.
lr_nodechild = lr_nodechild->get_next( ).
enddo.
Similar Messages
-
Hello,
Can anyone help me to know how to parse xml in sap abap.
I have a xml file which i want to parse and store it in internal table.
<?xml version="1.0" encoding="UTF-8"?>##<data><name>menaka<name></data>
Regards,
Menaka.H.BHello,
For how to get the node name, you have to refer to this :
[https://wiki.sdn.sap.com/wiki/display/ABAP/Upload%20XML%20file%20to%20internal%20table|https://wiki.sdn.sap.com/wiki/display/ABAP/Upload%20XML%20file%20to%20internal%20table]
Check the code after:
WHEN if_ixml_node=>co_node_element
It tells you how to get the node name.
BR,
Suhas -
How to parsing xml data in sql statement??
Hi friends, I have a table which contain column as clob ,stores in xml format, for example my column contain xml data like this
<Employees xmlns="http://TargetNamespace.com/read_emp">
<C1>106</C1>
<C2>Harish</C2>
<C3>1998-05-12</C3>
<C4>HR</C4>
<C5>1600</C5>
<C6>10</C6>
</Employees>
Then how to extract the data in above xml column data using SQL statement...Duplicate post
How to parsing xml data in sql statement?? -
How to create an dynamic internal table with the structure of a ddic table
Hi all,
I want to fill ddic-tables (which I already created) in my abap dictionary with data out of CSV-files (which are located on the CRM-Server). The ddic tables have different amount of fields.
I started with creating a table which contains the name of the tables and the path to the matching CSV-file.
At the beginning I'm filling an internal table with part of this data (the name of the ddic-tables) - after that I am looping at this internal table.
LOOP AT lt_struc ASSIGNING <lfs_struc>.
LOOP AT lv_itab1 INTO lv_wa1 WHERE ztab_name = <lfs_struc>.
lv_feld = lv_wa1-zdat_name.
ENDLOOP.
CONCATENATE 'C:\-tmp\Exportierte Tabellen\' lv_feld INTO lv_pfad.
Do.
OPEN DATASET lv_pfad FOR INPUT IN TEXT MODE ENCODING NON-UNICODE IGNORING CONVERSION ERRORS.
READ DATASET lv_pfad INTO lv_rec.
IF sy-subrc NE 0.
EXIT.
ENDIF.
enddo.
REPLACE ALL OCCURRENCES OF '"' IN lv_rec WITH ''.
SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
INSERT into (<lfs_struc>) values lr_str_value.
CLOSE DATASET lv_pfad.
endloop.
This is not the whole code, but it's working until
SPLIT lv_rec AT ';' INTO TABLE lt_str_values.
I want to split all the data of lv_rec into an internal table which has the structure of the current ddic-table, but I didn't find out how to do give the internal table the structure of the ddic-table. In the code I used an internal tyble type string but I should be the structure of the matching tabel.
If I try to create an internal table by using a fiel symbol, I am told, that the data types are not matching.
Has anyone an idea?Hi Mayari,
though you were successfull with
METHOD cl_alv_table_create=>create_dynamic_table
I must warn you not to use it. The reason is that the number of tables created is limited, the method uses GENERATE SUBROUTINE statement and this triggers an unwanted database commit.
If you know the DDIC structure, it is (starting with ECC6.0) much easier:
field-symbols:
<table> type standard table.
data:
lr_data type ref to data.
Create data lr_data type table of (<DDIC structure>).
assign lr_data->* to <table>.
The split code can be simplified gaining speed loosing complexity not loosing functionality.
field-symbols:<fs_s> type any.
field-symbols:<fs_t> type any.
SPLIT lv_rec AT ';' INTO table it_string.
loop at it_string assigning <fs_s>.
assign component sy-tabix of wa_string to <fs_t>.
if sy-subrc = 0.
<fs_t> = <fs_s>.
endif.
at last.
append <fs_itwa3> to <ft_itab3>.
endat.
endloop.
Though it may work as Keshav.T suggested, there is no need to do that way.
Regards,
Clemens -
*How can we use the internal table in module pool programming? Clarify plz*
If we creating a screen using the table having four fields(for e.g.). The screen has the functions of display, modify, delete, save, exit etc for the fields. The front-end of the screen having I/O fields of the table using internal table. How can we declare the internal table in the screen?
HI,
Create one WA for your Internal table and then map it to your fields.
For Example,
Data : begin of wa,
name(10),
age type i,
end of wa.
data : it like table of wa with header line.
Then in screen create input fields with the name, age and ***.
Then the user entered values are stored in name age and ***.
then you can manipulate with that values using wa.
Thanks. -
i've searched on how to parse xml against xsd,dtd,etc.. without the needs of internet connection..
but unfortunately, only the xsd file can be set locally and still there needs the internet connection for the other features, properties.
XML: GML file input from gui
XSD: input from gui
javax.xml
package demo;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.XMLConstants;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.SAXException;
public class Sample1WithJavaxXML {
public static void main(String[] args) {
URL schemaFile = null;
try {
//schemaFile = new URL("http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd");
File file0 = new File("AppSchema-C01-v1_0.xsd");
schemaFile = new URL(file0.toURI().toString());
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
//Source xmlFile = new StreamSource(new File("web.xml"));
Source xmlFile = new StreamSource(new File("C01.xml"));
SchemaFactory schemaFactory = SchemaFactory
.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
//File file1 = new File("XMLSchema.dtd");
//SchemaFactory schemaFactory = SchemaFactory
//.newInstance("javax.xml.validation.SchemaFactory:XMLSchema.dtd");
Schema schema = null;
try {
schema = schemaFactory.newSchema(schemaFile);
} catch (SAXException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
Validator validator = schema.newValidator();
try {
validator.validate(xmlFile);
System.out.println(xmlFile.getSystemId() + " is valid");
} catch (SAXException e) {
System.out.println(xmlFile.getSystemId() + " is NOT valid");
System.out.println("Reason: " + e.getLocalizedMessage());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}Xerces
package demo;
import java.io.File;
import java.util.Date;
import org.apache.xerces.parsers.DOMParser;
public class SchemaTest {
private String xmlFile = "";
private String xsdFile = "";
public SchemaTest(String xmlFile, String xsdFile) {
this.xmlFile = xmlFile;
this.xsdFile = xsdFile;
public static void main (String args[]) {
File file0 = new File("AppSchema-C01-v1_0.xsd");
String xsd = file0.toURI().toString();
SchemaTest testXml = new SchemaTest("C01.xml",xsd);
testXml.process();
public void process() {
File docFile = new File(xmlFile);
DOMParser parser = new DOMParser();
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema", true);
parser.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
xsdFile);
ErrorChecker errors = new ErrorChecker();
parser.setErrorHandler(errors);
System.out.println(new Date().toString() + " START");
parser.parse(docFile.toString());
} catch (Exception e) {
System.out.print("Problem parsing the file.");
System.out.println("Error: " + e);
System.out.println(new Date().toString() + " ERROR");
return;
System.out.println(new Date().toString() + " END");
}Thanks a lot Sir DrClap..
I tried to use and implement the org.w3c.dom.ls.LSResourceResolver Interface which is based on the SAX2 EntityResolver.
please give comments the way I implement it. Here's the code:
LSResourceResolver Implementation
import org.w3c.dom.ls.LSInput;
import org.w3c.dom.ls.LSResourceResolver;
import abc.xml.XsdConstant.Path.DTD;
import abc.xml.XsdConstant.Path.XSD;
public class LSResourceResolverImpl implements LSResourceResolver {
public LSResourceResolverImpl() {
* {@inheritDoc}
@Override
public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
LSInput input = new LSInputImpl(publicId, systemId, baseURI);
if ("http://www.w3.org/2001/xml.xsd".equals(systemId)) {
input.setByteStream(classLoader.getResourceAsStream(XSD.XML));
} else if (XsdConstant.PUBLIC_ID_XMLSCHEMA.equals(publicId)) {
input.setByteStream(classLoader.getResourceAsStream(DTD.XML_SCHEMA));
} else if (XsdConstant.PUBLIC_ID_DATATYPES.equals(publicId)) {
input.setByteStream(classLoader.getResourceAsStream(DTD.DATATYPES));
return input;
}I also implement org.w3c.dom.ls.LSInput
import java.io.InputStream;
import java.io.Reader;
import org.w3c.dom.ls.LSInput;
public class LSInputImpl implements LSInput {
private String publicId;
private String systemId;
private String baseURI;
private InputStream byteStream;
private String stringData;
public LSInputImpl(String publicId, String systemId, String baseURI) {
super();
this.publicId = publicId;
this.systemId = systemId;
this.baseURI = baseURI;
//getters & setters
}Then, here's the usage/application:
I create XMLChecker class (SchemaFactory implementation is Xerces)
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.xml.XMLConstants;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;
import javax.xml.validation.Validator;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
import abc.xml.XsdConstant.Path.XSD;
public class XMLChecker {
private ErrorMessage errorMessage = new ErrorMessage();
public boolean validate(String filePath){
final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
List<Source> schemas = new ArrayList<Source>();
schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XML_SCHEMA)));
schemas.add(new StreamSource(classLoader.getResourceAsStream(XSD.XLINKS)));
schemas.add(new StreamSource(classLoader.getResourceAsStream("abc/xml/AppSchema.xsd")));
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setResourceResolver(new LSResourceResolverImpl());
try {
Schema schema = schemaFactory.newSchema(schemas.toArray(new Source[schemas.size()]));
Validator validator = schema.newValidator();
validator.setErrorHandler(new ErrorHandler() {
@Override
public void error(SAXParseException e) throws SAXException {
errorMessage.setErrorMessage(e.getMessage());
errorMessage.setLineNumber(e.getLineNumber());
errorMessage.setColumnNumber(e.getLineNumber());
throw e;
@Override
public void fatalError(SAXParseException e) throws SAXException {
errorMessage.setErrorMessage(e.getMessage());
errorMessage.setLineNumber(e.getLineNumber());
errorMessage.setColumnNumber(e.getLineNumber());
throw e;
@Override
public void warning(SAXParseException e) throws SAXException {
errorMessage.setErrorMessage(e.getMessage());
errorMessage.setLineNumber(e.getLineNumber());
errorMessage.setColumnNumber(e.getLineNumber());
throw e;
StreamSource source = new StreamSource(new File(filePath));
validator.validate(source);
} catch (SAXParseException e) {
return false;
} catch (SAXException e) {
errorMessage.setErrorMessage(e.getMessage());
return false;
} catch (FactoryConfigurationError e) {
errorMessage.setErrorMessage(e.getMessage());
return false;
} catch (IOException e) {
errorMessage.setErrorMessage(e.getMessage());
return false;
return true;
public ErrorMessage getErrorMessage() {
return errorMessage;
}Edited by: erossy on Aug 31, 2010 1:56 AM -
Hi! I'm having problems parsing an xml string. I've done DOM and SAX parsing before. But both of them either parse a file or data from an input source. I don't think they handle strings. I also don't want to write the string into a file just so I can use DOM or SAX.
I'm looking for something where I could simply do:
Document doc = documentBuilder.parse( myXMLString );
So the heirarchy is automatically established for me. Then I could just do
Element elem = doc.getElement();
String name = elem.getTagName();
These aren't the only methods I would want to use. Again, my main problem is how to parse xml if it is stored in a string, not a file, nor comming from a stream.
thanks!But both of them either parse a file or data from an input source. I don't think they handle strings.An InputSource can be constructed with a Reader as input. One useful subclass of Reader is StringReader, so you'd use something likeDocument doc = documentBuilder.parse(new InputSource(new StringReader(myXMLString)));
-
System Variable For Internal table count
Can anybody tell me what the system variable for internal table count?
I just wants to know how many recoreds are there in my internal table ?
Regards,
pandu.Hi ,
DESCRIBE TABLE <itab> [LINES <l>] [OCCURS <n>] [KIND <k>].
If you use the LINES parameter, the number of filled lines is written to the variable <lin>. If parameter, the you use the OCCURS value of the INITIAL SIZE of the table is returned to the variable <n>. If you use the KIND parameter, the table type is returned to the variable <k>: T for standard table, S for sorted table, and H for hashed table.
using variable
SY-TFILL
After the statements DESCRIBE TABLE, LOOP AT, and READ TABLE, SY-TFILL contains the number of lines in the relevant internal table.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3798358411d1829f0000e829fbfe/content.htm
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Feb 21, 2008 4:53 PM -
Aggregate functions for internal table.
Hi Gurus,
I'm just wondering whether we can use aggregate functions for internal table. I wanted to know the max value for a particular column in my internal table. How can I achieve this easily and quickly.
Thanks,
David.sort the table on which you want the maximum value and read it. Please find below example code.
TYPES : BEGIN OF ty_mvke,
matnr TYPE mvke-matnr,
vkorg TYPE mvke-vkorg,
vtweg TYPE mvke-vtweg,
AUMNG type mvke-AUMNG,
END OF ty_mvke.
DATA : wa_mvke TYPE ty_mvke,
it_mvke TYPE STANDARD TABLE OF ty_mvke.
data : temp_AUMNG type AUMNG.
START-OF-SELECTION.
SELECT matnr vkorg vtweg AUMNG FROM mvke INTO
table it_mvke.
sort it_mvke by AUMNG.
read TABLE it_mvke into wa_mvke INDEX 1.
if sy-subrc = 0.
move wa_mvke-AUMNG to temp_AUMNG.
write : temp_AUMNG.
endif.
Thanks,
Sreekala. -
Xml to Internal table : Issue
Dear All,
I have written a program to bring the data from xml to internal table Below is the strucutre of my xml file .
- <Data>
- <MT Type="CR">
<MatType>FERT</MatType>
</MT>
- <OP Type="CR">
<MatNumber>9901040103-000115</MatNumber>
- <Activities Element="AT">
- <AT Type="CR">
<MaterialNumber>115</MaterialNumber>
<ActivityType>DEPR.</ActivityType>
</AT>
- <AT Type="CR">
<MaterialNumber>117</MaterialNumber>
<ActivityType>L.C.R</ActivityType>
</AT>
</Activities>
</OP>
</Data>
.However I am not able to handle the multiple entries which comes together . ie
- <AT Type="CR">
<MaterialNumber>115</MaterialNumber>
<ActivityType>DEPR.</ActivityType>
</AT>
- <AT Type="CR">
<MaterialNumber>117</MaterialNumber>
<ActivityType>L.C.R</ActivityType>
</AT>
Please let me know how to handle this . Thanks!
Regards,
SyedHi ,
To convert XML data into internal table u have to use FM "SMUM_XML_PARSE", this FM takes XString as input ,so first u have to
convert ur xml string into XString using FM "SCMS_STRING_TO_XSTRING".
Thanks
jitendra -
How to parse xml file in midlet
Hi Guys,
i wish to parse xml file and display it in my midlet. i found api's supporting xml parsing in j2se ie., in java.net or j2se 5.0. Can u please help me what package to use in midlet?
how to parse xml info and display in midlet? Plz reply soon......Thanks in advance....i have exactly the same problem with KXml2, but using a j2me-polish netbeans project.
i've tried to work around with similar ways like you, but none of them worked. now i've spent 3 days for solving this problem, i'm a bit disappointed :( what is wrong with setting the downloaded kxml2 jar path in libraries&resources?
screenshot -
How to create view for xmltype table in oracle
hi:
Can some one help me how to create view for xmltype table in oracle?
XMLType do not have column
SemThank you !!
I read it and become very hard to implement what I want to do.
Can you give me example please?
My main goal to create view for xmltype table is to XQuery the XML data?
Do you have any other suggestion?
Please help
Ali_2 -
Simple transformation error in converting XML to internal table
Hi Team,
I have an issue, its working in Dev, QA, and Prod in PI 7.0, once we upgrade it to PI 7.1 I'm getting the below mention error,
Unknown Simple transformation error in converting XML to internal table
Application error in mapping program ZF_INT006_FILE_TO_SAP_FILE, error code: , error text: Unknown Simple transformation error in converting XML to internal table An exception has occurred.
Can any one suggest related notes are suggestion.
appericate in advance for the solutions which you all provide me
Thank you
Venkat AnilCheck the flag "use SAP XML toolkit" for the operation mapping and try, if that works then.
Check the flag for all XSLT and Java mappings which is migrated from PI 7.0 -
How to create dynamic nested internal table
Hi Experts,
Pleae tell me or give sample code, how to create dynamic nested internal table ?
I have seen threads saying creation of dynamic internal tables using some table structure only. But now the requirement is to create dynamic nested internal table.
For example the internal table contains two fields viz., one is field1 of dynamic internal table and other is normal field2 and values as shown below:
Nested internal table:
field1 | field2 ...
<table content1> | value2..
<table content1> | value2..
Here the [table content] should also a dynamic internal table.
Let me know if you need any other info.
regards
Saravanan Rsee the complete code..i am currently working in ECC6.0 EHP4. just check which version you are using..
REPORT yst_test_000.
DATA:
lt_comptab TYPE cl_abap_structdescr=>component_table,
ls_comp LIKE LINE OF lt_comptab,
lref_newstr TYPE REF TO cl_abap_structdescr,
lref_tab_type TYPE REF TO cl_abap_tabledescr,
lt_fcat TYPE lvc_t_fcat,
ls_fcat TYPE lvc_s_fcat,
ls_dd03p TYPE dd03p,
lt_data type ref to data.
field-symbols: <fs_table> type standard table.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'SCARR'
CHANGING
ct_fieldcat = lt_fcat
EXCEPTIONS
inconsistent_interface = 1
program_error = 2
OTHERS = 3.
IF sy-subrc NE 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
LOOP AT lt_fcat INTO ls_fcat.
IF ls_fcat-ref_table IS NOT INITIAL.
CLEAR ls_dd03p.
CALL FUNCTION 'BUS_DDFIELD_GET'
EXPORTING
i_tabnm = ls_fcat-ref_table
i_fldnm = ls_fcat-fieldname
IMPORTING
e_dd03p = ls_dd03p
EXCEPTIONS
field_not_found = 1
OTHERS = 2.
IF sy-subrc EQ 0.
ls_comp-name = ls_fcat-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_dd03p-rollname ).
APPEND ls_comp TO lt_comptab.
CLEAR ls_comp.
ENDIF.
ELSE.
ls_comp-name = ls_fcat-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
APPEND ls_comp TO lt_comptab.
CLEAR ls_comp.
ENDIF.
ENDLOOP.
*Now for the Field which you want deep table then you can do like this
ls_fcat-fieldname = 'NESTED_TABLE'.
ls_fcat-inttype = 'C'.
ls_fcat-intlen = '000006'.
ls_fcat-rollname = 'SFLIGHT_TAB1'. "For SFLIGHT
APPEND ls_fcat TO lt_fcat.
ls_comp-name = ls_fcat-fieldname.
ls_comp-type ?= cl_abap_datadescr=>describe_by_name( ls_fcat-rollname ).
APPEND ls_comp TO lt_comptab.
CLEAR ls_comp.
lref_newstr = cl_abap_structdescr=>create( lt_comptab ).
lref_tab_type = cl_abap_tabledescr=>create( lref_newstr ).
create data lt_data type handle lref_tab_type.
assign lt_data->* to <fs_table>.
break-point.
Edited by: Vijay Babu Dudla on Apr 28, 2009 8:05 AM -
How to parse xml and import to execel
pls let me know how to parse XML file and import all data to execel sheet.
Hi Mandya,
This is outside of the normal use case for TestStand. It would be best to use a code module (developed in LabVIEW, C, or any other language) to accomlish this and then call it from a step in TestStand. You can find examples on ActiveX here:
http://forums.ni.com/t5/NI-TestStand/Controlling-Excel-from-TestStand-with-Activex-Automation/td-p/1...
I hope this helps.
Frank L.
Software Product Manager
National Instruments
Maybe you are looking for
-
Snowleopard broke my intern Superdrive on MacBook Pro (Original)
Hello, As by Thomas A Reed sugested (in my first thread, maybe someone can delete the one), i start a new thread, to keep it oversight and clear. Right now, i'm convinced, my case belongs to the 10.6 thread. The main threads about this problems seems
-
No Error Log generated in 'Costing' step in Costing Run (CK40N)
In the Costing Run, when the 'Costing' step is run (after 'Material selection' and 'BOM Explosion' steps), it gives a hard stop when it encounters the 1st error, instead of completing the 'Costing ' step and giving an Error Log with material informa
-
How can I... 1. Display the number of vowels, consonants, other characters, 2. Display the percent of vowels, consonants, other characters, 3. Display a pie chart using the above information, 4. All of this must be done in an applet. 5. Here is the p
-
Export to Excel - currency problem
Post Author: bontempi CA Forum: Exporting I'm using Crystal Reports 8.5 with Visual Basic 6. If I export to Excel using either the built in button on the report viewer toolbar, or using the Export function then any £ symbols are changed to $ symbols
-
Hello members, My requirement is to deaI with xml totally as a database instead of taking any data base(like oracle etc..).I.e i have to deal with all the operations like update,delete, insert etc to the xml file from my java application.So that my a