Skip to Content
author's profile photo Former Member
Former Member

Convert variable

Hi,

I need to convert a variabel.

p_lifnr is now 123999.

I need it to be 0000123999.

Is there any FM that can fix this ?

select * from EKKO where lifnr = p_lifnr.

//Martin

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • Best Answer
    Posted on Feb 10, 2005 at 08:01 AM

    Hello,

    If LIFNR is defined as type: char, then FM CONVERSION_EXIT_ALPHA_INPUT will pad the variable with leading zeros.

    Regards, Murugesh AS

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi everybody,

      You *all* are right. I only try to make my tiny contribution.

      Generally speaking, every domain (associated to a data element, associated to a field of a table) can have its own conversion routine.

      For instance, take a look into domain LIFNR (thru transaction SE12). At frame "Output characteristics", pls watch field "Conversion routine". In this case, it shows "ALPHA". That means there should be (at least) two function modules, one for input->output, the other one for output->input. In fact, if you double-click onto this field, you will get a matchcode with such function modules.

      I personally use these function modules instead of filling out with zeroes manually.

      Please let us know if it helped. Best regards,

      Alvaro

  • author's profile photo Former Member
    Former Member
    Posted on Feb 10, 2005 at 08:07 AM

    Hello Martin,

    There's one thing that you need to observe. If you are talking about the SAP standard field LIFNR, then the field will already contain the zeroes prefixed. The only thing is that you don't get to see it when you display it, say for example on the list. Just look at the following example, which might be a bit amusing to you.

    data : p_lifnr type lifnr.
    
    select single lifnr
      from lfa1
      into p_lifnr
     where lifnr gt 1. " Just to make sure that you select a numeric value"
    
    
    write p_lifnr.
    
    skip 2.
    * We know thast LIFNR is 10 characters long.
    do 10 times.
      write : / p_lifnr+0(sy-index).
    enddo.

    I shall leave the reasoning to you, coz I trust it's good fun <i>trying</i> to discover what happens <i>behind the screens..</i> Just see if you can make sense out of it. And get back if you have some doubts.

    Regards,

    Anand Mandlaika.

    P.S: BTW, if you already know how this whole thing works, then I'm sorry for assuming that you may not have known it 😊.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 10, 2005 at 07:43 AM

    Hi Martin,

    data l_lifnr(10) type n.
    move p_lifnr to l_lifnr.

    Now <b>l_lifnr</b> will contain the data in the format that you require.

    Regards,

    Anand Mandalika.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 10, 2005 at 07:48 AM

    hi,

    there's a form routine:

    PERFORM ALPHAFORMAT(SAPFS000) USING p_lifnr p_lifnr .

    regards Andreas

    Message was edited by: Andreas Mann

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 10, 2005 at 08:36 AM

    Hi!

    Unfortunately you're <b>NOT</b> all right.

    If lifnr contains at least one character (not only numbers), then NO leading zeros will be added by conversion_exit_alpha_input. That's the only correct handling, approach with variable type n is not working for all circumstances.

    Regards,

    Christian

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hello Christian,

      Obviously the comment that I have made put in the code (for the WHERE clause of the SELECT statement) in my explanation above was not articulate enough. I <b>did</b> mean that LIFNR would have to be a <i>numeric</i> value for the logic to work. But yes, the where condition is not <u><i>sufficient</i></u> to discard the alpha-numeric values for LIFNR.

      Secondly, though <i>possible</i>, I did not consider it <i>likely</i> that LIFNR would have an alpha-numeric value (in which case I should've probably omitted the WHERE clause altogether, you say?:-)).

      Regards,

      Anand Mandalika.

  • Posted on Feb 10, 2005 at 01:31 PM

    Hello Anand,

    I guess, I made my sentence to short:

    instead of 'not all right' -> 'not everyone was right' (or something like this) - I like to direct your focus on cases with characters.

    Example code of Anand can be extended by using no where-clause - but who wants to write 20 000 vendors.

    To show some examples:

    Internal External

    '1-001 ' '1-001 '

    '30A001 ' '30A001 '

    '0000000001' '1 '

    '0000001001' '1001 '

    Like Alvaro already mentioned: a lot of fields follow conversion rule alpha (e.g. mara-matnr). There will be customers, which use combinations of chars and nums; be careful (in general, not just Anand 😊).

    By the way: FM CONVERSION_EXIT_ALPHA_INPUT calls immediatly a system function (C-routine), so performance should be very good.

    Regards,

    Christian

    P.S.: I didn't mean to offend you

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.