# ViewDef

> Source: https://manual.pvxplus.com/views-system/views-definition-object/viewdef

**ViewDef** is a subordinate object used to define a basic view definition. It creates a group of **[CalcItem](https://manual.pvxplus.com/views-system/views-definition-object/calcitem)** objects to manage information concerning calculated items that have been defined for the view, as well as a group of **ViewItem** objects to manage information concerning items selected for the view. A **ViewDef** object corresponds to a record in the *pvxview.src* file.

For information on the *pvxview.src* file structure, see **[Views System File Structures](https://manual.pvxplus.com/views-system/views-system-file-structures/overview#src)**.

## ViewDef Properties

The following table lists the properties of the **ViewDef** subordinate object:

| **Property** | **Description** |
| --- | --- |
| **CloseLogic$** | Logic to be executed when a view is closed using the **'Close()** method. See **[Logic Procedures](https://manual.pvxplus.com/views-system/logic-procedures/overview)**. |
| **CloseLogicType$** | Same as for **InitLogicType$**. |
| **Description$** | Short description used to identify the view. |
| **Filter$** | Free-form data filter. |
| **InitLogic$** | Logic to be executed when a view is opened using the **'Open()** method. Reference based on **InitLogicType$**.  <br>  <br>If type C, **InitLogic$** contains *program;entrypoint*.  <br>  <br>If X, **InitLogic$** contains PxPlus statement(s) to be executed. String, 128 characters. See **[Logic Procedures](https://manual.pvxplus.com/views-system/logic-procedures/overview)**. |
| **InitLogicType$** | Single character string indicating logic type:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| C \| Call \|<br>\| X \| Execute \|<br>\| I or *null* \| Ignore ***(Default)*** \| |
| **InternalID$** | Internal identifier for the view. |
| **Key$** | Sort key for reading the primary data source. |
| **Locked** | Indicates that the view definition cannot be modified unless unlocked with password.<br>\|  \|  \|<br>\| --- \| --- \|<br>\| 1 \| Locked \|<br>\| 0 \| Not locked \| |
| **LogicObject$** | Object specified to supply logic references. See **[Logic Procedures](https://manual.pvxplus.com/views-system/logic-procedures/overview)**. |
| **LongDescription$** | Long description for storing notes about the view. |
| **Order$** | Element order:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| A \| Alphabetic \|<br>\| " " *null* \| Natural order ***(Default)*** \| |
| **OriginalDescription$** | ***(Internal Use Only)***<br>Original description of the view when loaded. |
| **Password$** | Encrypted password for locking view definition. |
| **PrimarySource** | **[DataSource](https://manual.pvxplus.com/views-system/views-definition-object/datasource)** object identifier for primary data source. |
| **UpdateStamp$** | Last update. |

## ViewDefMethods

The following table lists the methods of the **ViewDef** subordinate object:

| **Method** | **Description** |
| --- | --- |
| **AddCalcItem( )** | Add a new **CalcItem** object to the view.<br>*(AddCalcItem method was added in PxPlus 2021.)* |
| AddItem(*ItemPath$***)** | ***(Internal Use Only)***<br>Add a new **ViewItem** object to the view based on the item path. The sequence of the **ViewItem** objects will be adjusted automatically to ensure they are grouped by their linkage path. Use **[ViewCtl](https://manual.pvxplus.com/views-system/views-definition-object/viewctl)** equivalent. |
| **AdjustItemSequence( )** | Adjust the sequence of the **ViewItem** objects based on their linkage path. |
| **Clear( )** | Re-initialize the view definition and delete all **CalcItem** and **ViewItem** objects created by it. |
| **ClearCalcItems( )** | Delete all **CalcItem** objects belonging to the view.<br>*(ClearCalcItems method was added in PxPlus 2021.)* |
| **ClearItems( )** | Delete all **ViewItem** objects belonging to the view. |
| GetCalcItem(*ItemPath$* \| *Column$* \| *idx*) | Return the object identifier for the specified **CalcItem**. (No trailing "$" when specifying a column.)<br>*(GetCalcItem method was added in PxPlus 2021.)* |
| **GetCalcItemCount( )** | Return the number of **CalcItem** entries.<br>*(GetCalcItemCount method was added in PxPlus 2021.)* |
| GetCalcItemIndex(*ItemPath$* \| *Column$***)** | Return the specified **CalcItem** group index. (No trailing "$" when specifying a column.)<br>*(GetCalcItemIndex method was added in PxPlus 2021.)* |
| GetItem(*ItemPath$* **\|** *Column$* **\|** *idx*) | Return the object identifier for the specified **ViewItem**. (No trailing "$" when specifying a column.) |
| **GetItemCount( )** | Return the number of **ViewItem** entries. |
| GetItemIndex(*ItemPath$* **\|** *Column$***)** | Return the specified **ViewItem** group index. (No trailing "$" when specifying a column.) |
| LoadPassword(*Password$***)** | ***(Internal Use Only)***<br>Load an encrypted password. View must be unlocked with no current password. |
| RemoveCalcItem(*ItemPath$* \| *idx*) | Remove a calculated item from the view.<br>*(RemoveCalcItem method was added in PxPlus 2021.)* |
| RemoveItem(*ItemPath$* **\|** *idx*) | ***(Internal Use Only)***<br>Remove an item from the view. Use **ViewCtl** equivalent. |
| SetCondition(*ItmPath$***,** *Code*, *Case*\[, *v1$* *v8$***\])**  <br>SetCondition(*Column$***,** *Code*, *Case* **\[,** *v1$..v8$***\])** | Set a filter condition at the view item level.  <br>  <br>*ItmPath$/Column$* (No trailing "$"): Used to identify item.<br>\|  \|  \|  \|<br>\| --- \| --- \| --- \|<br>\| *Code -* Condition indicator code: \|  \|  \|<br>\| 1 \| Equal to \<Value1> \|  \|<br>\| 2 \| Not equal to \<Value1> \|  \|<br>\| 3 \| Less than \<Value1> \|  \|<br>\| 4 \| Greater than \<Value1> \|  \|<br>\| 5 \| Less than or equal to \<Value1> \|  \|<br>\| 6 \| Greater than or equal to \<Value1> \|  \|<br>\| 7 \| Between \<Value1> and \<Value2> inclusive \|  \|<br>\| 8 \| Between \<Value1> and \<Value2> exclusive \|  \|<br>\| 9 \| Any of \<Value1>,\<Value1>, …\<Value1> \|  \|<br>\| 10 \| None of \<Value1>,\<Value1>, …\<Value1> \|  \|<br>\| 11 \| Contains \<Value1> \|  \|<br>\| 12 \| Starts with \<Value1> \|  \|<br>\| *Case -* Case sensitivity indicator: \|  \|  \|<br>\| 0 \| Not case sensitive \|  \|<br>\| 1 \| Case sensitive \|  \|<br>*v1$...v8$* - Values to be used in comparison. Pass numeric values as string arguments.<br>Note:   <br>View item-level filters are analyzed at run time to optimize data retrieval by determining key ranges for reading records. |
| SetCloseLogic(*Type$,Logic$***)** | Set **CloseLogic$**. |
| SetDescription(*Description$***)** | ***(Internal Use Only)***<br>Set the description of the view. Use **ViewCtl** equivalent. |
| SetFilter(*Condition$***)** | ***(Internal Use Only)***<br>Set the filter to be applied at the view level.<br>\|  \|  \|<br>\| --- \| --- \|<br>\| *Condition$* \| A free-form PxPlus expression that can be evaluated as true (**1**) or false (**0**). Variables used in the condition must be the column names assigned to the view items. The condition may be a simple condition or a complex condition using **AND** and **OR** logical operators.  <br>  <br>***Example:***  <br>  <br>CustType$(2,1)="C" **OR** CustBalance>1000 \|<br>Note:   <br>View-level filters are not analyzed at run time to optimize data retrieval by determining key ranges for reading records. If the filter you are setting could be used for optimization purposes, see if you can set a similar condition at the view item level, using the SetCondition( ) method.<br>Use **ViewCtl** equivalent. |
| SetInitLogic(*SrcObjID, Type$, Logic$***)** | Set initialization logic for a **ViewDef** or **DataSource** object. |
| SetInitLogic(*Type$, Logic$***)** | Set **InitLogic$**. |
| SetInternalID(*InternalID$***)** | ***(Internal Use Only)***<br>Set the internal identifier for the view. |
| SetKey(*Key$***)** | Set the sort key for reading the primary data source.  <br>  <br>*Key$ -* Key number (0-based for primary key). |
| SetLogicObject(*ObjNm$***)** | Set **LogicObject$**. |
| SetLongDescription(*LongDescription$***)** | Set the long description for storing notes about the view. |
| SetOrder(*Order$***)** | Set the element order:<br>\|  \|  \|<br>\| --- \| --- \|<br>\| A \| Alphabetic \|<br>\| " " *null* \| Natural order ***(Default)*** \| |
| SetOriginalDescription$(*Description$***)** | ***(Internal Use Only)***<br>Set the original description when view is loaded. |
| SetPassword(*Password$***)** | Put a password on an unlocked view definition. Remove the password by passing a null password. |
| SetPrimarySource(*ObjID*) | ***(Internal Use Only)***<br>Set the object identifier of the primary **DataSource** object. |
| SetUpdateStamp(*Stamp$***)** | ***(Internal Use Only)***<br>Set the date/time stamp for the last update. |
| Unlock(*Password$***)** | Unlock a passworded view definition for update, but do not remove the password. |

*ItmPath$* - \[Link *ObjID* \[+ Link *ObjID* …\]\] + *DS_Item ObjID*

The path begins just below the primary data source, resulting in the path for items from the primary data source consisting of the *DS_ItemObjID* alone.
