Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

remove space in value

Former Member
0 Likes
1,093

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.

8 REPLIES 8
Read only

Former Member
0 Likes
1,050

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

Read only

0 Likes
1,050

Hi,

I have tried condense but it is not rem,oving the last space of the value .

Kindly advise me.

The below code is working

SHIFT input-value RIGHT DELETING TRAILING space.

SHIFT input-value RIGHT BY 1 PLACES.

CONDENSE input-value NO-GAPS.

but i dont know when space will be last character.

kindly advise

Read only

0 Likes
1,050

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

Read only

Former Member
0 Likes
1,050

Hi,

Use the keyword condense.

Read only

Former Member
0 Likes
1,050

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

Read only

Former Member
0 Likes
1,050

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

Read only

rajesh_akarte2
Active Participant
0 Likes
1,050

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

Read only

Former Member
0 Likes
1,050

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