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

How to Determine Length of variable up to period (.)

I have a variable called my_var in an ABAP and it is passed many #’s and they may or may not have some text following these #’s --- these #’s can have a Length of up to 13 and will always have 3 Decimal Places. I need to find a way to return the length of the # up to the decimal place.

The # is always first in this variable, it will always have a .000 and it may or may not have text following it. The only way I can think of doing this is to
loop through the my_var one character at a time to find the decimal place and to determine the length. Does anyone have any other ideas?

Examples:

my_var = “22.000 ABC” would return the length of 2

my_var = “0.000 this is more text” would return the length of 1

my_var = “1200000.00” would return the length of 7

my_var = 87098.000” would return a length of 5

my_var = “987.000 this is text again” would return a lenth of 3

Message was edited by: Manish Kumar : Basic programming. Answer can be easily found by searching. Thread locked.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on Jul 23, 2014 at 02:08 PM

    So you did not find the statement to find a character in a string, look for it again you should find it...

    Regards,

    Raymond

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2014 at 02:06 PM

    Hi Janice,

    You can use TRUNC function to read the integer part.

    Regards,

    Ashvin

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jul 23, 2014 at 02:11 PM


    Hi,

    You can use the SPLIT statement at the character - '.'

    SPLIT my_var AT '.' INTO lv_var1 lv_var2.

    lv_length = strlen (lv_var1).

    Regards,

    Abhi

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Jul 23, 2014 at 02:27 PM

    Hi ,

    try this

    data : var1 type char20 value '222.000ABC'.

    data : part1 type char10,

    part2 type char10.

    data : lv_int type i.

    split var1 at '.' into part1 part2.

    lv_int = strlen( part1 ).

    write : 'length of Interger Before decimal',lv_int.

    Regards

    pavan

    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.