cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PI mapping query

Former Member
0 Kudos

Hi Experts,

I have a mapping query regarding an UDF.

I am mapping a field A with field B. Now,

The requirement is that the incoming field will have the requirement:

1. Should be 4 Numeric values, Should only allow Numbers,Should not have spaces or symbols

Now, UDF always returns string so how to check that.

Let me know.

Regards,

Aniruddha

Accepted Solutions (1)

Accepted Solutions (1)

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Aniruddha,

Use this UDF

public String fieldValidation(String inputValue, Container container) throws StreamTransformationException{
if(inputValue.length() > 4 || inputValue.indexOf("-") != -1)
 {
   return "greater than 4 digits or conatain -1";
 }
try
{
  Integer outputValue = new Integer(inputValue);
  return outputValue + "";
}catch(NumberFormatException nfe)
 {
   return "has non numaric value";
 }

}

Regards,

Raghu_Vamsee

Answers (2)

Answers (2)

Former Member
0 Kudos

answered

Former Member
0 Kudos

You can try with MaskFormatter command

zipField = new JFormattedTextField(
                    createFormatter("#####"));
...
protected MaskFormatter createFormatter(String s) {
    MaskFormatter formatter = null;
    try {
        formatter = new MaskFormatter(s);
    } catch (java.text.ParseException exc) {
        System.err.println("formatter is bad: " + exc.getMessage());
        System.exit(-1);
    }
    return formatter;
}

To find if there's a Space or a SpecialChar, you can use follow code:

char letterChar = ' ';
for (int i = 0; i < message.length (); i++)
        {
            if(message.charAt(i) == letterChar) {
                // found
            }
        }