Application Development 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: 

What should happen when you add float and packed datatype values?

ajaygupta
Participant
0 Kudos

REPORT  ZDATATYPES.

data :

          xyz type f VALUE '123',

          pqr type p VALUE 12.

data : t type f.

t = xyz + pqr.

write t.

"OUTPUT


1,3500000000000000E+02

Why the o/p comes with trailing zeroes? Is there a way to remove it without changing their datatypes?

1 ACCEPTED SOLUTION

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

You mix up two things:

  • internal representation of data
  • output format (here WRITE)

The data object t has type f and for that reason the calculation type is f and the internal representation of the result is type f.

When using WRITE for any data type (here f), an implicit formatting of the output takes place that is described in the documentation. If you want to format your output in another way, use the respective formatting options.

In order to change the internal format, you assign to other data objects with other data types adhering to the conversion rules. You can also use the conversion operator CONV for that.

3 REPLIES 3

Former Member
0 Kudos

this is the text representation of your float variable.

For proper display you should pass the value on a char field by using a FM, there are quiete a few of those.

0 Kudos

change result data type to packed ....

REPORT  ZDATATYPES.

data :

           xyz type f VALUE '123',

           pqr type p VALUE 12.

data : t type DECIMALS 2 . "DECIMALS 2.

t = xyz + pqr.

write t.

horst_keller
Product and Topic Expert
Product and Topic Expert
0 Kudos

You mix up two things:

  • internal representation of data
  • output format (here WRITE)

The data object t has type f and for that reason the calculation type is f and the internal representation of the result is type f.

When using WRITE for any data type (here f), an implicit formatting of the output takes place that is described in the documentation. If you want to format your output in another way, use the respective formatting options.

In order to change the internal format, you assign to other data objects with other data types adhering to the conversion rules. You can also use the conversion operator CONV for that.