‎2007 Jun 26 9:58 AM
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
‎2007 Jun 26 10:06 AM
‎2007 Jun 26 10:09 AM
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.
‎2007 Jun 26 10:38 AM
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
‎2007 Jun 26 10:45 AM
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