cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping Issue, remove a field from source payload

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Experts,

Currently in production we have an interface which is failing in mapping daily, because one field is coming as Alphanumeric and that field is used in subtraction/Addition functionality in many fields in the mapping.

Mapping is quite complex and the clients are not ready to make changes in the current mapping.

So, as a workaround we decided to add another mapping(Graphical/XSLT/Java) before our current mapping(in Operational Mapping).

Mapping needs to handle

** To check that field(LtNumber) if it is alphanumeric say(W708088), then we need to delete the LtNumber field from the source payload and pass the entire payload as it is to our second mapping(current mapping).

Please suggest how I can handle it in an appropriate way and performance is also not affected.

Thanks,

Nidhi

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi Nidhi

Create a udf to check the alpha numeric value.

LtNumber-->UDF-->target field.

UDF Code:

try{

int i = Integer.parseInt(var1);

}

catch(NumberFormatException e){

return "0";

}

return var1;

Regards

Osman Jabri

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Osman,

Sorry I missed your reply so didn't tried before.

I tried your code and its working fine, but it will work context wise right?

Thanks,

Nidhi

Former Member
0 Kudos

The code is shared was for only for single values....If you are using input as array after changing context, you can use this.

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

try{

int temp = Integer.parseInt(var1[i]);

}

catch(NumberFormatException e){

result.addValue("0");

}

result.addValue(var1[i]);

}

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Osman,

Code seems fine, but I am getting value as 0 and then the actual value as well.

Its coming like this in the display queue-

0

W3943433 (this value should not come).

Can you please help with this?

Also, can i use suppress function instead of passing value 0.

Thanks,

Nidhi

justin_santhanam
Active Contributor
0 Kudos

Nidhi,

That's what the function I have given does isn't it .. It suppresses the value if it's not numeric.

Thx..

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Justin,

But it is not working as you suggested. Please find my reply below.

Thanks,

Nidhi

Former Member
0 Kudos

Add "continue" statement in the code, that will solve the issue.

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

try{

int temp = Integer.parseInt(var1[i]);

}

catch(NumberFormatException e){

result.addValue("0");

continue;

}

result.addValue(var1[i]);

}

Answers (5)

Answers (5)

nidhi_srivastava22
Active Contributor
0 Kudos

Hi All,

Thanks for your response.

Again a confusion is like -

IF I am adding a map(1-1, just removing the field if it is alphanumeric) before the main map(currently existing), will it impact performance or delay the messages?

Is it better to go for Graphical mapping or I can think for Java/XSLT from performance point of view?

Please suggest.

Thanks,

Nidhi

justin_santhanam
Active Contributor
0 Kudos

Hi Nidhi,

Check the below benchmark for the mapping programs comparison. I'm not sure what's the msg size/ or no.of transactions per day  . But I would say Graphical mapping should be okay in my opinion.

Comparing Performance of Mapping Programs | SCN

Also on the side note, when you are doing the calculation using Integer.parseInt you are type casting the string to Integer as you know it, just make sure what's your biggest number looks like.. Again I don't know the data, if it's really really big then you will get type casting error and you will get "0" as a result. Please watch out this one!

>>>>IF I am adding a map(1-1, just removing the field if it is alphanumeric) before the main map(currently existing), will it impact performance or delay the messages?


I would say add this logic in your current mapping program .. You are definitely adding overhead to the process because the client thinks it's complicated program and don't want to touch it. I would say convince them and add the logic in the current program and do more testing.

Thanks!

former_member186851
Active Contributor
0 Kudos

Nidhi,

You can just use UDF its not an extra mapping.And performance wise much difference wont be ter.

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Nidhi,

Try this this will work for multiple context too.

UDF : All values of context

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

{

if (var1[i].matches("[0-9]+")) 

  result.addValue(var1[i]); 

else 

  result.addSuppress(); 

}

Br,

Manoj

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nidhi,

             Do you need to delete the entire field or only delete the value within tags?

Regards

Anupam

former_member186851
Active Contributor
0 Kudos

Hello Nidhi,

In the first mapping for the LtNumber field use the below UDF and logic

for (int i=0; i<input.length(); i++) {
       
char c = input.charAt(i);
       
if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a)
           
return false;
   
}

   
return true;
}

Input------->UDF----->CreateIF------>LTNumber.

Let us know if you face any issues.

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Raghu,

I tried your code, edited a bit in the function definition -

public String createTargetCheck(String input, Container container) throws StreamTransformationException{

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

{

char c = input.charAt(i);

if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a)

   return "false";

}

return "true";

}

But the result is showing as true, either i pass numeric or alphanumeric.

Please suggest.

Thanks,

Nidhi

former_member186851
Active Contributor
0 Kudos

Hello Nidhi,

Try the below piece of code

public String createTargetCheck(String input, Container container) throws StreamTransformationException{

int flag = 0;

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

{

char c = input.charAt(i);

if (c < 0x30 || (c >= 0x3a && c <= 0x40) || (c > 0x5a && c <= 0x60) || c > 0x7a)

flag=flag+1;

}

if(flag>0)

{
  return "false";
}

else

{

  return "true"
}

}

Let me know if you face any issues.

justin_santhanam
Active Contributor
0 Kudos

Hi Nidhi,

Try this.

Assumptions here - The target field is of occurrence 0..1

Non-numeric field:

Numeric field:

UDF Code:


if (input[0].matches("[0-9]+"))

  result.addValue(input[0]);

else

  result.addSuppress();

Hope it helps!

Thanks!

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Justin,

Thanks for your reply.

I am adding the function, but its resulting into array index out of bound error.

Exception:[java.lang.ArrayIndexOutOfBoundsException: while trying to load from index 0 of an object array with length 0, loaded from the first parameter of the method] in class      

The value coming in the source field is alphanumeric say W7080AA.

Any suggestion?

Thanks,

Nidhi

Former Member
0 Kudos

Why dont you use the code that i shared....In that case you will not have to worry about removing the field as well....If alpha numeric value come it will be replaced with 0 which will not make any difference when you use it in addition/substraction.

justin_santhanam
Active Contributor
0 Kudos

Nidhi,

How did you create UDF? With Execution Type - All Values of Context, correct? Just see the screenshot.

Thanks!

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Justin,

I tried the same, PFB the screenshot attached.

Thanks,

Nidhi

justin_santhanam
Active Contributor
0 Kudos

Hi Nidhi,

Can you do a display queue on the Source field and give me the screenshot here?

Thanks!

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Justin,

PFB the screenshot for both source and function display queue.

Regards,

Nidhi

justin_santhanam
Active Contributor
0 Kudos

- I hope you are not changing the context of the source field in the mapping.

- What's the occurrence of the source field? Will the values always be there?

Thanks

nidhi_srivastava22
Active Contributor
0 Kudos

Hi Justin,

The source field occurrence is 0..1 but the the header to that source field is 0..unbounded.

This is not working.Please suggest.

Regards,

Nidhi

justin_santhanam
Active Contributor
0 Kudos

Okay try the same UDF , I have given with the below option.

- Do not change the context.


Source File - MapwithDefault[]- UDF - Target field.

Let me know the result.

Thank you,

Justin.