The $FDef function lets you access the attributes of a field from within a Model 204 procedure. $FDef maps the attributes of a field, whose values can then be read via an image similar to the ZFIELD image. Unlike $Dscr, which $FDef supplants, the attributes are displayed in a readable fashion without parsing.
$FDef works for files only (not for groups).
The format for the $FDef function is:
%image:item = $FDef([File] filename [At location], fieldname)
|%image:item||The image item to which $FDef returns the data.|
|filename||A %variable or a literal name of the file. A file synonym name can also be used.
If filename is the name of a group, the $FDef function assumes that the name passed is a file name, not a group name.
|location||The name of the remote node where the file is located.|
|fieldname||A %variable or a literal name of the field to be described.|
- An image is required by the $FDef and $LstFld functions. The ZFIELD image, which can give you complete field attribute information (see ZFIELD image details), is provided by the Model 204 installation software.
If you write your own image, be aware that $FDef maps to the locations of the image items, rather than the names.
- If the field specified in the $FDef argument is not defined in the opened file specified by filename, $FDef returns a
U(undefined) in the second ZFIELD image item (
DEFER.Y_N). If the file is not open, a
Uis returned in the
DEFER.Y_Nimage item, and an
Nis returned in the third image item (
FIELD.CODEimage item is unique for each field within a file. However, this value cannot remain constant for any one field over time, and it cannot be the same for the same field name in different files. Field names do not always hash to the same field codes because of deleted fields and hash collisions.
FIELD.CODEreturned in the ZFIELD image is the same as that which appears in CCAJRNL
RECTYPE=6entries. This information is valuable for Technical Support in case you need to run REGENERATE but cannot because you are missing one or more CCAJRNL data sets since your last DUMP of the file.
In the following example, you provide a field name and Model 204 displays output that indicates if the field is KEY or preallocated. If the field is preallocated, Model 204 also displays the number of occurrences and the length of the field.
This procedure maps the $FDef output to the ZFIELD image. Therefore, if the field is KEY, then the
KEY.Y_N image item contains a
PROCEDURE DISPFLD OPEN DAILY OPENC VEHICLES XXXX BEGIN %FIELD IS STRING LEN 50 %FIELD = $READ('ENTER FIELDNAME') * * * include the ZFIELD proc and prepare the ZFIELD image * * * INCLUDE ZFIELD PREPARE IMAGE ZFIELD * * * use the FDEF image item in ZFIELD to check the fieldname * * * %ZFIELD:FDEF = $FDEF('VEHICLES',%FIELD) IF %ZFIELD:KEY.Y_N = 'Y' THEN PRINT %FIELD ' IS KEY' ELSE PRINT %FIELD ' IS NOT A KEY FIELD' END IF IF %ZFIELD:OCCURS > '0' THEN PRINT %FIELD ' IS PREALLOCATED, WITH ' - %ZFIELD:OCCURS ' VALUES' PRINT 'THE LENGTH OF ' %FIELD ' IS ' %ZFIELD:LENGTH ELSE PRINT %FIELD ' IS NOT PREALLOCATED' END IF END
The following is the output produced by the procedure
DISPFLD for the field
INCLUDE DISPFLD ??ENTER FIELD NAME DEDUCTIBLE DEDUCTIBLE IS KEY DEDUCTIBLE IS PREALLOCATED WITH 1 VALUES THE LENGTH OF DEDUCTIBLE IS 3