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

Addition problem

Former Member
0 Likes
553

hi all,

I have number' s 297,513.38 and 1258,716,037.93- and 1,000,000.00- like this in variables with commas and dots. I need to do addition for these numbers and i need to get a output of addition like 1259,418,524.55- with commas and dot.

Pls let me know how to do this addition

Thanks

Saravana

4 REPLIES 4
Read only

Former Member
0 Likes
511

Hi

declare as type f or type p with decimals 2.

Regards

Navneet

Read only

Former Member
0 Likes
511

hi,

u can difine one local variable with data type p like this,

data: add type p decimal 2.

then u can move your additon field to this variable(add), now u can get the result with decimals,

to define comma and full stops is between,

go to T.code <b>su3</b>,

select defaults tab,

under the decimal notation u can define as u wish.

reward points if useful,

regards,

seshu.

Read only

Former Member
0 Likes
511

Hi,

Try with this code:

data: num1 type p decimals 2 value '297513.38',

num2 type p decimals 2 value '1258716037.93',

num3 type p decimals 2 value '1000000.00',

res type p decimals 2.

res = num1 + num2 + num3.

write: num1,

/ num2,

/ num3,

/ res.

Regards,

Bhaskar

Read only

Former Member
0 Likes
511

Hi,

try this

DATA: N1(20) VALUE '297,513.38'.

DATA: N2(20) VALUE '1258,716,037.93-'.

*

DATA: P1 TYPE F.

DATA: P2 TYPE F.

*

REPLACE ALL OCCURRENCES of '.' IN N1 WITH SPACE.

REPLACE ALL OCCURRENCES of ',' IN N1 WITH SPACE.

REPLACE ALL OCCURRENCES of '-' IN N1 WITH SPACE.

condense N2 NO-GAPS.

IF SY-SUBRC = 0.

P1 = N1 / 100 * ( -1 ).

ELSE.

P1 = N1 / 100.

ENDIF.

WRITE: / N1, P1.

REPLACE ALL OCCURRENCES of '.' IN N2 WITH SPACE.

REPLACE ALL OCCURRENCES of ',' IN N2 WITH SPACE.

REPLACE ALL OCCURRENCES of '-' IN N2 WITH SPACE.

IF SY-SUBRC = 0.

P2 = N2 / 100 * ( -1 ).

ELSE.

P2 = N2 / 100.

ENDIF.

WRITE: / N2, P2.

instead of type F you can use type P decimals 2 if you have lower value of N2.

Regards, Dieter