In this section: How to:
Reference: |
The execution flow of a procedure is determined using the following commands:
-GOTO label . . . -label [TYPE text]
where:
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.
Optionally sends a message to a client application.
Dialogue Manager processes a -GOTO as follows:
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
-IF expression [THEN] GOTO label1[;] [ELSE GOTO label2[;]] [ELSE IF...[;]]
where:
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.
Is a valid expression. Literals need not be enclosed in single quotation marks unless they contain embedded blanks or commas.
Is an optional keyword that increases readability of the command.
Optionally passes control to label2 when the -IF test fails.
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.
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 (-).
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
Expressions in a -IF test include arithmetic and logical operators, as well as available functions. See Creating Expressions and Using Functions for details.
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.
-IF &name.EXIST GOTO label...;
where:
Is a user-supplied variable.
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.
Specifies a label to branch to.
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
-IF &name.LENGTH expression GOTO label...;
where:
Is a user-supplied variable.
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.
Is the remainder of a valid expression, such as GT 8.
Specifies a label to branch to.
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.
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.
-IF &name.TYPE expression GOTO label...;
where:
Is a user-supplied variable.
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.
Is the remainder of a valid expression, such as EQ A.
Specifies a label to branch to.
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 |