cancel
Showing results for 
Search instead for 
Did you mean: 

Concat values from two diffreent nodes.

Former Member
0 Kudos

Hi,

I'm getting SUPRESS; When i want to concat values from diffrent nodes.

example:

Node1: <11> <> <12> <> <> <13> <> <> <> <>

Node2: <21>  <22> <23> <24> <25> <26> <27> <28> <29> <24>

should be Result: <1121> <1122><1223><1224><1225><1326><1327><1328><1329><1324>

<>   is no value or no node occures.

help is appriciated.

thanks.

Prema Boodi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Prema

You can write a UDF to do this.

Take two inputs A and B for Node1 and Node2

String s1=A[0]

for (int i=0;i<A.length();i++)

{ if (A[i]=="")

{ res=s1.concat(B[i];

else

{ res=A[i].concat(B[i]);

s1=A[i];

}

}

Former Member
0 Kudos

Thanks Sourab. Will try this.

former_member184681
Active Contributor
0 Kudos

Hi Sourabh Nirmal,

Let me make few small corrections to your code, as I'm afraid it won't work as required. First of all, string comparisons in Java usually do not work well when formulated like this: if (A[i]==""). Use equals() function instead. Moreover, I think I made the code more understandable. And finally, the important thing was to add result.addValue() statement.

String s1=A[0];
for (int i=0;i<A.length();i++)
{
  if (!(A[i].equals(""))) s1 = A[i];
  res = s1.concat(B[i];
  result.addValue(res);
}

Prema Boodi, make sure your UDF's execution type is all values of queue, otherwise it might give surprising results.

Regards,
Greg

Former Member
0 Kudos

thank you both; but why do i get this error:

cannot find symbol
symbol : method length
()

baskar_gopalakrishnan2
Active Contributor
0 Kudos

length is not a method. Use just length no paranthesis

Note: When you reference string array length, it will be just length.

Former Member
0 Kudos

thanks Baskar; i got that resolved.

and what is this error now?

·         incompatible types
found   : java.lang.String
required: com.sap.aii.mappingtool.tf7.rt.ResultList
res = s1.concat(B[i]);

former_member184681
Active Contributor
0 Kudos

Hi Prema,

Replace this code:

res = s1.concat(B[i];
result.addValue(res);

With this:

res.addValue(s1.concat(B[i]);

Hope this helps,
Greg

baskar_gopalakrishnan2
Active Contributor
0 Kudos

The error shows that res should be ResultList instance but you save it in a string object.
What is res? Is it declared as String. I dont see the declaration here.  Please contact the author of this code to decide. I don't want to modify or change the previous experts code.

Former Member
0 Kudos

Hi Prema,

Delete the statement res = s1.concat(B[i]);

and add the statement result.addValue(s1.concat(B[i]));

let me know the result.

Former Member
0 Kudos

thanks all.

this code now doesnt have any error; but doesnt give me the desired results:

String s1=A[0];

for (int i=0;i<A.length();i++)

{

  if (!(A[i].equals(""))) s1 = A[i];

res.addValue(s1.concat(B[i]);

}

res is type ResultList

Former Member
0 Kudos
  1. Nod1àsubnode1->field
  2. Nod1àsubnode2->field

Now I want to concat theses two fields from different subnodes, assuming subnode1 occurs only some times.. But it has to carry the previous values until it hits the next value.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Don't see else block? currently you write logic only node 1 has values for concat operation.

Former Member
0 Kudos

Hi,

Try with the below code...

for (int i=0;i<A.length();i++)

{

String s1="";

if (!(A[i].equals("")))
s1 = A[i];

res.addValue(s1.concat(B[i]);

}

also please provide the screenshot of total mapping...jus wanted to know what is the standard function u have used after UDF...

Former Member
0 Kudos

can u please be more specific on this...

field in subnode1 occurs only sometimes or subnode1 itself will occur sometimes..?

if subnode1 occurs only sometimes: u can't concatinate untill and unless u have an unique identifier between subnode1 and subnode2.

if field in subnode1 occurs only sometimes: use the below code in the udf. it will work.

String s1="";

String s2="";

for (int i=0;i<B.length;i++)

{

    if (!(A[i].equals("")))

    {

     s1 = A[i];

     s2 = s1.concat(B[i]);

     result.addValue(s2);

    }else{

          s2 = s1.concat(B[i]);

          result.addValue(s2);

         }

}

hope this clarifies.

Former Member
0 Kudos

hi,

how do I attach images? i did paste the screenshot to paint. but its not allowing me to upload it.

Former Member
0 Kudos

its giving some weired char when there is no occuarnce of first nodes values:

like this [__cC__cC_] in the ouput.

former_member184681
Active Contributor
0 Kudos

Hi Prema Boodi,

I guess there is no need for that. Only now did I realize that you do not have an EMPTY value when Node1 is missing, but you have SUPRESS instead (according to your initial post). So a slight change to the UDF should get the job done finally:

String s1 = "";
for (int i=0;i<A.length();i++) {
  if (!(A[i].equalsIgnoreCase(ResultList.SUPRESS)))
    s1 = A[i];
  res.addValue(s1.concat(B[i]);
}

There is no need for further complications, ELSE conditions and so on. The only change is to compare the currently checked value with SUPRESS, not an empty string

Hope this helps,
Greg

Former Member
0 Kudos

i am also facing the same issue...

use the udf code that i have pasted 10 min back...

String s1="";

String s2="";

for (int i=0;i<B.length;i++)

{

    if (!(A[i].equals("")))

    {

     s1 = A[i];

     s2 = s1.concat(B[i]);

     result.addValue(s2);

    }else{

          s2 = s1.concat(B[i]);

          result.addValue(s2);

         }

}

input values to the udf:

input1: field in subnode1->mapwithdefault->removecontexts

input2: field in subnode2->removecontexts

output value of the udf should be mapped to splitbyvalue(each value) function and then to the target field.

baskar_gopalakrishnan2
Active Contributor
0 Kudos

Just Few cents.,,

IMO, we need else block to concat the value of previous node A's value to the node b current value (in the event if A has no value or suppressed )

s2 = s1.concat(B[i]);

Former Member
0 Kudos

the below code worked like a charm; thanks so much everyone.

String s1="";
for (int i=0;i<A.length;i++)
{
if (!(A[i].equals("")))
s1 = A[i];
res.addValue(s1.concat(B[i]));
}

with Veerendra's logic:

input1: field in subnode1->mapwithdefault->removecontexts

input2: field in subnode2->removecontexts

output value of the udf should be mapped to splitbyvalue(each value) function and then to the target field.

former_member184681
Active Contributor
0 Kudos

Dear Baskar,

I believe else block is not necessary here. See that the only thing we do conditionally is we set the value of the temporary variable s1 (only under the condition that the value exists). Later, we always concatenate the current value of s1 with the second argument - either s1 is equal to current Node1 value, or any existing previous one (last value that did exist).

So I believe the only thing my code was missing is the information from the initial post - that "empty" is not "" (empty string), but SUPRESS.

Hope you got that clear now,
Greg

Former Member
0 Kudos

cross check the code

String s1="";
for (int i=0;i<A.length;i++)
{
if (!(A[i].equals("")))
s1 = A[i];
res.addValue(s1.concat(B[i]));
}

i hope it will not work it will not work for the muiltiple values. Do thorough testing(Ex: Field1: 1, field1:no value, field1: 2 and field2:3, field2:4, field2: 5... your output should be 13,14,25).. cross check...

Answers (0)