variables

Define the variables for a ProcScript module or component.

Local variables in trigger, operation, or entry:

variables 
{ {DataTypeVariableName {,VariableName } }
{ { {public | partner} handleSignatureName {,SignatureName} VariableName}
{ xmlstream[DTD:DTDName] VariableName} 
endvariables
;Example
variables ; local variables
   string vName, vDesc
endvariables

Component variables in Declarations container of components:

variables
  { DataType VariableName {, VariableName } }
  { FormattedDataType { DisplayFormat | @LIB::ModeledDisplayFormat } VariableName {, VariableName } }
  { { public | partner} handle VariableName  {, VariableName } } 
endvariables
;Example
; Declarations container of component
variables 
  string vString
  numeric DIS(999P99) myNumber
endvariables

Parameters

Parameters
Parameter Description
DataType Uniface data type; one of: string | numeric | boolean | float | date | time | datetime | lineardate | lineartime | lineardatetime | raw | image | xmlstream |any
VariableName Name of the variable; maximum length of 32 characters, including letters (A-Z), digits (0-9), and underscores (_); the first character must be a letter.

A local variable cannot have the same name as a named parameter in the same module or operation.

FormattedDataType Uniface data type to which a display format can be applied; one of: string | numeric | boolean | float | date | time | datetime | lineardate | lineartime | lineardatetime
DisplayFormat Shorthand code for a display format that matches the FormattedDataType, in the format:

DIS(Format)

For example:

  • numeric DIS(999P99) MyNum
  • date DIS(dd-mm-yy) MyDate
  • time DIS(hh:nn.ss) MyTime
  • datetime DIS(dd-MMM-yyyy hh:nn:ss) MyDateTime
  • string DIS(Ms. ?????) FemaleName

For more information, see Display Formats.

ModeledDisplayFormat

Name of a modeled display format. For example:

date @LIB::DateFormat1 PurchaseDate

SignatureName Name of a component signature
DTDName

Note:  Specifying a DTD or XSD for xmlstream variables serves no purpose and is therefore deprecated. It is recommended that you use string variables instead.

DTD or Schema that defines the structure of XML stream variables; can be one of the following:

  • String that evaluates to the name of a DTD in the format LitDTDName{.LitModelName} where LitDTDName is a literal DTD name defined in the application model LitModelName
  • Component constant that evaluates to a literal DTD name during compilation.
  • Global or component variable that evaluates to a string that contains the name of a DTD.

Return Values

None

Use

Allowed in all component types.

Description

Variables must be declared after parameters. If a params block is present, the variables block must follow that; otherwise, it must be the first statement present in the module or container.

It is possible to specify multiple variables blocks per script module (for local variables) or Declarations container, as long as they follow each other (after a params block, if applicable). This can be useful when including variable blocks from IncludeScript libraries. For example, for component variables:

#include MYLIB:MYVARS   ; IncludeScript with variables block
variables
 string vString1
endvariables
variables
 date DIS(AAA-dd-MMM-yyyy) vDate
endvariables

Note:  It is not possible to declare an individual variable within the same module or component more than once.

The value of a local variable is set to NULL at the start of the ProcScript module.

Scope of Variables

The scope of variables depends on where they are declared.

A local variable exists only in the operation or module in which it is defined. It cannot be directly referenced from another operation or module in the component, nor from a local or global ProcScript called by the operation or module. If a local variable has the same name as a field in the component, then the local variable takes precedence over the field; to access the field, you must use the qualified field name.

For example, consider a component that contains a field named DATE in the entity PO. The operation TODAY has a local variable, DATE. To update the field DATE, the field must be referenced by its qualified name, including its entity:

operation TODAY
variables
   date DATE
endvariables
;assign the current date to local variable DATE
DATE = $date
;assign the current date to field DATE.PO
DATE.PO = DATE
...
end ; operation TODAY

Warnings and Errors

During compilation, Uniface generates warnings and errors in the following circumstances:

  • A field exists with the same name as a local variable (warning).
  • A variable is defined more than once in one variable block (error).
  • A component variable has been defined more than once. (error)

    For example, if an IncludeScript contains a component variable declaration, it is not possible to override that declaration in the component. For example, the following will result in an error.

    ;Declarations
    #include MYLIB:MYVARS   ; MYVARS block contains declaration for vString1
    variables
      string vString1 
    endvariables
  • A declared component variable is not used. (info message).
  • Variable type mismatches (info message); for example, vCounter is defined as a string, but is treated as a numeric (counter + 1):
    variables
      string vCounter
    endvariables
      counter = vCounter + 1  ; results in an info warning 
    
  • Component variables block is defined in a script container that is not the Declarations container. (warning)
  • The display format specified for a component variable is not correct. (error)
  • A display format is specified for a data type that does not support it. (error)
History

Version

Change

10.01.03

Added support for component variables.

Deprecated specification of DTD or XSD for xmlstream variables.

Related Topics