Adding leading zeros to a non-numeric field

Hello
I have an application which currently does not validate a field and the user can enter any string on this specific field. The customer wants me to write a view to bring information from a child table which uses the free format field as the key to join.
Example, the field A is free format, but, we would expect something like "0000001-AB', however the users are inputing '1' or '001-AB'. The client wants to see these cases to be displayed (and joined) as '0000001-AB'. The format is 7 digits + '-' + two digit code.
I would like to know, how can I display this on a view, since most of my cases are '1' or '001-AB'. But there are others with crazy things like '1+2+3+4' and these cases are giving me an error of "invalid number" since I am using the TO_NUMBER function so far.
Thanks!
Eduardo Ferrari

WITH t AS (SELECT '1' txt FROM DUAL
           UNION
           SELECT '001-AB' FROM DUAL
           UNION
           SELECT '1+2+3+4' FROM DUAL)
SELECT CASE
          WHEN LENGTH ( (REGEXP_REPLACE (txt, '[-AB]') || '-AB')) < 10
          THEN
             LPAD ( (REGEXP_REPLACE (txt, '[-AB]') || '-AB'), 10, '0')
          ELSE
             REGEXP_REPLACE (txt, '[-AB]') || '-AB'      
         end  txt
from t
TXT
0000001-AB
0000001-AB
1+2+3+4-ABunion
Edited by: pollywog on Nov 10, 2010 3:41 PM
Edited by: pollywog on Nov 10, 2010 3:53 PM

