cancel
Showing results for 
Search instead for 
Did you mean: 

Adding zeros & eliminating zeros based on condition

Former Member
0 Kudos

Hi All,

Good Afternoon...!!

I do have a requirement wherein its File to Idoc scenario sales related details are send.

The Materials contains both numeric and alphanumeric strings.

For numeric it should add nine zero's in front and if is alpha numeric it should go to target(IDOC) as such.

SOURCE              TARGET

20520071016  = 00000000020520071016

20528081015 = 00000000020528081015

20528081020 = 00000000020528081020

1101084AF = 1101084AF

1101084FX = 1101084FX

1101084NN = 1101084NN

Is there any solution for this using UDF or mapping code? Please help. Many Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

azharshaikh
Active Contributor
0 Kudos

Hi Rajesh,

You can achieve it using following UDF:

if( var1.matches("^-?\\d+$"))

return "000000000"+var1;

else

return var1;

Regards,
Azhar

Former Member
0 Kudos

Thanks alot Azhar.

Above code achieved my requirement successfully.

Answers (1)

Answers (1)

iaki_vila
Active Contributor
0 Kudos

Hi Rajesh,

Check this wiki UDF for Zero Padding on Left - Code Gallery - SCN Wiki

In the b parameter you can set the length of the string by one constant.

Regards.