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

remove space in value

Hi ,

I have a variable var1 type char18 ,Sometimes It has value '111.80 ' where the last character is a space and becomes part of value , so when we do some calculation , it goes into error , kindly guide whenever there is a space as a part of value , it be deleted.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

6 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 09:20 AM

    Hello,

    Take a look at the ABAP statement CONDENSE.

    Use transaction ABAPDOCU and the "Keyword Help" on CONDENSE to find out how to use this statement.

    I hope this helps you.

    Success.

    Wim

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hello,

      Did you take a look at how to use the CONDENSE statement in ABAPDOCU ?

      Have a look at the example and especially how the variables are declared (type string !).

      The flat structure sentence contains only character-type components and can therefore be assigned to the string text. After the execution of the CONDENSE statement, text contains "She feeds you tea and oranges". Before the condense operation, the words in text are 30 characters apart from one another.

      DATA: BEGIN OF sentence,

      word1 TYPE c LENGTH 30 VALUE 'She',

      word2 TYPE c LENGTH 30 VALUE 'feeds',

      word3 TYPE c LENGTH 30 VALUE 'you',

      word4 TYPE c LENGTH 30 VALUE 'tea',

      word5 TYPE c LENGTH 30 VALUE 'and',

      word6 TYPE c LENGTH 30 VALUE 'oranges',

      END OF sentence,

      text TYPE string.

      text = sentence.

      CONDENSE text.

      Wim

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 09:27 AM

    Hi,

    Use the keyword condense.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 09:59 AM

    Hi Praveen,

    The space at the end of the value is not the problem for calculations as the last space will not be considered in the text. When you do claculations see to it that the value you are passing into will be integer or float.

    Example: data: dat(18) type c,

    dat1 type p decimals 2.

    dat = '111.80 '.

    write:/ dat.

    dat1 = dat + dat.

    write:/ dat, dat1.

    The result wil be

    111.80

    111.80 223.60

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 10:19 AM

    Hi Praveen

    Please see the various data types of variables and the results they generated below:

    Data : var1 type char18 value '111.80 ', "space at the last

    var2 type c value '5',

    var3 type char20.

    var3 = var1 + var2.

    write : var3.

    Result:

    Var3 = 116.8

    -


    Data : var1 type char18 value '111.80 ', "space at the last

    var2 type i value '5',

    var3 type char20.

    var3 = var1 + var2.

    write : var3.

    Result:

    Var3 = 116.8

    -


    Data : var1 type char18 value '111.80 ', "space at the last

    var2 type i value '5',

    var3 type i.

    var3 = var1 + var2.

    write : var3.

    Result:

    Var3 = 117

    -


    Data : var1 type char18 value '111.80 ',

    var2 type c value '5',

    var3 type i.

    var3 = var1 + var2.

    write : var3.

    Result:

    Var3 = 117

    It works fine even when there is a space in the end.

    Be specific on what type of calculation you perform for more clear solution.

    Regards

    Sowbhagya

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Oct 08, 2010 at 10:41 AM

    HI,

    You can not perform arithmatic operations on char fields If variable declared by you always contains numeric value then transfer that value to any TYPE P variable.

    Regards

    Rajesh

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Oct 08, 2010 at 01:46 PM

    Moderator message - Please do not ask or answer basic questions - thread locked Rob

    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.