cancel
Showing results for 
Search instead for 
Did you mean: 

JavaMapping Multipel Nodes

Former Member
0 Kudos

Hi.

I've done a mapping with a java-function and when I get mutipel elements I only get the first node with elements and for the sacond element I get just the node wirth no elements in the target.

Ocurrences in source element are 0-unbounded

Target node are 0-unbounded and the elements in the target node are 0-1.

In the source element I get a textstring where the attributes and the with belonging data are splitted up by a space.

public void serachstring (String[] a,String[] b,String[] c,ResultList result,Container container){
int     start_ind = 0, 
        end_ind = 0, 
        string_length = 0; 
        String item_string = ""; 
try { 
     start_ind  = a[0].indexOf(b[0]); 
if (start_ind<0) { 
        item_string = "No Value Present"; 
        result.addValue(item_string); 
        return; 
        } 
} 
catch (StringIndexOutOfBoundsException ex){ 
} 
        string_length = b[0].length(); 
        start_ind = start_ind + string_length; 
try { 
        end_ind = a[0].indexOf(c[0],start_ind); 
} 
catch (StringIndexOutOfBoundsException ex){ 
} 
try { 
        item_string = a[0].substring((start_ind), (end_ind)) + ""; 
} 
catch (StringIndexOutOfBoundsException ex){ 
} 

result.addValue(item_string); 
}

The function should split the string in the element like this.

sourceelement = <1="abc" 2="def" 3="ghi">

Target should look like this.

Node

element1 = abc

element2 = def

element3 = ghi

If I only get one elemt it works but if I get 2 elements I get the following result.

sourceelement = <1="abc" 2="def" 3="ghi">

sourceelement = <1="jkl" 2="mno" 3="pqr">

target

Node

element1 = abc

element2 = def

element3 = ghi

Node

So I get the first node with elements and the second node without elements.

Does anybody know why?

Edit:

The mapping looks as follow.

source: Function: Target:

element No Node

element Yes element

element Yes element

element Yes element

In the mappings between the element the function gets called. I'm calling it with a=the whole string, b=the attributename matching the target element, c=".

BR

Kalle

Edited by: Kalle Persson on Feb 22, 2008 5:08 PM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello,

could be a context problem.

Try the standard function 'split-by-value' after your sourceelement.

Regards

Patrick

Former Member
0 Kudos

I f that was the problem should I get the the result I get with one element then?

Feels like the function doesn't get called for the second element.

justin_santhanam
Active Contributor
0 Kudos

Kalle,

Can u confirm whether u r looking for the below expected output.

Source

<MT_Input>

<Records>

<Sourceelement attrib1="21" attrib2="34" attrib3="09">Test</Sourceelement>

</Records>

<Records>

<Sourceelement attrib1="abc" attrib2="def" attrib3="ghi">Test</Sourceelement>

</Records>

<Records>

<Sourceelement attrib1="ABC" attrib2="DEF" attrib3="GHI">Test</Sourceelement>

</Records>

</MT_Input>

Target

<MT_Output>

<Node>

<Element1>21</Element1>

<Element2>34</Element1>

<Element3>09</Element1>

</Node>

<Node>

<Element1>abc</Element1>

<Element2>def</Element1>

<Element3>ghi</Element1>

</Node>

<Node>

<Element1>ABC</Element1>

<Element2>DEF</Element1>

<Element3>GHI</Element1>

</Node>

</MT_Output>

If you are ok with the above results, could you tell us what is the Source element 3 Atrtibutes occurrences, is it optional or required

raj.

Former Member
0 Kudos

Hello,

please just try it with 'splitByValue'.

I guess your sourcefield is mapped two times to 'Node' (like you want it), but

without 'splitByValue' your complete source input goes in the first function call and there is no input for the second call (that's why the function isn't called a second time).

Regards

Patrick

Former Member
0 Kudos

Hi Raj.

All the attributes that will be mapped to an element in the target are 0-1.

Your example are exactly what I would like to get. The source element can be 1-unbounded.

Former Member
0 Kudos

Hi Patrick.

Should I have the SplitByValue in the mapping

sourceelement - targetnode?

Former Member
0 Kudos

Hello,

no between source element and target element.

Something like this:

source element -> target node

source element -> splitByValue -> yourFunction -> target element

Regards

Patrick

Former Member
0 Kudos

I will try it when I get to the system.

Hope it works...

Thanks Patrick

justin_santhanam
Active Contributor
0 Kudos
Former Member
0 Kudos

Something like it but the attributes comes in one element and not three like in your example. All the data comes in one string.

justin_santhanam
Active Contributor
0 Kudos

Kalle,

You mean you will attributes like,

<Sourceelement attribute="123 098 789">

<Sourceelement attribute="abc def ghi">

<Sourceelement attribute="jkl mno pqr">

with each attributes separated with spaces is it? Always there will three atrributes?

raj.

Former Member
0 Kudos

There will be a max number of attributes but all of them will not always be present in the string. That's why I have the test with No Present Value. There will only be one string in each element but the element can appear upto unbounded.

To se an example of an string look at message number one.

Former Member
0 Kudos

Hi Patrick

The SpliByValue function didn't work.

The queue into my function looks perfect. if I have 2 elements there are 2 elements comming in. Could the problem be that I put everything in a resultList? If that's the problem how can i solve it?

Former Member
0 Kudos

Hello,

