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

Problem with DEC data type

Former Member
0 Likes
1,217

Hi,

Problem with the DEC data type, for the -ve values the field contains the -ve sign but for the +ve values it is not storing the space.

Im concatenating couple of fields and one of the field is of DEC type. So my requirement is that when this DEC type field is at the end of the line then it is not storing the space for +ve values.

Ex:

f1 type DEC value is 1.002- and 1.50.

Now when this field is at the last during concatenation, it avoids space after the value 1.50 which normally contains 1.50 (1 space).

How to get this space in my internal table.

Thanks

rohith

12 REPLIES 12
Read only

rainer_hbenthal
Active Contributor
0 Likes
1,161

Spaces at the end of a character variable are always ignored by the system. Use strings instead. [Read this about characters versus strings|https://www.sdn.sap.com/irj/scn/weblogs?blog=/pub/wlg/15889] [original link is broken] [original link is broken] [original link is broken];

Read only

0 Likes
1,161

Hi,

Thanks for the reply.

For getting the data from db tables, i have used the same data type.

after that i have declared one string variable to concatenate all the fields. Now, here if the field contains decimal values with sign then blank is ignored for +ve values.

ex: concatenate f1

f2

f3 into wa_string

now f3 contains +ve and -ve values. so, finally in wa_string it doesn't contains the blank space which is requird for the f3 field.

I hope you understood my problem.

thanks

rohith

Read only

0 Likes
1,161

Hi,

As Rainer suggested, if you as a string variable before concatenation, the space for + will be considered. Just try executing this sample code and check if you are getting the space


data: char type decfloat34,
      char1 type decfloat34,
      var type string,
      var1 type string,
      var3 type string.

char = '-1245.34'.
char1 = '12312.34'.
var1 = char.
var3 = char1.
concatenate var3 var1 into var.
write: var.

Vikranth

Read only

0 Likes
1,161

If f3 is a character string its clear because you dont have s space at the end. Why didnt you read the blog?

Read only

0 Likes
1,161

Hi,

F3 is not a character string, its a DEC data type. As per the ex given by vikranth

data: char type decfloat34,

char1 type decfloat34,

var type string,

var1 type string,

var3 type string.

char = '-1245.34'.

char1 = '+12312.34'. (here + sign is replaced by a blank space)

var1 = char.

var3 = char1. ( i require the value and the blank space)

concatenate var3 var1 into var.

write: var.

Here, i require concatenate var1 var3 into var. finally in var i would get only 1245.34- 12312.34. Here after 12312.34 blank space should come but that is not coming.

Guess you got my requirement.

Thanks

rohith

Read only

0 Likes
1,161

But why dont you read the answers.... just transfer dec to a string an concatenate afterwards... but this was said already...

Only in strings trailing characters are taken in affect!

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,161

Hello Rainer,

Your blog elucidates the technique perfectly, but the OP does not want to take the pains of reading it & wants ready-made code.

Anyways thanks for the blog, well done !!

Cheers,

Suhas

Read only

0 Likes
1,161

Hi Rainer,

do you think i haven't done this small piece of testing ?

I have moved these two variables f1 f2 into a string, then i have concatenated both the variables into another string s1. My problem is like the last variable i.e. f2 doens't hold trailing space at the end.

But if i concatenate S1 '|' into S2 then f2 holds the blank space.

I need to avoid the second step, so my requirement is like in the first concatenation only i need to get the blank space.

Hi suhas

( I have done R&D then only i had posted this thread).

Thanks

rohith

Read only

0 Likes
1,161

Hi,

A variable declared of the type DEC will hold the space for the sign only at the last postion of the string and not at the first postition.

So when a negative value will be stored as 1245.34- and a postive value will be stored as 12312.34+.

when you concatenate negative and postive value you will get 1245.34-12312.34 (space included at the end).

Thats why in the sample i mention concatenate positive value and negative value to verify the space. The result will be

12312.34 1245.34- (Space after the postive value)

Hope you are clear now

Vikranth

Read only

0 Likes
1,161

You only put such effort into avoiding one intermediate step?

Read my blog again until you understand why spaces at the end of a character differs completly from spaces at the end of a string. You cant avoid doing additional steps mixing up chars and strings.

Read only

0 Likes
1,161

Hi Vikranth

That is wht im saying..

when you concatenate negative and postive value you will get 1245.34-12312.34 (space included at the end). Here you won't get any space at the end (plz check).

But if it is like 12312.34 1245.34- then you will get space.

What i assume is that the blank space will be considered only when the field is not at the end of the line. If it is at the end then blank space will be ignored no matter if it is string or char.

Thanks

rohith

Read only

0 Likes
1,161

Hi,

Any solution regarding the query which i had raised.

Thanks

rohith