Release 10.1A: OpenEdge Development:
Progress 4GL Reference

> ## BEGINS operator

> Tests a character expression to see if that expression begins with a second character expression.

> #### Syntax

>     expression1 BEGINS expression2

> ``expression1``

> An expression that has a CHARACTER or LONGCHAR value that you test to see if it begins with `expression2`.

> ``expression2``

> An expression that has a character value that you want to compare to the beginning of `expression1`. If you specify a null value ("") for `expression2,` Progress returns all the records in the database.

> Examples

> In this procedure, the user supplies a customer name or the first characters of a customer name. The procedure finds customer records where the name field begins with the user’s input. If the customer file is indexed on the name field, this procedure is very efficient and retrieves only the selected records.

> r-bgns.p
>     DEFINE VARIABLE cname LIKE customer.name LABEL "Name".

>     REPEAT:
>       SET cname WITH SIDE-LABELS.
>       FOR EACH customer WHERE name BEGINS cname:
>         DISPLAY name address city state postal-code.
>       END.
>     END.

> The next procedure lists exactly the same customers. However, it is much less efficient because it retrieves and examines all customer records, and only displays the ones with the appropriate names.

> r-bgns2.p
>     DEFINE VARIABLE cname LIKE customer.name LABEL "Name".

>     REPEAT:
>         SET cname WITH SIDE-LABELS.
>         /* create MATCHES pattern */
>         cname = cname + "*".
>         FOR EACH customer WHERE name MATCHES cname:
>             DISPLAY name address city state postal-code.
>         END.
>     END.

> #### Notes

> - The BEGINS operator is double-byte enabled. You can use the BEGINS operator to compare strings containing double-byte characters.

> - When you use the BEGINS operator to compare LONGCHAR fields, BEGINS always uses the `-cpcoll` collation.

> - BEGINS is useful in a WHERE phrase that specifies which records should be retrieved in a FOR EACH block. Unlike the MATCHES operator, which requires that all records in the file be scanned, BEGINS uses an index wherever possible.

> - Most character comparisons are case insensitive in Progress. By default, all characters are converted to uppercase prior to comparisons. However, you can define fields and variables as case sensitive (use if strict ANSI SQL adherence is required). If either of the character expressions passed to BEGINS is a field or variable defined as case sensitive, the comparison is case sensitive. In a case-sensitive comparison “SMITH” does not equal “Smith”.

> - Progress considers trailing blanks in the BEGINS operator. For example, this statement is FALSE:

>     "x" BEGINS "x      "

> This is different than comparisons, where trailing blanks are ignored. For example, this statement IS TRUE:

>     "x" = "x     "

> #### See also

> MATCHES operator

Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095