cancel
Showing results for 
Search instead for 
Did you mean: 

Message Mapping - Creating the same node sequences in Target as Source

0 Kudos

Hi,

Source Structure -

HEADER (0 to unbound)

DETAIL (0 to unbound)

Target Structure -

HEADER(0 to unbound)

DETAIL(0 to unbound)

Let's say source file has following nodes

HEADER

DETAIL

DETAIL

HEADER

HEADER

DETAIL

DETAIL

The target nodes should be as below (Same sequence as the source)

HEADER

DETAIL

DETAIL

HEADER

HEADER

DETAIL

DETAIL

Is this possible to do in message mapping ?

Thanks,

Sway

Accepted Solutions (1)

Accepted Solutions (1)

Muniyappan
Active Contributor
0 Kudos

Hi,

if you want output same as input you can follow hari's reply.

if you are looking to achieve this in message mapping follow below link

http://scn.sap.com/community/pi-and-soa-middleware/blog/2013/03/13/write-java-mapping-directly-in-es...

write a code like below in the function tab of message mapping and do not map anything in the editor.

public  void  transform(TransformationInput in, TransformationOutput out) throws StreamTransformationException {

    try {

                            

                              String targetxml ="";

                              String line ="";

                              StringBuffer sb = new StringBuffer();

                    InputStream ins = in.getInputPayload().getInputStream();

                    BufferedReader br = new BufferedReader( new InputStreamReader(ins));

                    while ((line = br.readLine()) != null)  

                              {

                              sb.append(line);

                              }

                              br.close();

                              targetxml = sb.toString();

                    out.getOutputPayload().getOutputStream().write(targetxml.getBytes());

  }

    catch (Exception e) {

           throw new StreamTransformationException(e.getMessage());

  }

}

function Tab

Test results

Regards,

Muniyappan.

Answers (5)

Answers (5)

0 Kudos

Using Java mapping helped me here. I don't think we can keep the same order in target as the source with Message Mapping. Thanks for all the suggestions.

Former Member
0 Kudos

Hello,

Check this (in fact this is what Mark was referring to):

http://scn.sap.com/community/pi-and-soa-middleware/blog/2010/01/14/file-conversion-using-nodeception

Thanks

Amit Srivastava

markangelo_dihiansan
Active Contributor
0 Kudos

Thanks Amit!

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

There was a blog here is SDN that is similar to yours. What he did was this:

1. Create a data type (imported in message type) that has this structure

<Root>

   <row>

     <HEADER> (0..n)

     <DETAIL> (0..n)

2. Once the mapping is done and the output is correct e.g

<Root>

   <row>

      <HEADER>

      <DETAIL>

      <DETAIL>

   <row>

      <HEADER>

   <row>

      <HEADER>

      <DETAIL>

      <DETAIL>

3. He removed the row using Java/XSLT

Hope this helps,

Mark

ambrish_mishra
Active Contributor
0 Kudos

Hi,

Do a direct mapping... in case you need to apply transformation rules in the data fields.

Ex Map header to header and so on....

Otherwise what Hari says will work.

Ambrish

former_member190624
Active Contributor
0 Kudos

Hi Sway,

If you want same input as output . Don't use any mapping in your scenario, problem solved

Regards

Hari.

0 Kudos

Hi Hari,

The output node has few more fields.

Right now, The output is as below (If I am doing an one-to-one mapping)

HEADER

HEADER

HEADER

DETAIL

DETAIL

DETAIL

DETAIL

Thanks,

Sway

ambrish_mishra
Active Contributor
0 Kudos

Hi Sway,

This means your input data\format is like below

HEADER

HEADER

HEADER

DETAIL

DETAIL

DETAIL

DETAIL

and not like

HEADER

DETAIL

DETAIL

HEADER

HEADER

DETAIL

DETAIL

In this case you need to sort this in mapping. Can you share a snapshot of the data received with key fields...

Ambrish