cancel
Showing results for 
Search instead for 
Did you mean: 

Function for Leading Zeroes and alphanumeric chararcters

Former Member
0 Kudos

Hi Friends,

I have a requirement where i want to suppress leading zeroes of material number, when i send to external legacy system .

I can achieve this by using round function, but the problem is the material can be alphanumeric characters also. If i use Round function , it will support only in deleting leading zeroes.

How i can achieve both functionalities?

Any suggestions please..

Regards,

Vijay

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member518917
Participant
0 Kudos

Hi,

before mapping to the target field , add one UDF... and write logic to delete leading zero.

UDF: removeLeadingZero

code:

String b = a.replaceFirst("^0+", "");

return b;

aashish_sinha
Active Contributor
0 Kudos

Hi,

Write a UDF like this ..

public String remLeadZeros(String a,Container container){

String b = a.replaceFirst("^0+", "");

return b;

}

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

Hi,

I tryed with the given function, but ended with below error.

is anything missing ?

F:/usr/sap/XID/DVEBMGS02/j2ee/cluster/server0/./temp/classpath_resolver/Mapfe3717e2007511dd8649001a64268de4/source/com/sap/xi/tf/_MM_ArticleMaster_.java:202: illegal start of expression public String remLeadZeros(String a,Container container); ^ 1 error

Regards,

Vijay

prateek
Active Contributor
0 Kudos