Adding two leading zeroes infront of a variable(both character and numeric)

Hi Experts,
I have a variable v_data. Whatever is the value of the v_data, two leading zeroes should get added to it.
v_data may be numeric or charachter type.
I am using FM CONVERSION_EXIT_ALPHA_INPUT for adding two preceding zeroes for numeric types but for character types what logic I should use?
Currently I am doing:
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
  EXPORTING
    input         = v_data
IMPORTING
   OUTPUT        = v_data.
if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
    SHIFT v_data BY 2 PLACES right.
    v_data+0(1) = '0'.
    v_data+0(2) = '0'.
endif.
But the above code is giving output like this: 0 P0001 but I want output like 00P0001.
How to fix it?
Regards,
Sangeeta.
Edited by: Sangeeta on Nov 11, 2008 6:22 AM

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = v_data
IMPORTING
OUTPUT = v_data.
if v_data CA 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.
SHIFT v_data BY 2 PLACES right.
v_data+0(1) = '0'.
v_data+1(1) = '0'.   " change this
endif.

Similar Messages

  • Adding Leading Zero's to a variable

    Hi friends ,
                <b>1.</b> I want to add leading zero's to a field .
    Wxample - LIFNR , if its value in a variable is 16987 then i want to convert it to standard format (0000016987).
    <b>2.</b> I want to convert date format to system's format. In Dev server and quality server it is in different format and i'm facing problem while uploading data using BDC.Also how i'll identify that in which format it is in production.
    How to get it

    Hi,
    <u>Use these function Modules for ur problems..</u>
    (1)For adding leading zeroes or in sap format internal..
    CONVERSION_EXIT_XXXXX_INPUT
    (2)For changing date into systems internal format..
    CONVERSION_EXIT_XXXXX_INPUT.
    u can find out conversion routines for each corresponding domain of that field in given below procedure.
    Domain->Defintion->Output Characteristics-> Conversion routine.
    Double click on that, it will show corresponding conversion routines.
    Please add ur rewards.
    With regards,
    Rajesh

  • How to add leading zeros to a packed variable

    Hi all,
    I have a to add leading zeros for a packed field.
    eg.
    Data : brgew like mara-brgew.
    brgew = '12.063'.
    but I have to display the field as '0000000000012.063'.
    How can we achieve this?
    Regards.

    Execute the code .
    REPORT zex13 .
    Data : brgew like mara-brgew.
    brgew = '12.063'.
    data:val(18) type c,
         in(13) type n ,
         dec(6) type c.
    data :  a type i ,
            b type i.
            a = TRUNC( brgew ).
            write:/ a .
    in = a.
    write:/ in.
            dec = frac( brgew ).
            write:/ dec.
            concatenate in  dec+2(4) into val separated by '.'.
            write:/ val.
    see if this works for u .
    regards,
    vijay

  • EBS check number with leading zeros

    When we upload EBS, we are getting the check number in the record 16 (reference field). But unlike the check number posted in SAP, the check number in the BAI file has 2 leading zeros. Now since check number is coming in record 16, instead of record 88 we are not able to solve this problem through String configuration.
    So, we thought of following solutions(Options):
    1.    Modify the check lot numbers to have two leading zeros plus associated changes like the form and so on.
    2.    Modify the check number in the incoming file u2013 strip the check number with two leading zeros with the use of customer enhancement. (After upload and before posting)
    Can we solve the problem of leading zeros (before the check number) through any configuration steps instead of changing the SAP script form for check(Check lot) or going for customer enhancement.
    Thanks
    Ron

    You are correct, since the check numbers are coming through only in the 16 records and not in the 88 records, you cannot use a search string to resolve the issue with leading zeros.  Also, I do not know of any other configuration that can be used to reformat the reference values in the 16 records.
    The 2 solutions you have listed are both valid options.  Although with the first option (changing the check lots), you would need to make sure the business users approved of changing the check lots before going forward with that option.  And you would still have to manually clear checks that had been issued prior to the check lot change.
    At my company, we went with the second option - using ABAP code to update the check numbers from the file to match those in SAP (we actually had to add leading zeros to the check numbers).  In our case, we had already created a pre-processor program for other re-formatting of the file that was needed prior to loading it into SAP - so we added the check number logic to that.
    However, if you do not have a pre-processor program, I know there is a user exit available for EBS - exit EXIT_RFEBBU10_001, include ZXF01U01.  I have heard of others using this exit to update the check numbers from 16 records.  The exit is called during the FF.5 processing.
    Regards,
    Shannon

  • Problem with Leading Zeros

    Hi Experts,
    In the start routine, I  am trying to compare  two object 0PLANT and ZSTORE which  contains the same values. But the problem is 0PLANT is of length 4 and ZSTORE is of length 8. As a result,for example,  the value 2  in  0PLANT is stored as '0002' and as ' 00000002'  in ZSTORE.
      I have written the code as following, which is not working due to the leading ZEROES. Please note that Both objects don't have ALPHA conversion as part of the info Object Definition.
    *Select PLANT /BIC/CBRCH_GRP from /BI0/PPLANT into table I_PLNT
    where PLANT = DATA_PACKAGE-/BIC/ZSTORE.*
    Though I knew that there is a FM CONVERSION_EXIT_ALPHA_OUTPUT, I am not sure whether we can use that FM for procesisng bulk amount of data.
    Request you all to propose a solution for the same.
    Thanks in advance,
    Babu Vasamsetti.

    Hi Babu ,
    Please use the code below.
    You can modify it according to your requirements :
    TYPES: BEGIN OF TY_ZTORE,
            ZTORE TYPE /BIC/OIZTORE
            PLANT TYPE /BI0/OIPLANT,
           END OF TY_ZTORE.
    DATA:       LT_ZTORE TYPE STANDARD TABLE OF TY_ZTORE,
          LS_ZTORE TYPE TY_ZTORE.
    SELECT /BIC/ZSTORE FROM
    /BIC/PZSTORE INTO TABLE LT_ZTORE
    FOR ALL ENTRIES IN DATA_PACKAGE.
    SORT LT_PLANT BY /bic/ZTORE.
    DELETE ADJACENT DUPLICATES FROM LT_DATAPACKAGE COMPARING /BIC/ZSTORE.
    LOOP AT LT_ZTORE
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          INPUT         = LT_ZTORE-/BIC/ZSTORE
       IMPORTING
         OUTPUT        = LT_ZTORE-PLANT.
    ENDLOOP.
    Select PLANT /BIC/CBRCH_GRP from /BI0/PPLANT into table I_PLNT
    where PLANT = LT_STORE-PLANT.
    -Vikram

  • Removing Leading Zeros

    Hi Friends,
    I need to delete leading zeros from material while loading to ODS and have tried followings options:
    CONVERSION_EXIT_ALPHA_OUTPUT
    Shift Variable LEFT deleting leading zeroes
    Both the options did not work in my case. I need to delete leading zeros from material. For example if source has material as "00000000002213749R" I was to convert it as "2213749R".
    Following is the code I am using in transformation:
    DATA: LV_MATNR(18) TYPE C.
    LV_MATNR = SOURCE_FIELDS-/BIC/Z9AMATNR.
    CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'
         EXPORTING
              INPUT  = LV_MATNR
         IMPORTING
              OUTPUT = LV_MATNR.
         RESULT = LV_MATNR.
    Also I tried the following code for SHIFT:
    DATA: LV_MATNR(18) TYPE C.
    LV_MATNR = SOURCE_FIELDS-/BIC/Z9AMATNR.
    SHIFT LV_MATNR  LEFT deleting leading zeroes
    RESULT = LV_MATNR.
    I tried both the option but could not get the leading zeros deleted. Can some one let me know whats wrong with the code, or is there any other option i can try for?
    Thanks,
    Manmit

    Hi amitesh,
                 Please try this code
    DATA: LV_MATNR(18) TYPE C.
    LV_MATNR = SOURCE_FIELDS-/BIC/Z9AMATNR.
    SHIFT LV_MATNR LEFT DELETING LEADING '0'.
      RESULT = LV_MATNR.
    Hope this will help u.....
    Regards,
    Yuvaraj.
    Edited by: sap_yuvaraj on Dec 13, 2010 12:54 PM

  • Leading zeroes on eight digit PO number

    We had a requirement to use an eight digit number for PO number instead of the standard 10 digits that SAP uses.  To accomplish this we created our number ranges with two leading zeroes (for example range 0060000000 to 0069999999).  Now on the GR screen when someone creates a GR based on a PO it is requiring that they enter the leading zeroes.  Is there any way to avoid this or is it always going to be required since that's the way the number range is assigned?
    Thanks!

    This can be ignored.

  • Leading Zeros in bank Account for EBS

    Hi,
    We configured the bank account number with two leading zeros in the house bank.  Say for example i defined the bank account number as 0012345 Under house bank HSBC.
    When I receive the bank statement, the bank account number is coming with 12 digits i.e. will all leading zeros. say for example 000000012345.
    When i am loading the bank statement using the transaction FF_5, the system is giving the error Table "T012K does not have an entry with bank account number 12345".  The client is saying the length of account number is 7 digits and should be maintained as 0012345. However the EBS is not working with the leading zeros. How can we fix this issue?
    Regards
    Kotesh Padarti

    Hello!
    You can try to configure alternatice bank account in FI12. This is used in situations when the presentation of bank account in bank statement differs from that configured in main bank account field e.g. your house bank might provide you with the following layouts 000000012345 or 0012345USD etc. Therefore this functionality enables the system to recognize the bank account.
    Hope this will help you!
    Best Regards!

  • Leading zero problem!

    Hi !
    i have a numeric type variable i.e. 'w_xyz type n length 7'
    now i want to delete the leading zero's for this variable simultaneously want to retain the length of the field unaltered i.e.
    if  w_xyz = '0000987'  then i want
    w_xyz = '    987'.
    any help pls,
    Thanks in advance.
    Regards,
    Parwez.

    Hi,
    There is a simple way to achieve that : just use shift statement.
    SHIFT w_xyz LEFT DELETING LEADING '0'.
    Regards,
    Nicolas.

  • Leading zero on char field

    I have what would be a simple thing.  A need to have leading zero retained on a variable..that holds a month.
    I have a field that is 20090501 and I want to make it 20090401...  that is take 1 month off
    But problem is the calculation does not give leading zeros
    ... here is very cut down version of what I am doing
    DATA:  lv_Period(8) type c,
          lv_mm(2) type c.
    lv_mm = '05'.
    lv_mm = lv_mm - 1.   "becomes 4.    " how do I make it "04".
    concatenate '2009' lv_mm '01' into lv_Period.    " this becomes  2009401  and not 20090401

    DATA: lv_Period(8) type c,
    lv_mm(2) type c.
    lv_mm = '05'.
    lv_mm = lv_mm - 1. "becomes 4. " how do I make it "04".
    if lv_mm is LT  '10'.
    concatenate '2009' '0' lv_mm '01' into lv_Period. 
    else.
    concatenate '2009' lv_mm '01' into lv_Period. " this becomes 2009401 and not 20090401
    endif.

  • Cfspreadsheet how to preserve leading zeroes

    Is there a way to preserve leading zeroes in a field when displaying in excel other than adding a ' at the front of the field?  I have an id field defined in sql server as varchar but when creating an xls document using cfspreadsheet excel is interpreting the field as numeric and dropping the leading zeroes.  I cannot have the ' leading that field since it is imported into another system.

    This has been resolved.  I tested both suggested solutions.  I tried formatting the columns with spreadsheetformatcolumn as suggested in http://stackoverflow.com/questions/3081202/how-to-format-spreadsheet-c olumns-using-coldfusion but that did not preserve the leading zeroes in the ID column.  I then tried the solution with POI found here http://www.bennadel.com/projects/poi-utility.htm by Ben Nadel and that did preserve the leading zeroes.  Thanks for everyone's assistance and thanks to Ben for sharing his POI utility.
    - Julie

  • 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

  • Leading zeros not displaying

    Hi All,
    I have a characterstic info object that is set up as CHAR-3 which is an attribute of another info object.
    The source of this characterstic is a R/3 field. In R/3 that field is showing value as 004 but in Bex it shows only 4.
    When I check the data in the info provider, it looks fine just like R/3 ie 004. The problem is just in Bex.
    How can I dispaly the two leading zeros before the 4 in Bex?
    Thanks in advance.

    Hi,
    You should be careful in doing this. Try to convince your user to use the present one itself.
    As if you want to perform this action then I think you need to remove ALPHA conversion manually in the next level systems before importing the object from D to Q and then P. As I think the Transport will not overwrite by removing the ALPHA directly in the target systems.
    When you import the transport in the target system then it will fail stating that the ALPHA is removed. So here you have two options either manually activating the object or by using the program to activate the object?
    So I ask you to be careful in this case, as for many of the clients in Q and P systems the objects can not be edited!!
    So check the same before proceeding further.
    Thanks
    Murali

  • Downloading data from internal table to xls file leading zeros are not disp

    Hai abap gurus,
    when i am downloading data from internal table to excle file. some field values in a column are with leading zeros and some others dont have leading zeros.but in the output it is showing without leading zeros. then how to get with exact values.
    Ex:
    <b>ECC Code.</b>
    045234
      88567
    098456 
    but output is giving like this:
    45234
    88567
    98456
    how to get the actual values.....
    plz help me in this matter.

    Dear Kiran,
    Those field in the internal table having Leading Zeroes, make those fields' datatype as character.
    Then use the function module to download the content of the internal table to the excel file.
    Regards,
    Abir
    Don't forget to Reward Points  *

  • Grid Download to Excel truncates leading zeros

    We are on tools 8.51. The download feature for a Grid now removes the leading zeros when the grid is downloaded to excel. Has anyone found a way to fix this issue ? Thanks in advance

    When you download from PS query, the output is created as a true binary xls file, but when you download from a grid in PT 8.51 the output file is html, even though the filename is ps.xls. You can open this file in a text editor.
    If you have all numeric data in a column, it will be stored as <td>nnnnnn</td> in the html file. if the column has mixed numeric and text data, it will be stored as <td>=&amp;quot;nnnnnn&amp;quot;</td>. The leading zeroes are still there in both cases, but when excel imports the first form it will convert the result to numeric, the second it will treat as text.
    Other than logging a case with Oracle, the only workaround I could think of would be to save the file to disk and run the macro directly against the html. Of course, this would likely be a major redesign.
    Regards,
    Bob

Maybe you are looking for