cancel
Showing results for 
Search instead for 
Did you mean: 

IDOC To XML Scenario

Former Member
0 Kudos
96

Hi all,

In my scenario I need to map fields of IDOC XML to a v complex and generic Enevelope ( XML ) <b>As well as send the entire IDOC XML as a string to one of the fields of the target Envelope XML</b> </b> Now wht is the best approach for mapping :

Java / XSLT ?

Is there any better simpler method to achieve this requiremnet ?

Thanks and Regards,

KLK

Accepted Solutions (0)

Answers (1)

Answers (1)

agasthuri_doss
Active Contributor
0 Kudos

Hi K.L.K,

If the data size is more then it is better to go for Java,XSLT mapping will consume more memory

Regards

Agasthuri Doss

former_member206604
Active Contributor
0 Kudos

Hi,

You can go for Java or XSLT mapping

XSLT code for copying to single field

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Target>
<SingleField>
 <xsl:copy-of select="." />
</SingleField>
</Target>
</xsl:template>
</xsl:stylesheet>

You can refer this thread and check out the post by Bhavesh for Java mapping

Thanks,

Prakash

Former Member
0 Kudos

Hi Prakash,

Thanks for the valuable input , apart from sending the whole IDOC XML as string I also need to MAP IDOC fields to the Target XML also in the same Mapping

So do u still suggest using Java Mapping for BOTH ( Fields as well as whole Idoc as string ) ?

If I could use Message mapping for field mapping my life would be lot more easier

Clarify a bit more

Regards,

KLK

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

One option, use multiple Mappings in Interface Mapping + Global Container / GLobal Variables.

First Mapping will be java which will convert the input stream into String XML and save it into the global variable. Output of this mapping will be the same input.

Next, message mapping, use the global variable in previous step to map it to target.

Havent tried this, but , worth a try.

Regards,

Bhavesh

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

One option, use multiple Mappings in Interface Mapping + Global Container / Global Variables.

First Mapping will be java which will convert the input stream into String XML and save it into the global variable. Output of this mapping will be the same input.

Next, message mapping, use the global variable in previous step to map it to target.

Haven't tried this, but,worth a try.

Regards,

Bhavesh

former_member206604
Active Contributor
0 Kudos

Hi,

You can try as Bhavesh said using multiple mapping programs.

Or

Just modify the existing XSLT mapping and do it. I think it very simple and easy

eg:

<?xml version='1.0'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<Target>
<Field1><xsl:value-of select="IDOCXPath"/></Field1>
<Field2><xsl:value-of select="IDOCXPath"/></Field2>
<Field3><xsl:value-of select="IDOCXPath"/></Field3>
<SingleField>
 <xsl:copy-of select="." />
</SingleField>
</Target>
</xsl:template>
</xsl:stylesheet>

Field1, Field2 and Field3 are the target fields. IDOCXpath is the Xpath of the value to be mapped from the source IDOC.

Thanks,

Prakash

Former Member
0 Kudos

Hi Bhavesh,

I tried java mapping followed by Msg Mapping I get the

following Erro :

com.sap.aii.utilxi.misc.api.BaseRuntimeException: Parsing an empty source. Root element expected

My input stream is exhausted in the Java Mapping itself

though I tried saving the inputstream , increasing the

source and target Interfaces in the mapping nothing worked !!

Prakas -

I dont have a XSLT editor to enhance the code u have given to fit my scenario !!

Guys , It would be great if u could suggest me a workable solution .

Thanks and Regards,

KLK

Former Member
0 Kudos

Attached is the code in Java Mapping

private InputStream payload ;

/* (non-Javadoc)

  • @see com.sap.aii.mapping.api.StreamTransformation#setParameter(java.util.Map)

*/

public void setParameter(Map arg0) {

this.param = arg0;

if (param == null) {

this.param = new HashMap();

}

}

/* (non-Javadoc)

  • @see com.sap.aii.mapping.api.StreamTransformation#execute(java.io.InputStream, java.io.OutputStream)

*/

public void execute(InputStream arg0, OutputStream arg1)

throws StreamTransformationException {

DefaultHandler handler = this;

try {

payload = arg0;

BufferedReader inp = new BufferedReader(new InputStreamReader(payload));

StringBuffer buffer = new StringBuffer();

String line="";

while ((line = inp.readLine()) != null) {

buffer.append(line);

}

source=buffer.toString();

if(source != null)

param.put("key1",source);

else

param.put("key1","Its Empty");

}

catch (Exception e){

e.printStackTrace();

}

}

former_member206604
Active Contributor
0 Kudos

