cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to compare values of different contexts

Former Member
0 Kudos

Hi All,


I am looking for UDF to perform the following logic, please help me

I will have 3 inputs, say field1, fields2, field3. If field1 = field2 then return field3.

You may say that this can be implemented by message mapping with IF condition itself. But here field1 & field2 are from different segments.Field1 & field3 are from same segment.

When i use message mapping because of this context problems, i am able to get this validation for the first set only.

If i have the multiple values means, i am not able to get it.

all these field1, field2 & field3 are multiple .

All the fields have different occurrences.

Thanks,

--Ramya

Accepted Solutions (1)

Accepted Solutions (1)

rcsegovia
Active Participant
0 Kudos

Hi Ramya,

If you don't have java knowledge you try to do it playing with contexts! Also provide us some source and to be examples to help you.

Regards,

Roberto.

Former Member
0 Kudos

Hi Roberto,

Please find the below screenshot of my requirement.

I am taking the first PERNR value of one segment and comparing it with second segment.If both are equal then Error message must be sent to target and it should be in the context of first PERNR.

Tried the below logic but it doesn't work.

Thanks,

Ramya

rcsegovia
Active Participant
0 Kudos

Hi Ramya,

Please let me know your expected output queue...

regards,

Roberto.

Former Member
0 Kudos

Hi Roberto,

It should compare 44444444,44444441 with all the values and if equal should return errormessage .

Thanks,

Ramya

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Ramya,

I have written UDF code for the requirement. Please find below the code and also my sample test result for better understanding:

Sample mapping:

UDF Code:

int flag;

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

{

      flag=0;

      for(int j=0;j<Pernr2.length;j++)

      {

           if(Pernr1[i].equals(Pernr2[j]))

           {

             result.addValue("Value Found");

             flag=1;

             break;

           }

      }

      if(flag==0)

            result.addValue("Value Not Found");

}

Can you try and let me know if you still face any issues.

Reward points if you found my reply helpful.

Regards

Vishnu

Former Member
0 Kudos

Hi Vishnu ,

My requirement is If PERNR1 values equal to PERNR2 then the corresponding Error message details must be sent to target.Here ErrorMessage is also an array coming in the input.

I already tried with the above udf.But I am facing error while sending it to the target.

Let me explain with an example.

This is a soap to RFC scenario.In soap Request the PERNR details will be sent .

My Input RFC response structure is

CData(0,1)---contact details

     Item(0,unbounded)

          PERNR

          Address

          City

          Residential Country

Edata(0,1)---error details

     Item(0,unbounded)

          PERNR

         Error message

Fdata(0,1)---family data

     Item(0,unbounded)

          PERNR

          Familytype

          FamilyDetailsetc

Pdata(0,1)--personal data)

     Item(0,unbounded)

     PERNR

     TITLE

     Designation...

Should convert the above structure to

Record

PERNR

Cdata

Fdata

Pdata( All the data of one particular PERNR should come under one record and Edata comes if the PERNR details are not availabe in ECC.when ever Edata comes for one particular PERNR the other data will not exist)

1.Cdata ,Fdata,Pdata are optional for one particular PERNR

2.To populate the Error data first i should check if PERNR of edata equals to PERNR of Pdata if equals should populate that particular error message in the corresponding PERNR record.

Regards,

--Ramya

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Ramya,

Yes, you can give the error array string to the UDF and in the code, when both pernr's gets equal, add that particular error message to the result object. Also, pass the required value to the output for the case when both are not equal.

Can you try this and let me know the error message which you are getting.

Regards

Vishnu

rcsegovia
Active Participant
0 Kudos

Hi,

I guess your problem is handling string with different items number, I mean you need mapwithdefault all nodes involves into an IF to do comparison right. Otherwise you will have problems with contexts amd missing values when data come after some missing nodes.

Check it to understand contexts

and try to use useoneasmany or formarbyexample to rebuild your contexts.

good luck,

Roberto.

Former Member
0 Kudos

Hi Vishnu,

I am using the following udf.But not getting the expected output.

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

{

      for(int j=0;j<PdataPERNR.length;j++)

      {

           if(EdataPERNR[i].equals(PdataPERNR[j]))

           {

             result.addValue(ErrorMsg[i]);

            

           }else  result.addValue(" ");

      }
}

Please have a look at the below screen shot.But the expect output is three blanks notfound,notfound 1

Thanks,

Ramya

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Ramya,

int flag;

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

{

      flag=0;

      for(int j=0;j<PdataPERNR.length;j++)

      {

           if(EdataPERNR[i].equals(PdataPERNR[j]))

           {

             result.addValue(ErrorMsg[i]);

             flag=1;

             break;

           

           }

      }

      if(flag==0)

         result.addValue(" ");

}

Can you check with the above code. I have just did some corrections to your code. Kindly check this and let me know the outcome.

Also, just make sure whether you need give EdataPERNR as the input, PdataPERNR as the second input or vice-versa...

Regards

Vishnu

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

I modified your UDF a bit. Here's the code


int b=0;

for(int a=0;a<EdataPERNR.length;a++){

  for(;b<PdataPERNR.length;b++){

       if(EdataPERNR[a].equals(PdataPERNR[b])){

            result.addValue(ErrorMsg[a]);

            break;

       }

       else{

            result.addValue(" ");

       }

  }

  b++;

}

and here is the input/output:

Regards,

Mark

Message was edited by: Mark Dihiansan

Former Member
0 Kudos

Hi Vishnu,

Already tried with the above code.but the desired output is three blanks,notfound,noutfound1

Thanks,

Ramya

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Ramya,

Give PdataPERNR as the first input & EdataPERNR as the second input, and the third input remains same.

Try this code:

int flag;

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

{

      flag=0;

      for(int j=0;j<EdataPERNR.length;j++)

      {

           if(EdataPERNR[i].equals(PdataPERNR[j]))

           {

             result.addValue(ErrorMsg[j]);

             flag=1;

             break;

          

           }

      }

      if(flag==0)

         result.addValue(" ");

}

Regards

Vishnu

Answers (2)

Answers (2)

RaghuVamseedhar
Active Contributor
0 Kudos

Ramya,

Please check this UDF


// Grouping XML records. 

public void udf_getCorrespondingRecord(String[] Name_People, String[] Name_Record, String[] Where, String[] Phone, ResultList Record_out, ResultList Where_out, ResultList Phone_out, Container container) throws StreamTransformationException{ 

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

     for(int j = 0; j < Name_Record.length; j ++) { 

         if(Name_People[ i ].equals(Name_Record[ j ])) { 

             Record_out.addValue(" "); 

             Where_out.addValue(Where[ j ]);             Phone_out.addValue(Phone[ j ]); 

             Where_out.addValue(ResultList.CC);    Phone_out.addValue(ResultList.CC); 

         } 

     } 

     Record_out.addValue(ResultList.CC); 

}

pvishnuvardan_reddy
Active Contributor
0 Kudos

Hi Ramya,

We can achieve this using graphical functions itself.

Can you share us the screen shots to help you further.

Regards

Vishnu