Focal Point
[SOLVED] Amper variable addition

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4371022171

June 09, 2006, 12:37 AM
Nitu Jain
[SOLVED] Amper variable addition
Hi,

I am trying to get the sum of amper variables using below code -

-SET &ECHO = ALL;
-SET &A=' 5.10';
-SET &B=' 10.05';
-SET &P=0.00;

-SET &P = &A.EVAL + &B.EVAL;
-TYPE &P

But I am losing decimal part of it.

Regards,

This message has been edited. Last edited by: Kerry,


WF dev version - 7.6.x
June 09, 2006, 02:37 AM
Mikel
Amper variables formats only can be alphanumeric or integer.
After arithmetic operations in Dialogue Manager, the decimal part is truncated.
To avoid this truncation, We can convert the result to alphanumeric format using FTOA function.

Try the example:

-SET &A ='5.10' ;
-SET &B = '10.05' ;
-SET &P = FTOA(&A+&B, '(D15.2)', 'A20'); 
-TYPE P = &P

Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
June 09, 2006, 03:28 AM
Nitu Jain
Thanks Michel,

That worked for the code I had submitted. The problem is that if the result goes beyond 1000 it is not able as there is a comma that gets added to the result. for Example

-SET &A ='1000.10' ;
-SET &B = '10.05' ;
-SET &P = FTOA(&A+&B, '(D15.2)', 'A20');
-TYPE P = &P
-SET &Q = FTOA(&P+&B, '(D15.2)', 'A20');
-TYPE Q = &Q

In this P gets printed properly but for Q there is an error.

Any leads please....


WF dev version - 7.6.x
June 09, 2006, 06:06 AM
Mikel
That's right.
Change format to D15.2c ("c" is the display option to avoid the comma on output).

-SET &A ='1000.10' ;
-SET &B = '10.05' ;
-SET &P = FTOA(&A+&B, '(D15.2c)', 'A20');
-TYPE P = &P
-SET &Q = FTOA(&P+&B, '(D15.2c)', 'A20');
-TYPE Q = &Q

Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
June 09, 2006, 08:03 AM
Nitu Jain
Thanks Mikel.

It worked for me.

Regards,


WF dev version - 7.6.x
June 09, 2006, 08:19 AM
Nitu Jain
I was trying to print last value of Q again with comma (number display). But not able to do that. Any idea???

please try below code

-SET &A ='-10000.10' ;
-SET &B = '10.05' ;
-SET &P = FTOA(&A+&B, '(D15.2c)', 'A20');
-TYPE P = &P
-SET &Q = FTOA(&P+&B, '(D15.2c)', 'A20');
-TYPE Q = &Q

I want to get Q as (-)9,980.00

Thanks.


WF dev version - 7.6.x
June 09, 2006, 08:58 AM
Mikel
Again, remove the "c" only in the last step, when you need to display. Or you can add the following command:

-SET &Q = FTOA(&Q, '(D15.2)', 'A20') ;

Regards,
Mikel


WebFOCUS 8.1.05, 8.2.01
June 14, 2006, 11:15 PM
Nitu Jain
Thanks Mikel,
It worked ... Smiler)

Regards,
Nitu


WF dev version - 7.6.x
January 10, 2007, 08:49 AM
FrankDutch
Just what I was looking for....




Frank

prod: WF 7.6.10 platform Windows,
databases: msSQL2000, msSQL2005, RMS, Oracle, Sybase,IE7
test: WF 7.6.10 on the same platform and databases,IE7

May 18, 2009, 06:03 AM
Ian Dalton
Me too - works well.


_______________________
*** WebFOCUS 8.1.05M ***
May 18, 2009, 09:57 AM
GamP
It could be done with a little bit less code:
 
SET DMPRECISION = 2
-RUN
-SET &A=' 5.10';
-SET &B=' 10.05';
-SET &P = &A + &B;
-TYPE &P 



GamP

- Using AS 8.2.01 on Windows 10 - IE11.
in Focus since 1988
May 19, 2009, 04:53 AM
Ian Dalton
Many thanks for the tip using SET DMPRECISION=2

What I was really having trouble with was the following:-

-SET &C = &A + &B ;
(where &A = 2222222222 and &B = 3333333333)
The result &C should be displayed as 5555555555
but instead shows as ******** (8 asterisks)
therefore by doing :-
-SET &D = FTOA(&A+&B, '(D10c)', 'A10');
you get the addition displaying correctly

Cheers...


_______________________
*** WebFOCUS 8.1.05M ***
May 19, 2009, 05:13 AM
<JG>
Just as a point of interest SET DMPRECISION was a new feature in 7.6.1.
May 19, 2009, 11:31 AM
j.gross
Based on a little experimentation, it appears that -SET has two different modes of operation when right-hand-side involves numbers.

1. -SET &var = a string of digits;
treats the string of digits as a character expression.

2. -SET &var = an expression involving an arithmetic operator;
evaluates the expression, and then effectively formats it using FTOA(result, '(F8)', 'A8'), if DMprecision is zero. If FTOA senses overflow, then '********' is stored in &var. But if result of the expression was out of range (not sure what that range is), the value fed to FTOA is reset to zero.

Parentheses can be either numeric or character operators, depending on context, so they do not of themselves transform the RHS into a "numeric" expression.

-SET &Z=123456789012345678901234567890;

-SET &Z1=(&Z);
-SET &Z2=0+(&Z);
-SET &Z3=&Z * 0.000000000000000000001;
-SET &Z4=&Z * 0.0000000000000000000001;

-SET &Z1L=&Z1.LENGTH;
-SET &Z1T=&Z1.TYPE;

-SET &Z2L=&Z2.LENGTH;
-SET &Z2T=&Z2.TYPE;

-SET &Z3L=&Z3.LENGTH;
-SET &Z3T=&Z3.TYPE;

-SET &Z4L=&Z4.LENGTH;
-SET &Z4T=&Z4.TYPE;

-? &Z


result

 -SET &Z=123456789012345678901234567890;
 -SET &Z1=(123456789012345678901234567890);
 -SET &Z2=0+(123456789012345678901234567890);
 -SET &Z3=123456789012345678901234567890 * 0.000000000000000000001;
 -SET &Z4=123456789012345678901234567890 * 0.0000000000000000000001;
 -SET &Z1L=30;
 -SET &Z1T=A;
 -SET &Z2L=01;
 -SET &Z2T=N;
 -SET &Z3L=08;
 -SET &Z3T=A;
 -SET &Z4L=08;
 -SET &Z4T=N;
 CURRENTLY DEFINED & VARIABLES STARTING WITH 'Z':
 &Z            = 123456789012345678901234567890
 
 &Z1           = 123456789012345678901234567890  // character-value assigned
 &Z1L          = 30
 &Z1T          = A

 &Z2           = 0            // numeric value obtained, result reset to zero
 &Z2L          = 01
 &Z2T          = N

 &Z3           = ********     // numeric value obtained, result overflowed I8 format, *'s stoted, marked as Alpha
 &Z3L          = 08
 &Z3T          = A

 &Z4           = 12345678     // result marked as numeric
 &Z4L          = 08
 &Z4T          = N



- Jack Gross
WF through 8.1.05