Truncating the leading zeros

hi,
Could anybody pls tell me how do i truncate the leading zeros in the incoming file structure.
Thanks,
Chinna

Hi,
Check this thread, i laready answered it there.
Suppressing leading zeroes during mapping
For you i pasting the solution here.
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

Similar Messages

  • Truncating the leading zeros which has both numbers and characters

    Hello Everyone,
    Can anybody pls help me to truncate the leading zeros in the incoming file structure which has both the numbers and characters.
    Thanks,
    Chinna

    HI,
    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

  • Truncating the leading zero's

    Hi experts,
    I have an ALV output, in which one of the fields is equipment number (equi-equnr).
    There are some leading zero's that I need to truncate from the ALV output.
    How can I achieve this? The code is as given below:
      fieldcatalog-fieldname   = 'EQUIPMENT_NUMBER'.
      fieldcatalog-seltext_m   = 'Equipment Number'.
      fieldcatalog-col_pos     = 5.
      append fieldcatalog to fieldcatalog.
      clear  fieldcatalog.
    Thanks,
    Ajay.

    Hello,
    Your requirement is that you need to display the equipment number in the ALV without the leading zeroes.
    Ypur code is
    fieldcatalog-fieldname = 'EQUIPMENT_NUMBER'.
    fieldcatalog-seltext_m = 'Equipment Number'.
    fieldcatalog-col_pos = 5.
    append fieldcatalog to fieldcatalog.
    clear fieldcatalog.
    Just before append statement add the following
    fieldcatalog-no_zero = 'X'.
    Now try the same it should solve your problem.
    Regards,
    Sachin
    Edited by: Sachin Dargan on Jan 19, 2010 7:34 AM

  • Truncates the leading zeros even though the member is text type

    We have members with data type “TEXT” in planning database. When user enters something with leading zero, it saves the same in relational but not showing the same in planning. It truncates the zero even though it is a text member.
    Planning version 11.1.2
    Example:
    Member name : Issue code (TEXT type)
    Entered value : 011_Issue (saves the same in relational)
    Display value : 11_Issue (Drops the zero)
    is there any workaround?
    Thanks

    I've opened a SR and here is the reply from MOS.
    Apply a fix for Bug 12422049 - DATA TYPE TEXT MEMBER DOES NOT DISPLAY VALUE STARTING WITH ZERO CORRECTLY when its available.
    The issue has been identified as a code bug and development team will fix it in future releases.
    Thanks
    Poorna

  • The leading zero in serial number..

    Hi all,
    Does anyone happen to know how to stop SAP from erasing the leading zero when entering a Serial number. I'm using profile 0003 (standard) and when a GR is posted the leading zeros are removed?
    Any help would be greatly appreciated.
    Best regards
    Begüm A.

    In the Standard SAP system, it is not possible to stop it from truncated the leading zeros.
    But if you are using  ECC6.0 and using Industrial Solutions, you may use the modification
    introduced by note 198285 to achieve this functionality.

  • Need to truncate extra leading zeros

    Post Author: dougatrueb
    CA Forum: Formula
    Dear Crystal Report Gurus,  I am trying to trucate the leading zeros in a feild that I am pulling from and ODBC table name {Inventory.ItemNumber}.  The item number will be similiar to 0000003785768 as an example, and I need it to trancate the leading zeros so the data looks like; 3785768.  Is there such a way to this easily? Thanks. Dougatrueb 

    Post Author: SKodidine
    CA Forum: Formula
    I am assuming that the itemnumber is a string.  If you want it as a string but truncate the leading zeros then do this:
    If NumericText({Inventory.ItemNumber}) thentotext(tonumber({Inventory.ItemNumber}),0,'','')else{Inventory.ItemNumber};

  • Non truncation of Leading Zero

    Hi All,
      I am downloading a .xls file using the function module "GUI_DOWNLOAD".
    But it is truncating the leading zero's in some fileds.
    For example : in the field Account group , value is "0001" but in .xls file it is coming as "1".
    Can anyone please help me on how to avoid this truncation of leading zeros.
    Thanks and Regards,
    Nimisha Deshpande.

    Just execute this porgram and check ur result .
    For this u need to handle the file type as DBF .
    types: begin of t_dat,
             fld1(30) type c,
             fld2(30) type c,
           end of t_dat.
    data: it_dat type table of t_dat,
          wa_dat type t_dat.
    wa_dat-fld1 = '12345678901234567890'.
    wa_dat-fld2 = '00000000000000043210'. "->
    append wa_dat to it_dat.
    wa_dat-fld1 = '12345678901234567890'.
    wa_dat-fld2 = '00000000000000543210'."->ur input
    append wa_dat to it_dat.
    CALL METHOD CL_GUI_FRONTEND_SERVICES=>GUI_DOWNLOAD
      EXPORTING
        FILENAME                  = 'C:\test.xls'
        FILETYPE                  = 'DBF'
      CHANGING
        DATA_TAB                  = it_dat[]
      EXCEPTIONS
        FILE_WRITE_ERROR          = 1
        NO_BATCH                  = 2
        GUI_REFUSE_FILETRANSFER   = 3
        INVALID_TYPE              = 4
        NO_AUTHORITY              = 5
        UNKNOWN_ERROR             = 6
        HEADER_NOT_ALLOWED        = 7
        SEPARATOR_NOT_ALLOWED     = 8
        FILESIZE_NOT_ALLOWED      = 9
        HEADER_TOO_LONG           = 10
        DP_ERROR_CREATE           = 11
        DP_ERROR_SEND             = 12
        DP_ERROR_WRITE            = 13
        UNKNOWN_DP_ERROR          = 14
        ACCESS_DENIED             = 15
        DP_OUT_OF_MEMORY          = 16
        DISK_FULL                 = 17
        DP_TIMEOUT                = 18
        FILE_NOT_FOUND            = 19
        DATAPROVIDER_EXCEPTION    = 20
        CONTROL_FLUSH_ERROR       = 21
        NOT_SUPPORTED_BY_GUI      = 22
        ERROR_NO_GUI              = 23
        others                    = 24.
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY  NUMBER SY-MSGNO
                WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    if sy-subrc eq 0.
    write:/ 'Download completed'.
    endif.
    Hope this works for u .
    Vijay

  • EAN values truncationg the leading zeroes

    Hi experts,
    I have created two new EAN category for one category accepts one leading zeroes another category accepts two leading zeroes.
    In the material master i am trying to enter the same EAN values with different unit of measure system accepts the EAN value for one UOM and when i am trying to enter the same value for another UOM with two leading zeroes the leading zeroes are truncating.I can see the below warning message.When i press enter the leading zeroes are truncated.
    _EAN already used for unit of measure EA of this material_
    Please help me how to solve the issue.

    i guess this is coming because you have already mentioned the EAN no in one material amster and the data is maintained at client level so system is not allowing redundntcy

  • Remove the leading Zero from the Query output in SAP BW ?

    Hi
    Experts,
    Vendor Number loaded  as   (0000010076) from R/3 to SAP BW.
    How to remove  Prefix  of Zero for  the Vendor Number(0000010076)  from Quey outpt.
    Regards.
    ASIT

    Hi,
    Please check out this thread.
    Remove leading zeros
    Also check if there is any conversion routine used for that particular infoobject.
    If ALPHA conversion is selected for your infoobject then it will automatically take away the leading zeros at query level.
    Regards,
    AL
    Edited by: AL1112 on Sep 16, 2011 9:15 AM

  • How can we put the leading zeros for the extract file.

    hello experts..
           Iam extracting values from one ztable in this for one filed length will be 2, for this field i need leading zero s at the time of extract... please help me....

    Hi,
    Declare the field as NUMC data type, automatically you will get the leading zeroes.
    Regards,
    Subramanian

  • How can I remove the leading zeros on jpg files?

    I'm looking for a way to remove the leading zeros on over 1000 jpg files, without changing the remaining digits in the file name. Is there some automated "batch" script?
    i.e going from 003405607.jpg  to  3405607.jpg

    You could write an AppleScript. but it will be easier to get and use a third-party file renaming utility. I use the freeware NameChanger which works quite well.
    https://www.macupdate.com/app/mac/21516/namechanger
    Regards.

  • How to maintain the leading zeros

    Hi all,
    I need help on this.
    I have field KNB1-KUNNR its real value for example is 0000000001,so there is leading zeros,but then everytime the program output the report leading zeros are removed. I need to display the leading zeros as is.
    By the way KNB1-KUNNR is declared as knb1-kunnr LIKE knb1-kunnr.
    thanks!

    Hi..
    Use this code for adding leading zeros for a particular field.
           CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
             EXPORTING
               input         =  p_kunnr
            IMPORTING
              OUTPUT     = p_kunnr.
    Use this code for removing leading zeros for a particular field.
           CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
             EXPORTING
               input         =  p_kunnr
            IMPORTING
              OUTPUT     = p_kunnr.

  • How to suppress the leading zeros , -ve sign in scripts

    Hi all,
    I was asked to suppress the leading zeros in a field while using a script.
    also how to suppress the negative sign in the scripts.
    Regards,
    Saroja.

    hi Saroja,
    <u>Sign</u>
    &ITCDP-TDULPOS& -> 100.00-
    &ITCDP-TDULPOS(S)& -> 100.00
    <u>zero</u>
    &DAY& -> 01
    &DAY(Z)& -> 1
    Hope this helps,
    Sajan Joseph.

  • Document Templates in MS Word - how to cut the leading zeroes in number

    Hello CRM gurus !
    We use document templates in MS Word but have the document number printed with the leading zeroes.
    example we have now:
    0005000681
    example we want to have:
    5000681
    Question - how to do that?
    Is that in standard? The document number is the ObjectID tag as far as I know. Do I need to create another tag?
    Or may be just call a function? Do I need to change my current Web Service Tool? Is that some extra ABAP to be inserted?
    Thank you very much.

    Hi,
    have you tried to use this function call to delete de leading zeros?:
         CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
           EXPORTING
             input  = value
           IMPORTING
             output = value.
    Best regards
    Manfred

  • Losing the leading zero in binary values

    Hi all,
    I�m currently creating some basic examples of bitwise operations and I�ve just noticed that I�m losing the leadnig zero of a binary value ( e.g.
    decimal 1 (expecting to see bin of 0001) is manifesting as 1
    decimal 16 (expecting to see bin of 00010000) is manifesting as 10000
    below is a full example
    import static java.lang.Integer.*;
    public class BitExample {
    public static void main(String[] args) {   
    System.out.println(
         toBinaryString(0x1) + '\n' +
         toBinaryString(0x16) + '\n' +
         toBinaryString(0x6a) + '\n' +
         toBinaryString(0x80)
    I can see I�m missing something, but not sure what. Can you help?
    Many Thanks
    Giles

    which obviously returns a very different resultNo it does not ... let's translate the example to decimal (with additions instead of bitwise operations, but that doesn't change anything:
    1234 +
    0001
    1235and
    1234 +
    1
    1235both notations are correct, aren't they? Now the second one doesn't look so nice (and usually the 1 should be right-aligned to be easily readable, but it isn't wrong, because of this.
    The same is true for binary operations. The problem is, that while learning bitwise operations it's easier to unserstand if you always write the leading zero (as you do in your example).

Maybe you are looking for