cancel
Showing results for 
Search instead for 
Did you mean: 

Problem with missing input tag

Former Member
0 Kudos

Hi,

When there is no inv2 in the first invoice tag of my input xml, the result breaks down. value of the 2. invoice tag moves up under the first item. Is it possible to correct this without addind an empty inv2 tag to the 1. invoice?

My mapping:

inv1-value -> itm1

inv2-value -> itm2

inv3-value -> itm3

input:

<root>
   <invoice>
      <inv1 value="1"/>
      <inv3 value="2"/>
   </invoice>
   <invoice>
      <inv1 value="3"/>
      <inv2 value="4"/>
      <inv3 value="5"/>
   </invoice>
</root>

output:

<root>
   <item>
      <itm1>1</itm1>
      <itm2>4</itm2>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm3>5</itm3>
   </item>
</root>

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member187339
Active Contributor
0 Kudos

Hi Ali,

Check the output structure in your question (first post).

You are saying you need an output like


<root>
   <item>
      <itm1>1</itm1>
      <itm2>4</itm2>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm3>5</itm3>
   </item>
</root>

But later you are saying you need an output like


<root>
   <item>
      <itm1>1</itm1>
      <itm2></itm2>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2>4</itm2>
      <itm3>5</itm3>
   </item>
</root>

or


<root>
   <item>
      <itm1>1</itm1>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2>4</itm2>
      <itm3>5</itm3>
   </item>
</root>

Which is the actual output that you are expecting!!!!

Also tell is it the problem with only inv2 or you have the same issue with inv1 and inv3

Regards

suraj

Former Member
0 Kudos

I think you have not red the question properly.. because from very begining he expecting only below mentioned result..

Plz go through once agin with original question... (actually just by looking it seems like that... so what you observed is correct but not true)

<root>
   <item>
      <itm1>1</itm1>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2>4</itm2>
      <itm3>5</itm3>
   </item>
</root>

Former Member
0 Kudos

In the first post it is the output I get, but I don't want that output.

What I want is:

<root>
   <item>
      <itm1>1</itm1>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2>4</itm2>
      <itm3>5</itm3>
   </item>
</root>

In my example the problem is with inv2. But if you omit inv1, then you get the same problem with that also (the same with inv3).

former_member187339
Active Contributor
0 Kudos

Hi Ali,

ok.

Now give me on how you have mapped the target root, item and iitem1, itm2, and itm3 nodes

Then i will suggest the mapping change which you need

Regards

Suraj

Former Member
0 Kudos

My mapping:

invoice -> item

value(inv1) -> itm1

value(inv2) -> itm2

value(inv3) -> itm3

there is no mapping at the root node.

former_member187339
Active Contributor
0 Kudos

Hi Ali,

Map like this:

invoice -> item

value(inv1) ->MapwithDefault-> itm1

value(inv2) -> MapwithDefault->itm2

value(inv3) -> MapwithDefault->itm3

Also please check what MapwithDefault does here http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm


Replaces empty contexts in the inbound queue with a default value, which you specify in the function properties.

Example:
If u201CDefaultu201D is the default value and
A|B1,B2| |C| |D
is the inbound queue,
mapWithDefault returns the following outbound queue:
A | B1,B2 | Default | C | Default |D.

So map with default shoudl work for you, now if that doesn't work, provide the input field which you are passing and the output that you are getting. No need to set any property for mapwithdeafult

regards

Suraj

Former Member
0 Kudos

I have already tried that before. But it didn't work. The <itm2> in the second <item> is empty, it should have the value "4".

What I got with the mapping you suggested:

<root>
   <item>
      <itm1>1</itm1>
      <itm2/>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2/>
      <itm3>5</itm3>
   </item>
</root>

Former Member
0 Kudos

Save and activate your mapping and then try. Becaue it is very simple logic and it should work with MapWithDefault function.

Could be some temp cache issue.. try closing and then opening mapping again.

former_member187339
Active Contributor
0 Kudos

Hi Ali,

Try this once

invoice -> item

value(inv1) ->MapwithDefault->splitbyvalue(each value)->itm1

value(inv2) -> MapwithDefault->splitbyvalue(each value)->itm2

value(inv3) -> MapwithDefault->splitbyvalue(each value)->itm3

Right Click the Mapwithdefault function in the mapping of itm2 and see the display queue. Also make sure the context of inv2 is set to its parent item.

Can you paste here the input and output values which you see in the display queue of mapwithDefault (for output node itm2)

Regards

Suraj

Former Member
0 Kudos

display queue of mapwithDefault (for output node itm2):

