Skip to Content
avatar image
Former Member

UDF to Compare values in two Fields

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!!

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

7 Answers

  • Best Answer
    Feb 15, 2017 at 01:16 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Feb 16, 2017 at 04:46 PM

    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]));

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 15, 2017 at 11:58 AM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 15, 2017 at 01:18 PM

    Thank you Karthik.Let me try this please.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 15, 2017 at 05:32 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 16, 2017 at 02:54 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 17, 2017 at 12:53 PM

    Thank you Karthik and Manoj for all your help.

    I am closing this thread.

    Add comment
    10|10000 characters needed characters exceeded