cancel
Showing results for 
Search instead for 
Did you mean: 

delete leading zeros for material in mapping.

Former Member
0 Kudos

Hi,

How to delete leading zeros for material like 0000000128736 if so I am expecting 128736 only.

We need to consider if I get material number is like RPG2389 .

Thanks,

Vinay.

Accepted Solutions (1)

Accepted Solutions (1)

markangelo_dihiansan
Active Contributor
0 Kudos

Hi,

If you will be getting alphanumeric codes, it would be best to use a UDF with a regex-expression.

UDF Type:

ContextType

imports:

java.util.regex; (if you are using PI 7.1 you must remove the semicolon)

arguments:

input1

Here's the code (courtesy of Sun Developer Network):


        Pattern p = Pattern.compile("[^a-zA-Z]");
        Matcher m = p.matcher(input1[0]);
        StringBuffer sb = new StringBuffer();
        boolean output = m.find();
        while(output) {
            m.appendReplacement(sb, "");
            output = m.find();
        }
        m.appendTail(sb);
result.addValue(input1[1]);

Now to solve the leading zeroes, just add formatNumber: 0 after the UDF and it will work.

Hope this helps,

Former Member
0 Kudos

Hi,

I can get both numeric value as well as character values for one field ( like 00009345 or mat123 ) . Please help me for this type values

Thanks,

Vinay.

justin_santhanam
Active Contributor
0 Kudos

Vinay,

Try the above code. It should work.

raj.

Former Member
0 Kudos

Hi Raj,

Thanks for response.

Can I use UDF for the above code ? How to pass my material number to those code ? Please explain me in detail.

Regards,

Vinay.

justin_santhanam
Active Contributor
0 Kudos

Vinay,

Yes- You have to use the UDF in order to implement the above code. Create a simple UDF with one input parameter. let say the variable name is input and don't forget to import java.util.*;

Map it like below:

MATNR --> UDF ---> Target field

Hope it helps!

Answers (3)

Answers (3)

Former Member

Hi Vinay,

use formatNumber standard function after your Material Number field then just place "#".

Hope it helps!

Cheers,

R-jay

stephen_xue
Active Participant
0 Kudos

obviously, this is the correct solution. the selected UDF solution should be working but not elegant. try to use native funcation as much as you can.

justin_santhanam
Active Contributor
0 Kudos

Vinay,

Use the below code, hope it helps! Get one parameter as input



BigDecimal bd;
		
		try
		{
		bd = new BigDecimal(input);
                return bd.toString();
		}
		catch(Exception e)
		{
                 return input;
		}

Thanks!

Shabarish_Nair
Active Contributor
0 Kudos

there are multiple ways you can do it -