Branching

In this section:

How to:

Reference:

The execution flow of a procedure is determined using the following commands:


Top of page

x
Syntax: How to Use the -GOTO Command for Unconditional Branching
-GOTO label 
  .
  .
  .
-label [TYPE text]

where:

label

Is a user-defined name of up to 12 characters. Do not use embedded blanks or the name of any other Dialogue Manager command except -QUIT or -EXIT. Do not use words that may be confused with functions or arithmetic or logical operations.

The label may precede or follow the -GOTO command in the procedure.

TYPE text

Optionally sends a message to a client application.


Top of page

x
Reference: Processing a -GOTO Command

Dialogue Manager processes a -GOTO as follows:



Example: Using the -GOTO Command for Unconditional Branching

The following example comments out all the SQL code using an unconditional branch rather than -* in front of every line.

-START TYPE PROCESSING BEGINS
-GOTO DONE
 SQL
 SELECT SUM(UNIT_SOLD),SUM(RETURNS)
 FROM SALES
 WHERE PROD_CODE BETWEEN '&CODE1' AND '&CODE2'
 AND PRODUCT = '&PRODUCT'
GROUP BY PROD_CODE,CITY
-RUN
-DONE

The next example illustrates two labels with TYPE messages appended:

   .
   .
   .
-PRODSALES TYPE TOTAL SALES BY PRODUCT
   .
   .
   .
-PRODRETURNS TYPE TOTAL RETURNS BY PRODUCT

Top of page

x
Syntax: How to Use the -IF...GOTO Command for Conditional Branching
-IF expression [THEN] GOTO label1[;] [ELSE GOTO label2[;]]
                                     [ELSE IF...[;]]

where:

label

Is a user-defined name of up to 12 characters. Do not use embedded blanks or the name of any other Dialogue Manager command except -QUIT or -EXIT. Do not use words that may be confused with functions or arithmetic or logical operations.

The label may precede or follow the -IF command in the procedure.

expression

Is a valid expression. Literals need not be enclosed in single quotation marks unless they contain embedded blanks or commas.

THEN

Is an optional keyword that increases readability of the command.

ELSE GOTO

Optionally passes control to label2 when the -IF test fails.

ELSE IF

Optionally specifies a compound -IF test. See Using Compound -IF Tests.

The command -IF must end with a semicolon (;) to signal that all logic has been specified. Continuation lines must begin with a hyphen (-) and lines must break between words. A space after the hyphen is not required, but adds to readability.



Example: Using the -IF...GOTO Command for Conditional Branching

In the following example, control passes to the label -PRODSALES if &OPTION is equal to S. Otherwise, control falls through to the label -PRODRETURNS, the line following the -IF test.

-IF &OPTION EQ 'S' GOTO PRODSALES;
-PRODRETURNS
     SQL
       .
       .
     END
-EXIT
-PRODSALES
     SQL
       .
       .
     END
-EXIT

The following command specifies both transfers explicitly:

-IF &OPTION EQ 'S' GOTO PRODSALES ELSE
- GOTO PRODRETURNS;

Notice that the continuation line begins with a hyphen (-).



Example: Using Compound -IF Tests

Use compound -IF tests provided each test specifies a target label.

In the following example, if the value of &OPTION is neither R nor S, the procedure terminates (GOTO QUIT). The -QUIT serves both as a target label for the GOTO and as an executable command.

-IF &OPTION EQ 'R' THEN GOTO PRODRETURNS ELSE IF
- &OPTION EQ 'S' THEN GOTO PRODSALES ELSE
- GOTO QUIT;
    .
    .
    .
-QUIT

Top of page

x
Reference: Operators and Functions in -IF Tests

Expressions in a -IF test include arithmetic and logical operators, as well as available functions. See Creating Expressions and Using Functions for details.


Top of page

x
Screening Values With -IF Tests

How to:

To ensure that a supplied value is valid in a procedure, test for its:

For instance, you would not want to perform a numerical computation on a variable for which alphanumeric data has been supplied.



x
Syntax: How to Test for the Presence of a Value
-IF &name.EXIST GOTO label...;

where:

&name

Is a user-supplied variable.

.EXIST

Indicates that you are testing for the presence of a value. If a value is not present, a zero (0) is passed to the expression. Otherwise, a non-zero value is passed.

GOTO label

Specifies a label to branch to.



Example: Testing for the Presence of a Variable

In the following example, if no value is supplied, &OPTION.EXIST is equal to zero and control is passed to the label -CANTRUN. The procedure sends a message to the client application and then exits. If a value is supplied, control passes to the label -PRODSALES.

-IF &OPTION.EXIST GOTO PRODSALES ELSE GOTO CANTRUN;
      .
      .
      .
-PRODSALES
    SQL
      .
      .
      .
    END
-EXIT
-CANTRUN
-TYPE TOTAL REPORT CAN'T BE RUN WITHOUT AN OPTION.
-EXIT


x
Syntax: How to Test for the Length of a Value
-IF &name.LENGTH expression GOTO label...;

where:

&name

Is a user-supplied variable.

.LENGTH

Indicates that you are testing for the length of a value. If a value is not present, a zero (0) is passed to the expression. Otherwise, the number of characters in the value is passed.

expression

Is the remainder of a valid expression, such as GT 8.

GOTO label

Specifies a label to branch to.



Example: Testing for Variable Length

In the following example, if the length of &OPTION is greater than one, control passes to the label -FORMAT, which informs the client application that only a single character is allowed.

-IF &OPTION.LENGTH GT 1 GOTO FORMAT ELSE
-GOTO PRODSALES;
      .
      .
      .
-PRODSALES
    SQL
      .
      .
      .
    END
-EXIT
-FORMAT
-TYPE ONLY A SINGLE CHARACTER IS ALLOWED.


Example: Storing the Length of a Variable for Later Use

The following example sets the variable &WORDLEN to the length of the string contained in the variable &WORD.

-PROMPT &WORD.ENTER WORD.
-SET &WORDLEN = &WORD.LENGTH;

You can use this technique when you want to use one variable to populate another.



x
Syntax: How to Test for the Type of a Value
-IF &name.TYPE expression GOTO label...;

where:

&name

Is a user-supplied variable.

.TYPE

Indicates that you are testing for the type of a value. The letter N (numeric) is passed to the expression if the value is interpreted as a number up to 109–1 and is stored in four bytes as a floating point format. In Dialogue Manager, the result of an arithmetic operation with numeric fields is truncated to an integer after the whole result of an expression is calculated. If the value could not be interpreted as numeric, the letter A (alphanumeric) is passed to the expression.

expression

Is the remainder of a valid expression, such as EQ A.

GOTO label

Specifies a label to branch to.



Example: Testing for Variable Type

In the following example, if &OPTION is not alphanumeric, control passes to the label -NOALPHA, which informs the client application that only alphanumeric characters are allowed.

-IF &OPTION.TYPE NE A GOTO NOALPHA ELSE
- GOTO PRODSALES;
      .
      .
      .
-PRODSALES
    SQL
      .
      .
      .
    END
-EXIT
-NOALPHA
-TYPE ENTER A LETTER ONLY.

iWay Software