Can I check the format of a field from within a DEFINE?
I wish to determine if a field is integer, decimal or alpha-numeric. Is there a function to do this?
Web FOCUS 7.6.11
May 15, 2006, 01:22 PM
susannah
I'm guessing that the field exists in a file and you don't have access to the master? or is this a DM field? If DM, then use the .TYPE suffix and test if &MYVAR.TYPE is 'A' or 'N', for starters. If this field is in a master and you just don't know about it, then in your fex, CHECK FILE mastername HOLD TABLE FILE HOLD PRINT FIELDNAME FORMAT if you do this on the car file , you'll get
PAGE 1
FIELDNAME FORMAT
COUNTRY A10
CAR A16
MODEL A24
BODYTYPE A12
SEATS I3
DEALER_COST D7
RETAIL_COST D7
SALES I6
LENGTH D5
WIDTH D5
HEIGHT D5
WEIGHT D6
WHEELBASE D6.1
FUEL_CAP D6.1
BHP D6
RPM I5
MPG D6
ACCEL D6
WARRANTY A40
STANDARD A40
In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
May 15, 2006, 04:04 PM
<JG>
You can not have a field in a define that you do not know the format of. WebFocus does not allow that.
You can have a field that contains a value that is of a different format. Or you can have a variable that you may not know the format of that you are trying to assign to a defined field (only an issue for numbers as if you are assigning it to an alpha you just wrap it in quotes).
Alpha is the only format that can legitimately contain ABC 123 -123 1.23 -1.23 1,200.3 or 1.2.3
As Susannah says using .TYPE as a suffix for DM variables can help but it has the limitation that it only identifies numerics if they only contain numbers a decimal point or a - sign i.e. 1234 1.234 -1.234 etc are returned as type N, 1,234 or 1,234.00 are returned as being type A. (not really that smart).
Your only real option is to write some extended IF-THEN-ELSE logic to handle it.
May 15, 2006, 10:17 PM
TexasStingray
There may be a couple of way to check the format of a field and have a dynamic field format in DEFINE FILE xxxx. This is How I am doing it in one of my programs.
DEFINE FILE SYSCOLUM
TYPE/A4 = EDIT(COLTYPE, '9999$');
END
TABLE FILE SYSCOLUM
PRINT
NAME
TYPE
LENGTH
WHERE TBNAME EQ '&1';
WHERE NAME EQ '&2';
ON TABLE HOLD AS COLINFO FORMAT ALPHA
END
? HOLD COLINFO
-RUN
-SET &LINE = '';
-READ COLINFO CLOSE &FLDNAME.A66. &FLDTYPE.A4. &FLDLENG.A4.
-SET &FLDNAME = TRIMV('B', '&FLDNAME.EVAL', &FLDNAME.LENGTH, ' ', 1, 'A66V');
-SET &FLDLENG = TRIMV('B', '&FLDLENG.EVAL', &FLDLENG.LENGTH, ' ', 1, 'A4V');
-SET &AFORMAT = 'A' | &FLDLENG;
-RUN
DEFINE FILE xxx
DYNFLDFMT/&AFORMAT = your code here;
I do have seperate defines one for VARC(VARCHAR) AND CHAR and Another one for everything else.
Check &FLDTYPE for the field type, It only have the first 4 characters for the TYPE.
Hope this helpsThis message has been edited. Last edited by: TexasStingray,