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: 

Convert XML to SAP

former_member474499
Participant
0 Kudos
1,090

Hello everybody,

I want to create a program that will read an input file and save the information in the system.

The problem is that my file is an XML one with at least 128 tags (the max is 294 tags).

After searching on google I found some MF like FILE_READ_AND_CONVERT_SAP_DATA and TEXT_CONVERT_XML_TO_SAP.

Can you please tell me if this conversion is possible? If yes, can you please tell me the steps to get the suitable result?

It's really urgent. I wish you can give me some tracks to solve the issue.

Thank you in advance.

Kind regards.

Hk

8 REPLIES 8

former_member16322
Participant
0 Kudos
436

I'm not sure if there is a standard method for reading XML into SAP.

If I had to code this myself, I would create tables that map the XML contexts (tags) to specific fields.

1. Read XML file into ABAP memory (should be possible with GUI_UPLOAD or OPEN DATASET)

2. Read Table that maps XML Contexts to specific Database Structures/Fields.

3. Loop at XML file, as the tags switch context, make sure you are working with the correct Database Structures/Fields based upon your mapping.

4. After file has been processed, write changes to database.

For example, if you were bringing in material information, assuming a structure similar to this:

<material>

     <number>data</number>

     <desc>data</desc>

</material>

Your map table could look as follows:

TAG          Type          Map

material     S               MARA

number      F               MATNR

desc          B               MAKT-MAKTX

As you read through the file, you would need to change the structure and fields you are working with based upon the map.

Reading line 1: <material> = switch to using MARA structure in ABAP

Reading line 2: <number> = assign data value to MATNR in Structure MARA

Reading line 3: <desc> = Assign value to MAKT-MAKTX, notice I had to fully qualify the structure to

use and the field to apply to; you would populate MAKT-MATNR from MARA-MATNR, since it is with in the same Material context.

Using a method like this, and if created general enough, you should be able to just build the MAP table to control how the files are read in and processed.

This is not fully fleshed out obviously, but I believe it would be a good starting place.

former_member474499
Participant
0 Kudos
436

Hello Steve,

Thank you for your answer.

I have two questions about your solution:

1 - If for example I have an XML file like that:

<material>

<number>

            <number1>data</number1>

     </number>

<desc>data</desc>

     <field3>

            <field4>

            <field5>data</field5>

</field4>

     </field3>

</material>

How would my internal table be?

2 – Do you think that this solution is good for an XML file that can contain between 128 and 294 tags? I think that way, may be a lot of mistakes will be made? what do you think?

If you have any other solution, please let me know.

Thank you a lot for your help.

Best regards.

0 Kudos
436

1. The specific mapping would be dependent on the XML files. There may be xml tags you skip, etc. That would need to be decided by your developers; I was simply providing a broad strokes initial idea (as I mentioned, not completely fleshed out). For example, I did not mention it, but you would probably want to allow for multiple maps; this was only intended to be the seed of an idea.

2. I believe the solution, if fully generalized and thought out would be great for high tag count XML documents, as you would be just filling the mapping table and it would know how to parse the file. The table contents for the map would be similar to writing code, if the program was properly built, so it would be relatively involatile and would be maintained by a developer. Changes to the table would require testing, etc.

Once again, this was intended to be an idea that could be expanded, not necessarily a final solution, the details of this would need to be sorted out by your developers.

former_member474499
Participant
0 Kudos
436

Ok Steve thank you for your help.

0 Kudos
436

I'm not a PI developer, so I did not think about it; but if you have SAP PI, you could use that to pick up your file and handle the mapping. Sorry I did not think about it until just now.

I'm not sure what is involved with this, but I know at my company we receive XML files through PI and then have interfaces from PI to ERP that handle the updates.

former_member474499
Participant
0 Kudos
436

Hello Steve,

We have SAP PI but our developers don't know how to receive XML files. Till now we used PI for receiving normal files.

If anyone knows how to deal with XML in PI, please let me know.

Kind regards

Former Member
0 Kudos
436

There is an excellent blog by Robert Eijpe which I found most helpful when converting from ABAP to XML and vice versa.

http://scn.sap.com/people/r.eijpe/blog/2005/11/21/xml-dom-processing-in-abap-part-ii--convert-an-xml...

former_member474499
Participant
0 Kudos
436

Hello,

Thank you for your answers.

Kind regards.