mapWithDefault:in0     mapWithDefault:out     bgcolor
SUPPRESS               SUPPRESS                  
[4]                    [4]                    light gray
[4]                    [4]                    dark gray

former_member187339
Active Contributor
0 Kudos

Hi Ali,

Try this:


invoice -> item
value(inv1) ->exists-->if then value (inv1) -->itm1
                                        else Constant("") 
value(inv1) ->exists-->if then value (inv2) -->itm2
                                        else Constant("") 
value(inv1) ->exists-->if then value (inv3) -->itm3
                                        else Constant("") 

Hope this time it shoudl work

Regards

Suraj

Former Member
0 Kudos

Thank you for your replies. I think it is not possible without the complete structure. All elements should exist in the input even if they are empty.

Former Member
0 Kudos

It is possible... I created the same situation in my system and it is working fine without any conditions. I used simple 1:1 mapping.

And all values are coming in correct places. Something wrong with your system I guess.

Former Member
0 Kudos

I think if you just do the direct assaignment between Invoice and Item

as


Invoice----->Item

and for the value(Inv1) to Itm1 and respectively for other Inv2 and Inv3 to Itm2 and Itm 3.then you will get the required output.

If you tell the exact mapping requirement then we will help you further.

Former Member
0 Kudos

>

> I think if you just do the direct assaignment between Invoice and Item

> as

>


> Invoice----->Item
> 

> and for the value(Inv1) to Itm1 and respectively for other Inv2 and Inv3 to Itm2 and Itm 3.then you will get the required output.

> If you tell the exact mapping requirement then we will help you further.

I have already made that mapping. In my input XML some elements may sometimes not exist. In this circumstances that values are shifted from below values. Please check it from the first post.

Former Member
0 Kudos

Add a condition using if else and if inv2 exists then inv2 --> item else default to inv2

Need to check the context if it is used at child levels

HTH

Rajesh

Former Member
0 Kudos

>

> Add a condition using if else and if inv2 exists then inv2 --> item else default to inv2

>

> Need to check the context if it is used at child levels

>

> HTH

> Rajesh

<itm2> in the second <item> is still missing.

new output:

<root>
   <item>
      <itm1>1</itm1>
      <itm2/>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm3>5</itm3>
   </item>
</root>

Edited by: Ali Varli on Oct 6, 2009 12:15 PM

Former Member
0 Kudos

You need to maintain the queues properly for that you have to either fill all the fields or use MapWithDefault function. I can imagin that when you use splitByValue function then your data get shifted above if any of the field does not exist.

Regards,

Sarvesh

Former Member
0 Kudos

Yes, it gets shifted up. MapWithDefault and splitByValue doesn't help. I think I have to fill all the fields.

Former Member
0 Kudos

MapWithDefault should help you.

I think MapWithDefault should give the output even if field does not exist, if not then add a condition that if field doesn't exist then Map with some constant so that your queue should be maintained.

Regards,

Sarvesh

Former Member
0 Kudos

>

> MapWithDefault should help you.

>

> I think MapWithDefault should give the output even if field does not exist, if not then add a condition that if field doesn't exist then Map with some constant so that your queue should be maintained.

>

> Regards,

> Sarvesh

Yes MapWithDefault gives the output even if field does not exist, but as stated in my example <itm2> in the 2. <item> gets no value as it should get "4".

Former Member
0 Kudos

Can you tell us your mapping steps. It look weird that MapWithDefault is not helping.

Based on your current example should get 3 values (along with one default value which you set in MapWithDefault function) in first and then context change and then next 3 values.

Former Member
0 Kudos

My mapping:

invoice -> item

value(inv1) -> itm1

value(inv2) -> mapWithDefault("") -> itm2

value(inv3) -> itm3

what I get:

<root>
   <item>
      <itm1>1</itm1>
      <itm2/>
      <itm3>2</itm3>
   </item>
   <item>
      <itm1>3</itm1>
      <itm2/>
      <itm3>5</itm3>
   </item>
</root>

my request:

<root>
   <invoice>
      <inv1 value="1"/>
      <inv3 value="2"/>
   </invoice>
   <invoice>
      <inv1 value="3"/>
      <inv2 value="4"/>
      <inv3 value="5"/>
   </invoice>
</root>

or

<root>
   <invoice>
      <inv1 value="1"/>
      <itm2/>
      <inv3 value="2"/>
   </invoice>
   <invoice>
      <inv1 value="3"/>
      <inv2 value="4"/>
      <inv3 value="5"/>
   </invoice>
</root>

Former Member
0 Kudos

What is the default value in your MapWithDefault function. If you have not given anything then double click on it and give empty value by pressing spacebar once.

Former Member
0 Kudos

Tried giving space, but no success. <itm2> is still epmty.