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

Calculation error with character type

Former Member
0 Likes
1,214

Good noon everyone.

In my previous post I have asked about the problem in displaying 0 in modulepool screen. I overcame it by declaring it as character type, but the problem here is that it is giving wrong result while calculations. It is giving * as the output.

Any ideas which datatype to use so that 0 is displayed in the screen and calculations are possible.

Dev.

1 ACCEPTED SOLUTION
Read only

sridhar_meesala
Active Contributor
0 Likes
838

Hi,

As you have already declared you field as character type, you can do one thing.

Declare anothe variable of type p and copy that screen value which you declared as type c into that and use that for your calculations. And declare your output field also of type p only.

Thanks,

Sri.

6 REPLIES 6
Read only

jrg_wulf
Active Contributor
0 Likes
838

Hi,

the + indicates, that your output field is too short. If you defined your field as c, without any length, the default length is 1. So you would be able to display and calculate all 1 digit values. Declare your field like this

data: output(15) type c

or like this

Data: output type char15

then your display field can display up to 15 digits (including all -,.)

Regards

Jörg

Read only

sridhar_meesala
Active Contributor
0 Likes
839

Hi,

As you have already declared you field as character type, you can do one thing.

Declare anothe variable of type p and copy that screen value which you declared as type c into that and use that for your calculations. And declare your output field also of type p only.

Thanks,

Sri.

Read only

0 Likes
838

Thanks very much Sri.

It worked.

But isn't there any data type that can display 0 and can also be used for calculation?

Dev.

Read only

Former Member
0 Likes
838

Hi DKBR,

You will need to do a small data conversion for this. Just create a fixed point numeric variable like:

DATA: p_num(8) type p decimals 2. "Or whatever parameters are suitable

and then pass the character field value to this variable:

p_num = character_variable.

Just put in a check before this statement to verify whether all the characters in your character-type variable are actually numerals. This you can do as follows:

data: string_num(10) type c value '0123456789'.

if character_variable CO string_num. "Contains Only

<proceed>

else.

<throw error>

endif.

Hope this helps! Please revert if you need anything else.

Cheers,

Shailesh.

Always provide feedback for helpful answers

Read only

Clemenss
Active Contributor
0 Likes
838

Hi dkbr1992,

I did not see your previous thread, no link given.

  • just means that the result does not fit in the field. If you declare a character(1) and try to put the result of, say 4+7=11 here, it will display as * because 11 has two characters and the variable has only one.

Regards,.

Clemens

Read only

Former Member
0 Likes
838

Hi,

if you are performing calculations on 'char' fields it will show unexpected results or some times may leads to dump.

do one thing, before displaying the variable(on which you need zeros) move that value(having no zeros-numeric value)

into a variable of type 'NUMC'.

it will works.

then no need to perform on 'char' fields.

move the value to any other type after performing all the calculations. if you move before and perform operations on that new variable you will unexpected values only.

Hope clear right.

Thanks & regards,

Sasi Kanth.