USING-ENDUSING

Conditionally execute a statement

WSupported on Windows
USupported on Unix
VSupported on OpenVMS
NSupported in Synergy .NET
USING control SELECT
([match_term[, ...]]),
  statement
  .
  .
  .
ENDUSING

control

An expression whose value determines which statement is executed. (a or n)

match_term

(optional) Defines one or more conditions, enclosed in parentheses, in which statement is executed. Match_term uses any combination of the following formats:

exp

A match expression. A match occurs if control is equal to exp.

exp_1 thru exp_2

Two expressions separated by the THRU keyword. A match occurs if match_term is equal to or greater than exp_1 and less than or equal to exp_2.

operator exp

An expression preceded by a relational operator. (See Operators for a list of operators.) Control is compared to exp by operator and evaluated for its truth value. If it’s true, a match occurs.

( )

Null term. If no match_terms are matched, the null term is matched. This condition must be listed last.

statement

One or more Synergy DBL procedure division statements that are executed if one or more of the match_term ­expressions are true.

The USING statement selects a single statement for execution from a set of statements based on the value of a specified expression. It is similar to the CASE statement, except that it provides more powerful structures. USING is most efficient when using an i or d control expression and all match_terms are compile-time literals.

Each match_term is evaluated from top to bottom and left to right. Once a match is found, no other conditions in the match_term list are evaluated.

Important

If you use “( )” , it must be the last match_term in the list; otherwise, a “Statement can never be executed” compiler error (NOTEXE) will occur.

Note

If you use alpha labels with string control variables (and don’t compile with -qnoargnopt), be aware that the comparisons are .EQ. and .NE., which will be compared for the length of the shortest field. If you would like to match against the exact label, you should use the USING statement with the label (.EQS.“ABC”). Synergy .NET acts as if -qnoargnopt is set.

.define TTCHN ,1
record
    code        ,a5
proc
    open(TTCHN, o, "tt:")
    display(TTCHN, "Enter code: ")
    reads(TTCHN, code, done)
    using code select
    ('0' thru '9'),
      xcall class1(code)
    ('A' thru 'Z'),
      xcall class2(code)
    ("99", '$'),
      xcall class3(code)
    (.gt.'z'),
      xcall ierror(code)
    (),
      xcall ferror(code)
    endusing
done,
    stop
end