Similar Messages

  • FM WHICH adds leading zeroes to a non numeric input

    hi i need the<b> fm name</b> which will add leading zeroes to anu non numeric input
    say
    input is <b>ABC</b>
    SO MY OUTPUT SHOULD BE
    <b>000000000000ABC</b>
    URGENT
    NEED A FUNCTIOJN MODULE NAME

    i think no fn module is there for non numeric values to add zero do like this..
    data : text(20) value 'ABC',
           len type i.
    compute len = strlen( text ).
    len = 20 - len.
    do len times.
    concatenate '0' text into text.
    enddo.
    write : / text.
    regards
    shiba dutta

  • 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

  • Truncation of leading zero's for a numeric field

    How to truncate leading zeros for numeric key figure field. The field value shows 0.0000000000000000E+00. Why the value shows like this??? Plz explain.
    Draj S

    Hi,
    I guess the Infoobj is FLOATING POINT. So its displaying that way.

  • F8as2-displaying leading zeros in a dynamic text field

    F8as2-
    Background:
    Currently I have to use two different text fields to display 10000 due to the different font sizes.
    The 10 is a larger font and the 000 is a smaller font.  When I assign '0 'to the dynamic text fields of the smaller font I get just that a '0' not a '000' which is what I want.
    Question:
    Is there an easy way to display leading zeros in a dynamic text field?  Or can a dynamic text field have different character positions displayed in different font sizes?  or both?
    Thanks for the help.

    F8as2-
    Thanks for the reply kglad.
    Are for saying the best way to display numerically calculated numbers that need leading zeros and or different font sizes is to convert them to a string for display purposes with textFormatting??

  • 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 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

  • @ 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

  • At new- command - making non-numeric fields as ******* how to correct this

    Hi,
    I am using the following code.
    Tables : vbap.
    DATA: t_vbap TYPE STANDARD TABLE OF vbap,
          x_vbap TYPE vbap.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-000.
    SELECT-OPTIONS: s_vbeln FOR vbap-vbeln.
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      SELECT * FROM vbap
        INTO TABLE t_vbap
        WHERE vbeln IN s_vbeln.
      LOOP AT t_vbap INTO x_vbap.
        at new vbeln.
          write:'new vbeln'.
          ENDAT.
      ENDLOOP.
    In debugging mode, the non-numeric fields on x_vbap becomes ****
    I want to know whether this can be done using oops.. any methods available for at new
    Moderator message: please search for available information/documentation before asking (as you can tell from some of the replies so far)
    locked by: Thomas Zloch on Oct 1, 2010 3:25 PM

    see documentation:
    "If the INTO addition is used in the LOOP statement to assign the content of the current line to a work area wa, its content is changed upon entry into the AT-ENDAT control structure as follows:
    The components of the current control key remain unchanged.
    All components with a character-type, flat data type to the right of the current control key are set to character "*" in every position.
    All the other components to the right of the current control key are set to their initial value.
    When the AT-ENDAT control structure is exited, the content of the current table line is assigned to the entire work area wa. "

  • How do I take two separate non numeric fields in a acrobat form and combine the data to display in a third separate field?

    How do I take two separate non numeric fields in a acrobat form and combine the data to display in a third separate field?

    You have to use custom JavScripting to concatenate the first 2 fields. You cannot use the first 2 calculation options because they force the values of the fields to a numeric value or ignore string values.
    Possible scripts for the 3rd field are:
    event.value = this.getField("Text1").valueAsString + " " + this.getField("Text2").valueAsString;
    or
    event.value = this.getField("Text1").valueAsString.concat( " ",  this.getField("Text2").valueAsString);
    If you do not want change the separator or not show the separator when on or the other field is empty, you will need to add more code to adjust for change.
    The above scripts will also concatenate number because the field values are read as strings and not numbers.
    There is also a generalized user written function to concatenate up to 3 fields with a separator that adjust for missing data.

  • Catching errors such as divide by zero and typing non-numeric characters

    Fellows: How do I extend following script to catch errors such as divide by zero and typing non-numeric characters.      Thanks
    This program takes two integers (whole numbers), then displays the sum, average, division,
    Modula of those numbers and finally the first number raised to the power of the second number.
    import java.io.*;
    public class HWOne
         public static void main(String[] args) throws IOException  // error handling
              // variable declaration
              String firstdigit, seconddigit;
              int first, second, sum, total, modus, power;
              float division;
              double average;
              BufferedReader myIn = new BufferedReader(new InputStreamReader(System.in));
              //Invoke user response
              System.out.print("Please enter first digit ");
                   firstdigit = myIn.readLine();
                   first = Integer.parseInt(firstdigit);
              System.out.print("Please enter second digit ");
                   seconddigit = myIn.readLine();
                   second = Integer.parseInt(seconddigit);
              //computations
              sum = first + second;
              average = (double)sum / (double)2;
              division = (float)first / (float)second;
              modus = first % second;
              power = (int)Math.pow(first, second);
              //Screen message
              System.out.println("Sum: " + sum);
              System.out.println("Average: " + average);
              System.out.println("Division: " + division);
              System.out.println("Modula: " + modus);
              System.out.println("Power: " + power);

    Have you learnt about try/catch statements yet?
    The parseInt method throws a NumberFormatException. So you place the call to that method inside a try statement and catch the exception.
    For divide by zero, you can use an if statement. If the divisor != 0 perform division.

  • Convert non numeric field

    I'm looking for a function that will allow a conversion from a non-numeric field to a numeric field. Any suggestions?

    CAST(col as INTEGER) or CAST(col as DOUBLE)

  • 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 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

  • 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.

Maybe you are looking for

  • Gradient Color Picker

    Dear Community, i have a Problem with Illustrator CS6. I've attached an image below. I have an object with gradient fill and i've selected the first color stop. In previous Versions of AI i could the pick any color with color Picker while holding the

  • MM MIRO Invoice Parking calc due date from PO not working

    When I Park and invoice linked to a purchase order (PO) using MIRO/ MIR7 the invoice due date is not calculating using either the Vendor or PO terms code. We do not see the same issue with FB60 and both work fine when the invoice is Posted and not pa

  • JDBC or RandomAccessFile?

    I'm thinking of developing a pure Java application/applet that gets line inputs from text files and stores them in either a random access file or a database, whichever is workable, for later retrieval. I was told I may need SQL so I am thinking of JD

  • Upload Program(sap-abap)

    Hi Friends,     I am using existing program to upload data(MM01 - BASIC VIEW ).But one of the field(MARA-BISMT) for old material number is neither uploading to transaction nor database.I have to uoload for other views(Purchasing, Accounting and so on

  • Format gets lost when I copy

    Hi I try to format some text within pages and copy it to another program where it is much more complicate. Does anybody know why I loose the formats  -  as if I would copy / paste out of a simple editer