you have 2 elements in your queue, but are they splitted by a context?

That's why you need 'splitByValue' and what makes the difference.

Regards

Patrick

Former Member
0 Kudos

But I tried the splitByValue. Didn't work. How can I see if I have contextchange in my elements?

Former Member
0 Kudos

Hi,

in the (result) column of the function will be a grey row between the elements.

For example:

input:

firstValue

secondValue

output:

firstValue

grey Row (firstValue)

secondValue

Regards

Patrick

Former Member
0 Kudos

How do i add a picture to this forum. I can show you how my test looks in SAP...

Former Member
0 Kudos

My source looks like

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

<ns0:MsgT_Incoming_file xmlns:ns0="http***">
   <Line>
      <SegmentA>TEST</SegmentA>
      <SegmentB>080221</SegmentB>
      <SegmentC>&lt;Sequence=&quot;1&quot; Time=&quot;2006-09-12 12:12:00&quot; Id=&quot;v012345&quot; Role=&quot;Manager&quot; Status=&quot; Rejected&quot; Comment=&quot;YES&quot;/&gt;</SegmentC>
      <SegmentC>&lt;Sequence=&quot;2&quot; Time=&quot;2006-09-12 12:12:01&quot; Id=&quot;v123456&quot; Role=&quot;Java Developer&quot; Status=&quot;Active&quot; Comment=&quot;YES&quot;/&gt;</SegmentC>
   </Line>
</ns0:MsgT_Incoming_file>

And my target becomes like this.

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MsgT_Outgoing_xml xmlns:ns0="http***">
   <LineA>
     <SegementA>TEST</SegementA>
   </LineA>
   <LineB>
     <SegementB>2008/02/25</SegementB>
   </LineB>
   <LineC>
     <Sequence>1</Sequence>
     <Time>2006-09-12 12:12:00</Time>
     <Id>v012345</Id>
     <Role>Manager</Role>
     <Status> Rejected</Status>
     <Comment>YES</Comment>
   </LineC>
</ns0:MsgT_Outgoing_xml>

Edited by: Kalle Persson on Feb 25, 2008 10:25 AM

Former Member
0 Kudos

Hello,

your result is what you want, but you are missing the second SegmentC?

Could you please give one detailed description of your mapping.

Regards

Patrick

Former Member
0 Kudos

Hi Patrick.

Between the element containing the string I have the following mapping.

SourceElement -> SplitByValue(Each Value) -> TargetNode

SourceElement, Constant(with the startstring to search for), Constant (with the endstring to search for) -> MyUserFunction -> TragetElement

(SE, C, C are inputs for my function.)

If I have 2 SourceElements then where the strings to search for are the numbers 1 and 2 the queue at my function looks as this.

Input 0 Input 1      Input 2   Output
String1 Constant    Constant      1
String2                           1
String2

How come that I just get the value in the first string?

The Strings are there for the input but not the constants. why?

I hope this is what you was asking for to get a better picture.

Former Member
0 Kudos

Hi,

you say it's like this:

> SourceElement -> SplitByValue(Each Value) -> TargetNode

But it should be like this:

SourceElement -> SplitByValue(Each Value) -> MyUserFunction

Constant1 -> MyUserFunction

Constant2 -> MyUserFunction

MyUserFunction -> TargetNode

Is it like this?

Regards

Patrick

Former Member
0 Kudos

Are you sure about TargetNode?

I want the splitted string in the elements in the TargeNode...

Also I need to Ad so many constants then as inputs for the function.

Is it possibly to do it in some way that I described?

If I do it like you configure it don't I need to use global variables then?

Edited by: Kalle Persson on Feb 26, 2008 9:51 AM

Former Member
0 Kudos

Sorry -> targetElement !

BUT you need in both cases a splitByValue:

Here:

SourceElement -> SplitByValue(Each Value) -> TargetNode

And here:

SourceElement -> SplitByValue(Each Value) -> MyUserFunction

Constant1 -> MyUserFunction

Constant2 -> MyUserFunction

MyUserFunction -> TargetElement

Regards

Patrick

Former Member
0 Kudos

Mapped it just as you describes it now and getting the same result.

Just checked the queue.

The values are there but the node does not duplicate...

Edited by: Kalle Persson on Feb 26, 2008 10:04 AM

Former Member
0 Kudos

Hello,

guess i was wrong in one point!

please try the splitByValue ONLY before your function

NOT here:

SourceElement -> SplitByValue(Each Value) -> TargetNode

ONLY here:

SourceElement -> SplitByValue(Each Value) -> MyUserFunction

Constant1 -> MyUserFunction

Constant2 -> MyUserFunction

MyUserFunction -> TargetElement

Regards

Patrick

Former Member
0 Kudos

Just tried it. Worked perfect.

I think I tried this before but then my function was a queuedfunction and todasy I changed it to a contextfunction. Is that why it worked today and not before?

What's the differens between context and queued functions?

Thanks for all the help Patrick. You have som points coming...

Former Member
0 Kudos

Hello,

> Just tried it. Worked perfect.

Happy to hear that

> What's the differens between context and queued functions?

It's explained here:

http://help.sap.com/saphelp_nw04/helpdata/en/f8/2857cbc374da48993c8eb7d3c8c87a/frameset.htm

> Thanks for all the help Patrick. You have som points coming...

Thank you and regards

Patrick

Answers (0)