Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

XML to deep/complex ABAP table

Former Member
0 Kudos

Hello

I can successfully transform an XML file into an internal table with a flat structure.

But I would like to use an internal table with a deep/complex structure representing the relationship of some of data elements.

Has anyone been able to transform an XML into an internal table with deep/complex structure?

Regards, Steve

6 REPLIES 6

Former Member
0 Kudos

Hi,

You can create an internal table with a deep structure by introducing data declaration as shown below:

DATA: BEGIN OF it_test OCCURS 0,

f1 TYPE mara,

f2 TYPE marc,

END OF it_test.

Here F1 will have all the fields of table MARA and F2 will have all the fields of table MARC.

Regards,

Rajesh.

0 Kudos

Thanks for the reply Rajesh.

I should explain further... I have no trouble creating the deep/complex table in ABAP, ie table nested within another table. I am already able to transform an XML file into the deep fields, but I cannot figure out how to push data into the nested table via the transformation.

My problem is in writing the XSLT to perform the transformation into the complex part of the structure. Ideally I'd like to see an example if anyone has one.

Cheers, Steve

0 Kudos

Hi all

I eventually found an old SDJ article entitled "Mastering the asXML format to Leverage ABAP-XML Serialization". Understanding the asXML format for my particular requirement was the key to building my XSLT.

Briefly here's the steps I took to determine how the asXML should look:

I changed my ABAP to populate the complex internal table with some dummy data and changed the direction of my transformation to produce asXML from the internal table. By complex I mean an internal table with a nested table as one of its fields.

My call to the transformation now looks like this:


  CALL TRANSFORMATION ID
    SOURCE thisone = lt_complextable
    RESULT XML lt_xml. " asxml.

Using keyword "ID" tells the transformation to produce an asXML stream instead of performing a transformation via my XSLT. "thisone" is a dummy tag that is written into the stream and surrounds the data.

Looking at the resulting lt_xml I can now see what my XSLT needs to output. Now that I know what format the asXML needs to be I am able to modify my XSLT accordingly.

There is quite a bit of code involved in a demo so I won't post it all here but if anyone is interested I'll write up a document with all the sample code etc.

Cheers, Steve

0 Kudos

Hi Steven,

I have a similar requirement where we are trying to store the xml document into SAP so that we can execute some reports out of SAP. The xml structure needs to be mapped to complex ABAP tables and so i would like to know the steps which you executed to achieve this on your end. Some pointers or sample code would be useful.

Thanks for your help in advance.

Thanks

0 Kudos

Hi Hemant

I abandoned the transformation and chose to process my XML files using the iXML library.

Essentially the process is to read the XML file into an internal table, convert it to a stream and then parse it into a DOM (Document object model).

The DOM nodes are then read according to how the XML is structured and values written to internal structures and table accordingly.

I found this approach a lot simpler than building the complex transformation. Parsing the XML files was very fast (but they are only about 10K) and then iterating through all the nodes equally fast.

My final solution was to create TYPES in ABAP with field names matching all the expected element names in the XML. My node processing method then did an assignment of the element value to the field in a structure with a matching field name. However the method calls itself recursively when the ABAP field is a deep structure.

There is plenty of SAP help available for the iXML library and the "jumpstart" is a really good place to start as it contains good simple examples that you can use immediately.

Try the following link:

http://help.sap.com/saphelp_nw70/helpdata/EN/4c/b5413acdb62f70e10000000a114084/frameset.htm

Cheers, Steve

0 Kudos

Hey Steve,

I do have exactly the same Problem with parsing huge, deep structured XML. Do have some example coding?

Thanks a lot,

--Alex