Navigation: Templates > Template Language Reference > Complete Alpha Listing >====== #DECLARE (declare a user-defined symbol) ====== | |
#DECLARE( symbol [, type ] ) [, MULTI ] [, UNIQUE ] [, SAVE ]
#DECLARE( symbol [, parentsymbol] [, type ] ) [, MULTI ] [, UNIQUE ] [, SAVE ]
#DECLARE | Explicitly declares a user-defined symbol. |
symbol | The name of the symbol being declared. This must meet all the requirements of a user-defined symbol. This must not be a #PROMPT symbol or a variable in the same scope. |
parentsymbol | Specifies the parent of the symbol, indicating its value is dependent upon the current value in another symbol. This must be a multi-valued symbol. You may specify more than one parentsymbol if the symbol is dependent upon a set of symbols. This allows implicit multi-dimensional arrays. |
type | The data type of the symbol: LONG, REAL, or STRING. If omitted, the data type is STRING. |
MULTI | Specifies the symbol may contain multiple values. |
UNIQUE | Specifies a multi-valued symbol that cannot contain duplicate values. The values are stored in ascending order. This implicitly declares the symbol as multi-valued, the MULTI attribute is not required. |
SAVE | Specifies the value(s) in the symbol are saved between source generation sessions. A symbol with the SAVE attribute may only be declared in the #APPLICATION area. |
The #DECLARE statement explicitly declares a user-defined symbol. This may contain a single value or multiple values. All user-defined symbols must be explicitly declared with #DECLARE except those declared on #GROUP parameters, and #PROMPT or #EQUATE statements.
The MULTI attribute declares the symbol as multi-valued. This allows the #FIX, #FOR, #ADD, #DELETE, #SELECT, and #FREE statements to operate on the symbol.
The UNIQUE attribute ensures all instances of a multi-valued symbol to be unique and sorted in ascending sequence. When UNIQUE is specified, MULTI is not required. The #ADD statement builds the symbol values in sorted order and only allows a single instance of every value in the symbol when each entry is added.
If the #DECLARE statement contains one or more parentsymbol parameters, the user-defined symbol is dependent on the parentsymbols. This means a separate instance (or instances, if multi-valued) of the symbol is available for each instance of the parentsymbol. If there are no parentsymbol parameters, it is independent.
#DECLARE may be used to create dependent symbols. The parentsymbol must be a multi-valued symbol, whetherit is a built-in or user-defined symbol.
The SAVE attribute causes a symbol's value(s) to be saved at the end of source generation and restored when the #DECLARE statement is eXEcuted at the beginning of the next source generation session. A symbol with the SAVE attribute may only be declared in the #APPLICATION section.
Example:
#APPLICATION('Sample One')
#DECLARE(%UserSymbol),SAVE #!Value saved after generation
#! and restored for next generation
#DECLARE(%ModuleFile,%Module),UNIQUE,MULTI #!Level-1 dependent symbol
#DECLARE(%ModuleFilePut,%ModuleFile) #!Level-2 dependent symbol
#DECLARE(%ModuleFileDelete,%ModuleFile) #!Second Level-2 dependent symbol
#DECLARE(%FileList),MULTI #!Multivalued symbol
#DECLARE(%FieldListID,%FileList,LONG),UNIQUE
#DECLARE(%FieldList,%FieldListID)
#DECLARE(%FieldListType,%FieldListID)
#DECLARE(%Dest) #!implicitly STRING
#DECLARE(%Char, STRING) #!explicitly STRING
#DECLARE(%Idx,LONG) #!explicitly LONG
#DECLARE(%LnS,LONG) #!ditto