DEFVIEW


General Forms:

1.
  • [LOCAL] DEFVIEW viewname OF [RECORD] recordname
  •    FLD fldname
  •    ...
  • END VIEW
2.
  • [LOCAL] DEFVIEW viewname EXTENDS VIEW baseviewname
  •    FLD fldname
  •    ...
  • END VIEW
Where:

DEFVIEW can be used to specify a subset of fields in a pre-existing DEFRECORD or another DEFVIEW. This can simplify database programming by exposing only the fields that a particular program needs to see while using the same field definitions and row buffers. In particular it can confer performance advantages with SQL databases.

The view has the same size and value as the original record so row buffers declared for the view are the same size of the row buffers of the original record. Enumeration, and find functions are also available. There is no initialization function for a view as this requires knowledge of all the fields of the original record. To initialize a buffer declared as a view, the initialization function of the original record must be used.

The FLD field names referenced inside the view definition must exist in the record on which the view is based. They cannot be redefined. Ordering does not matter. Fields with an occurs clause in the original record do not need any parentheses to distinguish them in the view.

In the first form, based on a record and using the OF RECORD keyword, the listed fields are the only fields to be included in the view but in the second form, based on another view and using the EXTENDS keyword, the listed fields are added to the fields of the defining view.

DEFVIEW does not take PUBLIC or PRIVATE attributes and may be considered PUBLIC in all cases. The original record on which it is based must also be PUBLIC. The view may be defined in a different library context from the original record however when views of views are used, at most two contexts can be involved.

Views can be used in most places the original record is used. The kc compiler will check that when FLD() is used with a view then only the fields defined in the view are allowed. Also when a DEFSUB has a view structure as an argument, only another instance of that view or its base record can be passed on a call and you cannot pass a view to a DEFSUB argument that expects the original record. Exceptionally it is allowed to pass a view buffer to the base record initialization function.

Example

// full details of the employee
DEFRECORD employee
	FLD empno = "UINT(4)"		// clock number
	FLD ename$ = "CHAR(30)"		// employee name
	FLD esalary = "UNUM(7,2)"		// monthly salary
	FLD elist$(10)_ELIST	// attributes
END RECORD
// view used in programs other than payroll
DEFVIEW employee_view OF RECORD employee
	FLD empno
	FLD ename$
	FLD elist$
END VIEW
DIM ebuf$_employee_view

Compatibility

DEFVIEW was introduced in KCML 6.60.

See also:

DEFRECORD, DEFLINKEDVIEW, DEFDATABASEROW, LIST R, FLD