Hi,

You don't need a editor basically for writing a XSLT mapping. Whatever mapping you are going to do you need to parse the XML document so you do the same here in XSLT and which is simple. How many fields from your IDOC should be mappied to the target apart from the whole XML in one tag? In above code you just need to change the Field1..Fieldn to your Target field names and the IdocXPath is simple, the path from the root.

Eg:

IDOC

- DELVRY03

- SomeSegment

- Field1

your xpath is IDOC/DELVRY03/SomeSegment/Field1

thats it., repeat the same for all the fields

Thanks,

Prakash

Former Member
0 Kudos

Hi Prakash,

I am trying as u suggested but not getting values in the Target XML while testing from Interface Mapping

My Source IDOC Structure :

<?xml version="1.0" encoding="UTF-8"?>

<ZEU_MATMAS03>

<IDOC BEGIN="">

<EDI_DC40 SEGMENT="">

<TABNAM/>

<MANDT/>

<DOCNUM/>

my XSLT program

<?xml version='1.0'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<MATERIAL>

<MATNO><xsl:value-of select="ZEU_MATMAS03/IDOC/EDI_DC40/DOCNUM"/></MATNO>

<MATTEXT>

When I test the interface mapping I get the following out put :

<?xml version="1.0" encoding="utf-8"?>

<MATERIAL>

<MATNO/>

<MATTEXT>

Please help fixing the XPATH

Thanks and Regards,

KLK

Shabarish_Nair
Active Contributor
0 Kudos

<?xml version="1.0" encoding="UTF-8"?>

<ZEU_MATMAS03>

<IDOC BEGIN="">

<EDI_DC40 SEGMENT="">

<TABNAM/>

<MANDT/>

<DOCNUM/>

in your source i guess there is no value in DOCNUM

Only if you have values your XSLT will fill the same into the target. Put some values and test again.

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

Wih regard to your Java Mapping, you need to push the Outputstream.

Use the following code to do that,

arg1.write(source);
arg1.flush();

Regards,

Bhavesh

Former Member
0 Kudos

Shabarish ,

that was just example I do have values in my XML

Even after giving values it is not working

Probably wrong with my mapping

Bhavesh,

I will insert the code and test

but source for second mapping needs to be a XML msg right ? not a string ..

Plese correct me if my understanding wrong !!

kind Regards

KLK

Shabarish_Nair
Active Contributor
0 Kudos

Source:

<?xml version="1.0" encoding="UTF-8"?>

<ZEU_MATMAS03>

<IDOC BEGIN="">

<EDI_DC40 SEGMENT="">

<TABNAM/>

<MANDT/>

<DOCNUM>ETC</DOCNUM>

</EDI_DC40>

</IDOC>

</ZEU_MATMAS03>

XSL:

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">

<xsl:template match="/">

<TEST>

<MATERIAL>TEST</MATERIAL>

<MATNO>

<xsl:value-of select="ZEU_MATMAS03/IDOC/EDI_DC40/DOCNUM"/>

</MATNO>

<MATTEXT>TEST</MATTEXT>

</TEST>

</xsl:template>

</xsl:stylesheet>

Output:

<?xml version="1.0" encoding="UTF-8"?>

<TEST xmlns:fo="http://www.w3.org/1999/XSL/Format">

<MATERIAL>TEST</MATERIAL>

<MATNO>ETC</MATNO>

<MATTEXT>TEST</MATTEXT>

</TEST>

Well, just a trial and it works at my end ...

bhavesh_kantilal
Active Contributor
0 Kudos

KLK,

The string is your Source XML content itself and you can push the String to the OutputStream and the mapping source for the next mapping will be this XML only.

Regards,

Bhavesh

former_member206604
Active Contributor
0 Kudos

Hi,

<i>>>><?xml version="1.0" encoding="UTF-8"?>

<ZEU_MATMAS03>

<IDOC BEGIN="">

<EDI_DC40 SEGMENT="">

<TABNAM/>

<MANDT/>

<b><DOCNUM/></b>

my XSLT program

<?xml version='1.0'?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/">

<MATERIAL>

<MATNO><xsl:value-of select="<b>ZEU_MATMAS03/IDOC/EDI_DC40/DOCNUM</b>"/></MATNO>

<MATTEXT>

When I test the interface mapping I get the following out put :

<?xml version="1.0" encoding="utf-8"?>

<MATERIAL>

<b><MATNO/></b>

<MATTEXT></i>

Check your source document DOCNUM is empty in the source file so obviously you will not have any value in the MATNO. Your XPATH is perfect.

Thanks,

Prakash