Adding leading zeros in abap objects.

Can anyone explain me
1. How to add leading zeros to a field in abap objects.
For eg:
data: dmb(6) type c value '123456',
actually the output value of c should have leading zeros added to it for length 16.
i.e '0000000000123456' . If the length of dmb is less than 16 then leading zeros should be added to that value to make it 16 as length.
Please tell me how to do it in ABAP Objects.

Hi Camila
Try to use the statement
DATA: ALPHABET(15) VALUE '     ABCDEFGHIJ',
      M1(4)        VALUE 'ABCD',
      M2(6)        VALUE 'BJJCA '.
SHIFT ALPHABET LEFT DELETING LEADING M1.
The field
ALPHABET
remains unchanged.
SHIFT ALPHABET LEFT DELETING LEADING SPACE.
The field ALPHABET now has the following contents:
'ABCDEFGHIJ     '.
SHIFT ALPHABET RIGHT DELETING TRAILING M2.
<b>ALPHABET</b> now has the following contents:
'      ABCDEFGHI'.
<u><b>IN CHARACTER MODE</b></u>
<b>Effect</b>
This is the default setting (see above), and the addition is therefore optional.
<b>Note
Performance:</b>
For performance reasons, you should avoid using SHIFT in WHILE loops.
The runtime required to shift a field with length 10 by one character to the right or left requires about 5 msn (standardized microseconds). A cyclical shift requires around 7 msn. The runtime for the ...
LEFT DELETING LEADING
... variant is around 3.5 msn, for ...
RIGHT DELETING TRAILING
... around 4.5 msn.
Reward all helpfull answers
Regards
Pavan

