cancel
Showing results for 
Search instead for 
Did you mean: 

Suppressing leading zeroes during mapping

Former Member
0 Kudos

Dear All,

I am having one requirement in which i want to compress all the leading zeroes for the material no only eg 0000123450 shuld be converted into 123450.

Is there any standard function available which compresses the leading zeroes???

Waiting for your valuable response.

Regards,

N.Jain

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

nishu,

Create a user defined funciton <b>zerosuppress</b> and take the <b>cache as value</b> and take <b>one argument input</b>. Then put the code below:

//write your code here

String output = input.replaceFirst("^0+","");

return output;

i will suggest u to check these threads also..

regards

biplab

Answers (5)

Answers (5)

aashish_sinha
Active Contributor
0 Kudos

HI Nishu,

Can you please mark this thread as answered if the purpose is done?

Also reward points.

Regards

Aashish Sinha

Former Member
0 Kudos

Hi Ashish,

While I was working on this, some problem came in my PRD Server and I was not able to solve this issue.I will surely mark this thread as answered once I am thru with the things.

Thanks for your valuable replies.

Regards,

N.Jain

aashish_sinha
Active Contributor
0 Kudos

Write a UDF like this ..

public class test {

public static void main(String[] args) {

System.out.println(args[0].replaceAll("^0*",""));

}

}

Also you can use XSLT for this.

Try the XPath function number($string) in your XSLT and see if it does what you want. Since it turns any XPath object into a number, the leading zeros won't appear.

Use it ike this

<xsl:variable name="a">

<xsl:call-template name="removeLeadingZeros">

<xsl:with-param name="phone">

<xsl:value-of select="EVENT/ContactPhone"/>

</xsl:with-param>

</xsl:call-template>

</xsl:variable>

<xsl:template name="removeLeadingZeros">

<xsl:param name="phone"/>

<xsl:message>

<xsl:value-of select="$phone"/>

</xsl:message>

<xsl:choose>

<xsl:when test="starts-with($phone,'0')">

<xsl:call-template name="removeLeadingZeros">

<xsl:with-param name="phone">

<xsl:value-of

select="substring-after($phone,'0' )"/>

</xsl:with-param>

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$phone"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

Regards

Aashish Sinha

PS : Reward Point if Helpful

Former Member
0 Kudos

Good solution, but duing Mapping specially just one to one mapping filed if

standard functions do not work then we just have to write UDF with few java lines

and use that UDF to achieve the requirement. Its not good to write separate XSLT Mapping for one field?

Thanks

Farooq.

aashish_sinha
Active Contributor
0 Kudos

Agreed with you but it depends upon the requirement you have. I guess we can also provide the more fields if it the same or may be we can reuse it if it happening regularly.

Writing an UDF is always a good solution but why don't we try some different solutions also to check the performance of system?

Regards

Aashish Sinha

Former Member
0 Kudos

>why

> don't we try some different solutions also to check

> the performance of system?

Yes that is really good , but it woth while doing dummy projects..in real scenario we have to make things simple:)

Thanks

Farooq.

Former Member
0 Kudos

Hi nishu,

I dont think ther is any standard function for this , but u can write ur <b>User Defined Function</b> or u can use <b>If Else</b> condition or apply some logic for this .

hope this will help

regards

HONEY

Former Member
0 Kudos

Hey Nishant,

>>public static void main(String[] args) {

>>System.out.println(args[0].replaceAll("^0*",""));

Don`t use the above method to replace leading zero.

Sumit

Former Member
0 Kudos

HI Nishu.

You just defined the maximum permissible length of that field as you requirement.

Then test it.

The values specified for the size category and data class are mapped to database-specific values via control tables.

for your knowlegge base

*rewards pointsif you thing it will help you.*

Regards

Sumit Gupta

Former Member
0 Kudos

Hi

Use format number or write a udf for the same.

Thanks

Former Member
0 Kudos

Write Simple UDF:

Steps Create the UDF : <b>removeLeadingZeros</b> with one parameter (String a)//

and paste the below code in that and save it. then map

source -removeLeadingZeros-target


                if (a == null)
                {
                        return null;
                }
                char[] chars = a.toCharArray();
                int index = 0;
                for (; index < a.length(); index++)
                {
                        if (chars[index] != '0')
                        {
                                break;
                        }
                }
                return (index == 0) ? a : a.substring(index);

It will solve your problem:)

Thanks

*Rewards Points if you find it useful*

Former Member
0 Kudos

Use the aobe java code, it will work as per your requirement:)

Just I created the same function and its working fine:)

Thanks

Farooq.