Official Content

Compares two values using the indicated relational operator ('=', '>', '>=', '<', '<=', '<>', 'like') which can be dynamic (for example, entered by the end user at runtime).

Syntax

Compare(<value1>,<operator>,<value2>)

Where:

<value1>
    Is an attribute, variable, or fixed value.

<operator>
    Is a specific value of the predefined CompareKind Enumerated Domain.

<value2>
    Is an attribute, variable or fixed value.

Type returned:
Boolean

Scope

Objects: ProcedureTransactionWeb PanelPanelData Provider
Generators: .NET, .NET Framework, Java, Apple, AndroidAngular

Description

To compare two values using the operator entered by the end user at runtime, you may define filters (for example, Conditions) as follows:

Compare(&value1,&operator &value2);   //&operator is a variable based on the CompareKind Enumerated domain. It's included in the screen and entered by the end user.

CompareKind is a predefined Enumerated Domain, whose Enum Values are:

CompareKind
{
    .Equal - '='
    .Greater - '>'
    .GreaterOrEqual -'>=' 
    .Less - '<'
    .LessOrEqual - '<='
    .NotEqual -'<>'
    .Like -'like'
}

Context of use

You can use the function anywhere an expression is supported.

Runtime features

  • If the operator value entered by the end user at runtime is not valid, the value used is =.
  • Performing this construction at runtime is the same as writing the operator to send the SQL statements to the DBMS.
  • The like operator only makes sense for Character types and their variants. If you use it for other data types, it may give an execution error depending on whether the DBMS / version supports it or not.

Samples

Consider the following Transaction object:

Product
{
   ProductId*
   ProductName
   ProductPrice
}

Also, consider the 'ProducList' Web Panel object whose Web Layout, Variables, and Conditions are shown below:

Web Layout

CompareFunctionGX18_WebPanel_WebLayout

Variables

&ProductId - Data type based on Attribute: ProductId
&ProductName - Data type based on Attribute: ProductName
&ProductPrice - Data type based on Attribute: ProductPrice
&Op1 - Data type CompareKind, GeneXus
&Op2 - Data type CompareKind, GeneXus
&Op3 - Data type CompareKind, GeneXus

Conditions

Compare(ProductId, &Op1, &ProductId)
when not &ProductId.IsEmpty();

Compare(ProductName, &Op2, &ProductName)
when not &ProductName.IsEmpty();

Compare(ProductPrice, &Op3, &ProductPrice)
when not &ProductPrice.IsEmpty();

At runtime, when executing the 'ProducList' Web Panel object, the end user can select a predefined operator value for &Op1, &Op2, and/or &Op3.

image_2024912162337_1_png

For example, if the end user selects Greater for the &op3 variable and enters 9 for the &ProductPrice variable, only products with a price greater than 9 will be displayed in the Grid:

image_20249120426_1_png

See Also

Operators

  

Last update: March 2025 | © GeneXus. All rights reserved. GeneXus Powered by Globant