Similar Messages

  • How to delete decimal point and adding leading zeros....

    Hi,
    I have one requirement in the report   i.e.
            <b>Present Value    :</b>  44567.98
            <b>Expected Value  :</b> 0000004456798
    In the present Value how will I remove that decimal point and how to add those six ing zeros. I tried with CONVERSION_EXIT....but it is not giving. Help me...
    Thanks in advance.
    Regards,
    Kumar.

    Hi,
    Use SPLIT and COMCATENATE fnctions.
    Eg:  split l_v at '.' into l_v1 l_v2
            concatenate l_v1 l_v2 into l_v.
    For adding leading zeros
    Use FM CONVERSION_EXIT_ALPHA_INPUT.
    Eg:
    data: tknum type vttk-tknum value '99156'.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
         exporting
              input  = tknum
         importing
              output = tknum.
    Sri
    Message was edited by:
            Sri Tayi

  • Leading zeroes in ABAP

    How to remove leading zeros in ABAP?

    shift <field> left deleting leading '0'.
    U write ur code like this
    data a(9) value '000012345'.
    SHIFT a LEFT DELETING LEADING '0'.
    write:/ a.
    Output will be : 12345
    Or use this method also
    data a(9) value '000012345'.
    Call function 'CONVERSION_EXIT_ALPHA_OUTPUT'
    Exporting
    input = a
    Importing
    output = a.
    write a.
    output:
    12345.
    Thanks and best of luck
    Reward if useful
    Ankesh

  • @ adding leading zeros to a number

    Hi,
    How do I go abt adding leading zeros to a 8- digit number?
    eg DATA: number(8) Type N.
        number = 16.
    How do i go about converting this to '00000016'.
    Note that the value in variable number would be read frm a file (Inbound prog).

    Hi,
      Use the function.
    data: tknum type vttk-tknum value '99156'.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
         exporting
              input  = tknum
         importing
              output = tknum
    Regards

  • 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

  • Adding leading zeros before data loaded into DSO

    Hi
    In below PROD_ID... In some ID leading zeros are missing before data loaded into BI from SRM into PROD_ID. Data type is character. If leading zeros are missing then data activation of DSO is failed due to missing zeros and have to manually add them in PSA table. I want to add leading zeros if they're missing before data loaded into DSO.... total character length is 40.. so e.g. if character is 1502 then there should be 36 zeros before it and if character is 265721 then there should be 34 zeros. Only two type of character is coming either length is 4 or 6 so there will be always need to 34 or 36 zeros in front of them if zeros are missing.
    Can we use CONVERSION_EXIT_ALPHPA_INPUT functional module ? As this is char so I'm not sure how to use in that case.. Do need to convert it first integer?
    Can someone please give me sample code? We're using BW 3.5 data flow to load data into DSO.... please give sample code and where need to write code either in rule type or in start routine...

    Hi,
    Can you check at info object level, what kind of conversion routine it used by.
    Use T code - RSD1, enter your info object and display it.
    Even at data source level also you can see external/internal format what it maintained.
    if your info object was using ALPHA conversion then it will have leading 0s automatically.
    Can you check from source how its coming, check at RSA3.
    if your receiving this issue for records only then you need to check those records.
    Thanks

  • Leading zeroes to the objects; no conversion exist

    Hi All,
    Info object data  is showing leading zeroes even though there is no conversion exit.
    Here is the exact scenario: ZABC_WHL1 is the navigation attribute of MATNR_ABC.both fileds doesn't have any conversion exit.ZABC_WHL1 is of length 20.
    Loaded the data for MATNR_ABC using a attrib data source .Upto the PSA level for ZABC_WHL1 (corresponding ECC filed)there are no leading zeroes.But when we go to display data for this objects it is showing leading zeroes ie.00000000000000023456.
    Can anyone suggest how to remove these zeroes.
    Thanks
    Sri

    Hi,
    please check the link http://www.sd-solutions.com/SAP-HCM-BW-Conversion-Routines.html.
    Hope it helps.
    Regards,
    Prakash

  • Need to strip the leading ZERO using ABAP code.

    Hi Friends,
    I got a situation where i got customer number called 011. I need to write an ABAP in Transformation to strip the leading ZERO , 11 should be posted to the master data attribute. could you help me in the logic pls.
    Thanks in advance,

    hi friends, i got a prob again, as i mentioned if i got 0 as prefix its deleting but if any 3 digit is comming it's converting in to 2 digit, as i mentioned if the prefix is 0(zero) then only i need to delete the zero.
    Is there any other solution for this..
    thansk in advance.

  • Adding leading zeroes (PADDING in SQL Server)

    Hi to everyone,
    Is there a function to add leading zeros to int converted to varchar?
    I have 5, need to get varchar(5) = 00005..
    I hate to do like left('00000',5-len(Int))+cast(Int as varchar)
    I know in Oracle there is PAD, what about SQL Server?
    Thanks

    There is nothing like PAD in SQLServer 2008, but SQLServer 2012 has  FORMAT ([fieldname], '00000').
    For SQLServer 2008, I've found that something like this works...
     Right('00000'+ convert(varchar,[fieldname]),5)

  • Trouble adding leading zeros to numbers in PowerShell script

    I am new to PowerShell scripting (so have mercy on me please!), and I'm trying to write a script that takes simplified, menu-based user input to create a folder on the network named based on a month number and the year. The month must be expressed as a two-digit
    number, but I'm trying to make it simple enough that the user only needs to input a one-digit number (for the first nine months of the year) and have the script add the leading zero (for example, if a user inputs the number "2" for February, the
    script will output "02").
    Here is a portion of my script:
    # Get current year
    $year = Get-Date -Format yyyy
    # Provide menu of months for user to choose from
    Write-Host "Choose the name of the month for the folder you want to create."
    Write-Host "1. January"
    Write-Host "2. February"
    Write-Host "3. March"
    Write-Host "4. April"
    Write-Host "5. May"
    Write-Host "6. June"
    Write-Host "7. July"
    Write-Host "8. August"
    Write-Host "9. September"
    Write-Host "10. October"
    Write-Host "11. November"
    Write-Host "12. December"
    Write-Host " "
    Do {
    $mNum = Read-Host "Select the number of the month (1 - 12): "
    # Convert the menu item to the month name
    switch ($mNum)
    1 {$month = "January"}
    2 {$month = "February"}
    3 {$month = "March"}
    4 {$month = "April"}
    5 {$month = "May"}
    6 {$month = "June"}
    7 {$month = "July"}
    8 {$month = "August"}
    9 {$month = "September"}
    10 {$month = "October"}
    11 {$month = "November"}
    12 {$month = "December"}
    default {"Invalid entry. Please select a number from 1 - 12 (without the trailing period)."}
    # Validate user input. Current code is cumbersome; try to find more elegant method.
    While ($mNum -ne 1 -and $mNum -ne 2 -and $mNum -ne 3 -and $mNum -ne 4 -and $mNum -ne 5 -and `
    $mNum -ne 6 -and $mNum -ne 7 -and $mNum -ne 8 -and $mNum -ne 9 -and $mNum -ne 10 -and `
    $mNum -ne 11 -and $mNum -ne 12)
    # Add leading zeros to month number
    $fNum = "{0:D2}" -f $mNum
    Write-Host $fNum
    When I run it, I don't get the leading zero. However, when I create a very basic script, it seems to work:
    $mNum = 3
    $fNum = "{0:D2}" -f $mNum
    Write-Host $fNum
    Can anyone offer any suggestions as to what I might be doing wrong?
    Also, if anyone has a suggestion on how to better validate the user input (making sure they enter a number between 1 and 12), I would appreciate that as well.

    .NET formatting is a complicated subject
    http://msdn.microsoft.com/en-us/library/26etazsy(v=vs.110).aspx#FormatStrings
    I'm not sure how all that documentation applies when you attempt to format a value that is already a string.
    In general, formatting is described as "Formatting is the process of converting an instance of a class,
    structure, or enumeration value to its string representation".  If it is already a string I'm not sure what to expect.
    For example,
    <# C: #> '3',3,'03',03,'003',003 | % { "{0:D2}" -f $_ }
    3
    03
    03
    03
    003
    03
    <# C: #>

  • Adding leading zeros...

    I have a number (let's say 12345) and I need to add 3 leading zeros to it and make it 00012345. I could do it by first converting the number to a string, concatenating '000' to it and then converting it back to a number.
    I realize this is a trivial question, but how do you convert a number to a string and then back to a number in Oracle 10g?
    Thanks.

    In reference to the above, I need to store a total of 8 characters in vTgtSALES.EMPLOYEE_ID. For example, if the vTempEmpID variable has 5 characters, I need to add 3 zeros, etc. I have the following code:
    vTgtSALES.EMPLOYEE_ID:=CASE Length (LTrim(RTrim(vTempEmpID)))
              WHEN 0 THEN WriteLog (pCmdID, pSubCmdID, 'Employee ID value has length of zero. WMC: ' || srcSALESNNM.WMC)
              WHEN 1 THEN '0000000' || vTempEmpID
              WHEN 2 THEN '000000' || vTempEmpID     
    WHEN 3 THEN '00000' || vTempEmpID
              WHEN 4 THEN '0000' || vTempEmpID      
    WHEN 5 THEN '000' || vTempEmpID
              WHEN 6 THEN '00' || vTempEmpID
              WHEN 7 THEN '0' || vTempEmpID                WHEN 8 THEN vTempEmpID
              ELSE WriteLog (pCmdID, pSubCmdID, 'Employee ID value too long for field. WMC: ' || srcSALESNNM.WMC)          
         END;
    The CASE clause does not seem to work - the actual value of vTempEmpID is stored in vTgtSALES.EMPLOYEE_ID without leading zeros being asses. What am I doing wrong?
    Thanks.

  • Adding leading zeros to the display data

    hi folks,
    I have the character variable of size 9, if I get the value of the variable less than 9, I need to add leading zeros to it accordingly before displaying the numeric value stored in it. I tried to use the 'SHIFT' command for that it did not work out.
    here is the code..
             data: len type I,
                   amount type C,
                   addspace len type I.
              len = strlen( amount ).
              write: ' the length of the string',len.
               if ( len < 9 ).
               addspace = 9 - len.
               write: addspace.
    SHIFT amount BY addspace Places LEFT.
    Thanks in advance.

    Hi Santhosh,
    All the suggestions here will work. Make sure that your number is on the right justified to your character field. Here is an example.
    DATA: v_char09_left_justified(09)  TYPE c,
          v_char09_right_justified(09) TYPE c,
          v_numc09(09)                 TYPE n.
    START-OF-SELECTION.
    *-- in case the value is left justified in the field
      v_char09_left_justified = '9        '.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
           EXPORTING
                input  = v_char09_left_justified
           IMPORTING
                output = v_char09_left_justified.
      WRITE:/ 'V_CHAR09_LEFT_JUSTIFIED from FM =', v_char09_left_justified.
      v_numc09 = v_char09_left_justified.
      WRITE:/ 'V_NUMC09 =', v_numc09.
    *-- in case the value is right justified in the field
      v_char09_right_justified = '        9'.
      SHIFT v_char09_right_justified LEFT DELETING LEADING space.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
           EXPORTING
                input  = v_char09_right_justified
           IMPORTING
                output = v_char09_right_justified.
    WRITE:/ 'V_CHAR09_RIGHT_JUSTIFIED from FM =', v_char09_right_justified.
      v_numc09 = v_char09_right_justified.
      WRITE:/ 'V_NUMC09 =', v_numc09.

  • Adding leading zeros in a field mapping

    Hi,
    I am getting account as a 5 char field in the input file. I need to map this to a 10 char field in XI and add leading zeros in case the value is all numeric. Is there any standard data type/ mapping that can achieve this or I need to write a UDF.
    Thanks,

    formatNum field will cause an exception if your input isnt all numeric...
    I'd go for UDF id your input isnt always numeric.
    Regards,
    Henrique.

  • Adding leading Zeros to table

    Hi i have a table having structure as
    CREATE TABLE "OMPODI"."END_RECORD"
    "RECORD_TYPE" CHAR(5 BYTE),
    *"TOTAL_NUMBER" CHAR(10 BYTE)*
    and insert statement is as
    insert into ompodi.end_record
    (select 'END',to_char(count(*)+2) from omp.ompproduction where locationid='MES2'
    and (select distinct to_char(to_date(productionweek,'YYYYMMDD'),'ww') from omp.ompproduction)>=(SELECT TO_CHAR(sysdate,'WW') FROM DUAL))
    I want to have leading zeros for total_number.
    e.g:- i i have a count of 10 then it should be displayed as '000000010'.
    How it can be achieved?
    Edited by: MaheshGx on Feb 5, 2012 10:29 AM
    Edited by: MaheshGx on Feb 5, 2012 10:29 AM
    Edited by: MaheshGx on Feb 5, 2012 10:30 AM

    MaheshGx wrote:
    Hi i have a table having structure as
    CREATE TABLE "OMPODI"."END_RECORD"
    "RECORD_TYPE" CHAR(5 BYTE),
    *"TOTAL_NUMBER" CHAR(10 BYTE)*
    and insert statement is as
    insert into ompodi.end_record
    (select 'END',to_char(count(*)+2) from omp.ompproduction where locationid='MES2'
    and (select distinct to_char(to_date(productionweek,'YYYYMMDD'),'ww') from omp.ompproduction)>=(SELECT TO_CHAR(sysdate,'WW') FROM DUAL))
    I want to have leading zeros for total_number.
    e.g:- i i have a count of 10 then it should be displayed as '000000010'.
    How it can be achieved?
    Edited by: MaheshGx on Feb 5, 2012 10:29 AM
    Edited by: MaheshGx on Feb 5, 2012 10:29 AM
    Edited by: MaheshGx on Feb 5, 2012 10:30 AM
      1* select to_char(10,'0000000009') from dual
    SQL> /
    TO_CHAR(10,
    0000000010

  • Function Module for adding Leading Zero's to a specific field

    Hi,
    Can anyone please provide a Function that will do the following:
    1. Take the value of the field
    2. Take the field type
    3. Output the value of the field with leading zero's.
    Anything similar would be very helpful.
    Thank You & Best Regards,
    John

    Sure use the function  CONVERSION_EXIT_ALPHA_INPUT, this will add leading zeros to a character based field of any length.
    data: lv_c(10) type c value '123'.
    call function 'CONVERSION_EXIT_ALPHA_INPUT'
              exporting
                      input = lv_c
              importing
                     output = lv_c.
    write:/ lv_c.
    Regards,
    Rich Heilman

Maybe you are looking for