Focal Point
How to check field contents to see whether numeric or not

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

July 21, 2004, 09:02 PM
<sandyhart>
How to check field contents to see whether numeric or not
Does anyone know if there is some way to check the contents of a field in MVS Focus to see whether the contents are numeric or not?
In COBOL, it would be IF FIELD IS NUMERIC, but I know of no way to accomplish this in Focus.
Can anyone help?
Thanks.
Sandy
July 21, 2004, 09:52 PM
reFOCUSing
I don't run MVS Focus but here is some code I use to check amper variables in DM.
-SET &TST1 = 'HI';
-SET &TST2 = 1;
-SET &VAL1 = IF &TST1.TYPE EQ 'A' THEN 'TEXT' ELSE 'NUM';
-SET &VAL2 = IF &TST2.TYPE EQ 'A' THEN 'TEXT' ELSE 'NUM';

The .TYPE is what knows if the value is text or numerical.

I hope this helps.
July 22, 2004, 04:47 PM
<sandyhart>
Curtis, thank you so much for your tip.
Please forgive my dumb questions, but I am beginner Focus programmer.

Will your code example work for a field that is more than one digit? For example, if a field were supposed to have a valid numeric date in it, could your example check to see if it was numeric or not?
Thank you again.
July 22, 2004, 06:48 PM
reFOCUSing
The size of the number does not matter as long as its all numerical. In this example &TST1 is a number and &TST2 is text.

What is the format of the date you are comparing?

-SET &TST1 = 20040721;
-SET &TST2 = '2004-07-21';
-SET &VAL1 = IF &TST1.TYPE EQ 'A' THEN 'TEXT' ELSE 'NUM';
-SET &VAL2 = IF &TST2.TYPE EQ 'A' THEN 'TEXT' ELSE 'NUM';
-TYPE &TST1 &VAL1
-TYPE &TST2 &VAL2
July 22, 2004, 10:07 PM
susannah
For a 'beginner', as you describe yourself, you ask really good questions.
If your incoming field is a date as you suggest, or is supposed to be a date,
if you convert it to a SmartDate (a focus term here), focus will brilliantly NOT transform anything that isn't a date.
For example, in my legacy databases I have a date field in alpha '20040231';
When i translate that to a SmartDate, it will translate as 0, because of course there IS NO 31st of February. This is a very handy thing, i can produce an exception report, for example, from my legacy db, to tell the data entry folks what they have to fix;
So if your question really is about dates, read the chapters in the manual about SmartDates and you'll be a happy camper. Otherwise check out Chapter 11 in the manual "using functions" ;
July 23, 2004, 04:51 AM
krishkasi
Hi,
Could you please tell me how can find the Usage type of a field in the table.
Because in my reports all the parameters will be passed as string.
Like as follows
-set &parm1 = 'where country_id eq ''12''';
Actually in my table the country id is a numeric field.so it is throwing error if I include the above parameter in the WHERE section.
Following is the error i am getting
"COMPARISON BETWEEN COMPUTATIONAL AND ALPHA VALUES IS NOT ALLOWED"
My table request looks as follows.

TABLE FILE COUNTRY
PRINT *
&PARM1
END

And the &Parm will be dynamic and it can be of any data type sometime i may use country_name as parm1.
Can anyone of you help me how to figure out columns usage type before comparing it.
July 26, 2004, 09:00 PM
TexasStingray
Check out the User-Written Subroutine Manual it has a subroutine called CHKFMT. I think that my be what you want.