compare

Compare fields of two adjacent occurrences.

compare{/previous | /next}  (FieldList)  {from  Entity}

Example: compare/next (INVDATE) from "INVOICE"

Qualifiers

Qualifiers
Qualifier Description
/previous Compare the fields of the active occurrence with those of the previous occurrence.
/next Compares the fields in the active occurrence with those of the next occurrence. This is the default behavior of compare. However, it is recommended that you use the /next switch for clarity.
from Specifies an entity containing the fields to compare. If omitted, the active occurrence of the current entity (available in $entname) is used.

Parameters

Parameters
Parameter Data Type Description
FieldList String Comma-separated list of literal field names. The FieldList is of the form:
LitFieldName Literal Literal name of a field in the entity being compared. Do not enclose the name in double quotation marks (") or qualify the name with the entity and model name. If FieldList contains only one LitFieldName, the surrounding parentheses (()) are not required.
Entity String Name of an entity.

Return Values

The compare statement sets both $status and $result.

Values returned in $status
Value Description
-1 An error occurred. $procerror contains the exact error. In this situation, $result is always 0.
0 No error occurred. This can be returned even when there is no next or previous occurrence.
Values returned in $result
Value Meaning
1 Perfect match of all specified fields.
0 Fields do not match. (This value is also returned if $status is -1.)
-1 No previous or next occurrence.
Values commonly returned by $procerror following compare
Value Error constant Meaning
-2 through -12 <UIOSERR_*> Errors during database I/O.
-16 through -30 <UNETERR_*> Errors during network I/O.
-1101 <UPROCERR_FIELD> An incorrect field name was provided; either the field name is not valid syntactically or the field is not available in the component.

Use

Allowed in all component types.

Description

The compare statement compares the contents of fields listed in FieldList with the corresponding fields in the next or previous occurrence. The compare statement first formats the data in the listed fields before comparing them. This allows the assignment to be done in ProcScript without a compare error occurring.

Using compare

The following example shows the use of the compare statement:

trigger leavePrinted 
  compare/next (INVDATE) from "INVOICE"
  if ($result <= 0)
     printbreak "SUBTOTAL"
     if ($result = 0)
        eject
        printbreak "TITLE"
     endif
  endif
ends; leavePrinted

Related Topics