Focal Point
[SOLVED] Dialog Manager Variable Test for Numerics Using .TYPE

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

July 24, 2014, 09:58 AM
Ian Dalton
[SOLVED] Dialog Manager Variable Test for Numerics Using .TYPE
I pass an amount (dial. mgr. variable &SAMNT) into a fex via HTML (format on the final database is D15.2). I want to control the data entry so there must be no more than 2 dec. places and the number range is between
-99,999,999,999.99 and 999,999,999,999.99

On the HTML page I have restricted characters entered to just
0 1 2 3 4 5 6 7 8 9 - .
using Javascript.

Sadly the .TYPE test on Dial. Mgr. variable &SAMNT only allow numbers up to 10 to the power 9 - 1 ie. 999999999
This means that if they enter 123456789012.99 it fails the numeric test – if you see my code below you’ll get an idea of what I am trying to do.

Any suggestions ?

-SET &ECHO=ALL;
-SET &SAMNT=9999999999.99;
-SET &POS_DECPT = POSIT(&SAMNT, &SAMNT.LENGTH, '.', '1', 'I4');
-TYPE &SAMNT &SAMNT.TYPE &SAMNT.LENGTH &POS_DECPT
-*EXIT

-IF &SAMNT.TYPE NE 'N' THEN GOTO CONT3;
-IF &SAMNT OMITS '.' THEN GOTO CONT4;
-SET &POS_DECPT = POSIT(&SAMNT, &SAMNT.LENGTH, '.', '1', 'I8');
-SET &NOPLACES = &SAMNT.LENGTH - &POS_DECPT;
-IF &NOPLACES GT 2 THEN GOTO CONT3 ELSE GOTO CONT4;
-RUN
-CONT3
-TYPE You must enter a valid Amount with a maximum of 2 dec. places
-EXIT

-CONT4
-TYPE No. OK
-EXIT

This message has been edited. Last edited by: Ian Dalton,


_______________________
*** WebFOCUS 8.1.05M ***
July 24, 2014, 10:13 AM
David Briars
For clarification purposes, why not check for a valid number range on the client (with JavaScript)?

This message has been edited. Last edited by: David Briars,
July 24, 2014, 10:18 AM
Tom Flynn
&SAMNT will never be numeric with a decimal point in the data.
  
-SET &ECHO=ALL;
-SET &SAMNT= '9999999999.99';
-SET &POS_DECPT = POSIT(&SAMNT.EVAL, &SAMNT.LENGTH, '.', '1', 'I4');
-TYPE &SAMNT &SAMNT.TYPE &SAMNT.LENGTH &POS_DECPT
-*-EXIT

-*-IF &SAMNT.TYPE NE 'N' THEN GOTO CONT3;
-IF &SAMNT OMITS '.'   THEN GOTO CONT4;
-SET &POS_DECPT = POSIT(&SAMNT, &SAMNT.LENGTH, '.', '1', 'I8');
-SET &NOPLACES = &SAMNT.LENGTH - &POS_DECPT;
-TYPE &POS_DECPT
-TYPE &NOPLACES
-IF &NOPLACES GT 2 THEN GOTO CONT3 ELSE GOTO CONT4;
-RUN
-CONT3
-TYPE You must enter a valid Amount with a maximum of 2 dec. places
-EXIT

-CONT4
-TYPE No. OK
-EXIT


works fine when omitting .TYPE statement


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
July 24, 2014, 10:26 AM
Ian Dalton
Yes we could do David but this would mean changing loads of .html programs to keep our code etc. consistent across all applications which we don't want to do. We use WebFOCUS to do this.


_______________________
*** WebFOCUS 8.1.05M ***
July 24, 2014, 10:44 AM
Ian Dalton
Tom, I beg to differ.
If I code the following below, ie. a no. with a dec. point, it works for 999.99 but not for 9999999999.99
-SET &ECHO=ALL;
-SET &SAMNT=9999999.99;
-TYPE &SAMNT &SAMNT.TYPE &SAMNT.LENGTH

The reason we do the check is that the string coming across may be 999....99 or ---99.99
I can tighten up the input via Javascript as David mentioned, by using the IsNan function for example, but it would be good to be able to do this validation within WebFOCUS.


_______________________
*** WebFOCUS 8.1.05M ***
July 24, 2014, 11:26 AM
David Briars
Thanks for sharing the reason for the requirement to validate on the server side.

Here is something you might want to 'kick the tires' on...

-* Returns 'Y'.  
-*-SET &SAMNT='999999999999.99';
-*-SET &SAMNT='0';
-*-SET &SAMNT = '-99999999999.99';
-* Returns 'N'  
-SET &SAMNT='IAN';
-*
DEFINE FUNCTION ISANUM (INPUT/A15)
CHECK1/D15.2  = ATODBL(INPUT, '15', 'D15.2');
ISANUM/A1      = IF (INPUT EQ '0') THEN 'Y' ELSE   
                  IF ((CHECK1 GE -99999999999.99) AND 
                      (CHECK1 LE 999999999999.99) AND 
		    (CHECK1 NE 0)) THEN 'Y' ELSE 'N';
END
-RUN
-*
-SET &ISANUMBER_YN = ISANUM(&SAMNT);
-TYPE ISANUMBER_YN => &ISANUMBER_YN  


It has been a long time since I've had to validate numeric input on the server side, but this might be something to consider.

The idea to call a DEFINE FUNCTION from DM, came from a recent post from Alan B. :-)

This message has been edited. Last edited by: David Briars,
July 24, 2014, 11:36 AM
Ian Dalton
Many thanks David - works well and funnily enough Alan B did reply to me privately with the follwing which does what I need also.....
-* Alan B's solution......
DEFINE FUNCTION TEST(NUMBER/A20)
FUNC1/A32 = IF NUMBER CONTAINS '.' THEN
GETTOK(NUMBER, 20, -1, '.', 20, 'A20') ELSE ' ';
FUNC2/A32 = IF NUMBER CONTAINS '.' THEN
GETTOK(NUMBER, 20, 1, '.', 32, 'A20') ELSE NUMBER;
TEST/A1 = IF ARGLEN(20, FUNC1, 'I9') GT 2 THEN 'N' ELSE
IF (ATODBL(NUMBER, '20', 'D20.2') LT -99999999999.99 OR
ATODBL(NUMBER, '20', 'D20.2') GT 999999999999.99) THEN 'N' ELSE 'Y';

END
-RUN
-SET &ECHO=ALL;
-SET &SAMNT=9999999999999.99;
-SET &CERTO = TEST(&SAMNT);
-TYPE &SAMNT &SAMNT.TYPE &SAMNT.LENGTH &CERTO
-*EXIT

-IF &CERTO EQ 'N' THEN GOTO CONT3 ELSE GOTO CONT4;
-RUN
-CONT3
-TYPE You must enter a valid Settlement Amount with a maximum of 2 dec. places
-EXIT

-CONT4
-TYPE No. OK
-EXIT


_______________________
*** WebFOCUS 8.1.05M ***