Skip to Content
0

UDF to Compare values in two Fields

Feb 15, 2017 at 11:54 AM

118

avatar image

Hi All

In one of the scenario IDOC to File I have created Message mapping.

The requirement is to check if fieldA value present any where in fieldB then output should be True.Else False

Field A Feild B Output

a c false
----------------------------------------------------
b a true
----------------------------------------------------
e e true
-------------------------------------------- -------
a b true

-----------------------------------------------------

e true

I tried with standard functions but could not able to get the desired output.

So I request your help!!

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

7 Answers

Best Answer
Karthik Bangera Feb 15, 2017 at 01:16 PM
0

Hi Anitha,

Check if the below code helps-

public void CompareVals(String[] FieldA, String[] FieldB, ResultList result, Container container) throws StreamTransformationException{ List<String> LFieldA = Arrays.asList(FieldA);

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

result.addValue(LFieldA.contains(FieldB[i]));}

}

Regards,

Karthik

Share
10 |10000 characters needed characters left characters exceeded
Manoj K Feb 16, 2017 at 04:46 PM
1

its just a other way around to compare values in the UDF mentioned by karthik.

List<String> LFieldB = Arrays.asList(FieldB); 
for(int i=0; i<FieldA.length; i++) 
result.addValue(LFieldB.contains(FieldA[i]));


compare.png (4.6 kB)
Share
10 |10000 characters needed characters left characters exceeded
Anitha Gajula Feb 15, 2017 at 11:58 AM
0

Table is not clear in Question so pasted here.Please check this one


c2yku.png (3.6 kB)
Share
10 |10000 characters needed characters left characters exceeded
Anitha Gajula Feb 15, 2017 at 01:18 PM
0

Thank you Karthik.Let me try this please.

Share
10 |10000 characters needed characters left characters exceeded
Anitha Gajula Feb 15, 2017 at 05:32 PM
0

Thank you so much Karthik its working fine I will test few more cases and confirm you the result.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Good to know :)

Regards,

Karthik

0
AMSFUNCTIONAL AMSFUNCTIONAL Feb 16, 2017 at 02:54 PM
0

Hi Karthik

when I change the values and see the output it is not expected.Please correct me if wrong.

This should come as False,False,true,true,true

Regards

Anitha


zwj2h.png (7.9 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Anitha,

Well my logic was as per your earlier sample table below :) but the above screenshot gives an opposite picture. Manoj has corrected it anyway :) Hope all is well now.

Regards,

Karthik

20671-c2yku.png (3.6 kB)
0
Anitha Gajula Feb 17, 2017 at 12:53 PM
0

Thank you Karthik and Manoj for all your help.

I am closing this thread.

Share
10 |10000 characters needed characters left characters exceeded