DTRHELP.HLB  —  Commands Statements Clauses, CHOICE Statement
       Causes DEC DATATRIEVE to execute one of a series of statements
       or compound statements, depending on the evaluation of a series
       of conditional (Boolean) expressions. The CHOICE statement is a
       convenient substitute for nested IF-THEN-ELSE statements.

       Format

         CHOICE  [OF]

              boolean-expression-1 [THEN] statement-1
              [boolean-expression-2 [THEN] statement-2]
                         .         .      .
                         .         .      .
                         .         .      .
              [ELSE statement-n]

         END_CHOICE

1  –  Arguments

    CHOICE

       Marks the beginning of a CHOICE statement.

    OF

       Is an optional language element you can use to clarify syntax.

    boolean-expression

       Is a Boolean expression.

    THEN

       Is an optional language element you can use to clarify syntax.

    statement

       Is a simple or compound statement you want DEC DATATRIEVE to
       execute if the corresponding Boolean expression evaluates to
       true.

    ELSE statement-n

       Specifies the statement you want DEC DATATRIEVE to execute if all
       the preceding Boolean expressions evaluate to false.

    END_CHOICE

       Marks the end of the CHOICE statement.

2  –  Examples

       The following example shows how to define a procedure MODIFY_
       YACHTS, prompt the user to identify a record by specifying the
       BUILDER and MODEL of a yacht, and print the record, prompting
       the user to modify a field from YACHTS. This process is continued
       until the user replies to a prompt that no further changes need
       to be made.

       DTR> SHOW MODIFY_YACHTS
       PROCEDURE MODIFY_YACHTS
       READY YACHTS WRITE
       FOR YACHTS WITH BUILDER = *."the builder" AND
             MODEL = *."the model"
       BEGIN
         PRINT
         PRINT SKIP
         PRINT "The fields you can modify are: RIG,LOA,DISP,BEAM,PRICE"
         MODIFY USING
         WHILE *."Y to modify a field, N to exit" CONT "Y"
           BEGIN
             DECLARE FLD PIC X(5).
             FLD = *."field to modify"
             CHOICE
                  FLD = "RIG" THEN RIG = *.RIG
                  FLD = "LOA" THEN LOA = *.LOA
                  FLD = "DISP" THEN DISP = *.DISP
                  FLD = "BEAM" THEN BEAM = *.BEAM
                  FLD = "PRICE" THEN PRICE = *.PRICE
                  ELSE PRINT "That's not a field in YACHTS."
             END_CHOICE
             PRINT
             PRINT SKIP
           END
         PRINT SKIP, "No more changes."
       END
       END_PROCEDURE

       DTR> :MODIFY_YACHTS
       Enter the builder: ALBIN
       Enter the model: 79

                                      LENGTH
                                       OVER
       MANUFACTURER   MODEL     RIG    ALL   WEIGHT BEAM  PRICE

        ALBIN       79         SLOOP   26     4,200  10  $17,900

       The fields you can modify are: RIG, LOA, DISP, BEAM, PRICE
       Enter Y to modify a field, N to exit: Y
       Enter field to modify: RIG
       Enter RIG: KETCH

                                      LENGTH
                                       OVER
       MANUFACTURER   MODEL     RIG    ALL   WEIGHT BEAM  PRICE

        ALBIN       79         KETCH   26     4,200  10  $17,900

       Enter Y to modify a field, N to exit: Y
       Enter field to modify: RUG
       That's not a field in YACHTS.
        ALBIN       79         KETCH   26     4,200  10  $17,900

       Enter Y to modify a field, N to exit: N

       No more changes.

       DTR>

       The following example shows how to print the TYPE and PRICE of
       the yachts by ALBERG and ALBIN, indicating whether the price
       is inexpensive, moderate, or expensive. Column headers are
       suppressed:

       DTR> READY YACHTS
       DTR> FOR YACHTS WITH BUILDER = "ALBERG" OR BUILDER = "ALBIN"
       CON> CHOICE
       CON> PRICE LT 20000 THEN PRINT TYPE(-),PRICE(-),"INEXPENSIVE"
       CON> PRICE LT 30000 THEN PRINT TYPE(-),PRICE(-),"MODERATE"
       CON> ELSE PRINT TYPE(-), PRICE(-), "EXPENSIVE"
       CON> END_CHOICE

       ALBERG     37 MK II   $36,951 EXPENSIVE
       ALBIN      79         $17,900 INEXPENSIVE
       ALBIN      BALLAD     $27,500 MODERATE
       ALBIN      VEGA       $18,600 INEXPENSIVE

       DTR>
Close Help