EXECUTE (statement execution structure)

Top  Previous  Next

 

EXECUTE expression

statement 1

statement 2

[ BEGIN

statements

END ]

statement n

[ ELSE ]

statement

END

EXECUTE

Initiates a single statement execution structure.

expression

A numeric expression or a variable that contains a numeric integer.

statement 1

A single statement that executes only when the expression is equal to 1.

statement 2

A single statement that executes only when the expression is equal to 2.

BEGIN

BEGIN marks the beginning of a structure containing a number of lines of code. The BEGIN structure will be treated as a single statement by the EXECUTE structure. The BEGIN structure is terminated by a period or the keyword END.

statement n

A single statement that executes only when the expression is equal to n.

ELSE

The statement following ELSE executes when the expression evaluates to a value outside the range of 1 to n, where n is defined as the total number of single statements between the EXECUTE and the ELSE.

statement

A single statement that executes only when the expression is outside the valid range.

An EXECUTE structure selects a single executable statement (or executable code structure) based on the value of the expression. The EXECUTE structure must terminate with an END statement (or period).

If the expression equals 1, the first statement (statement 1) executes. If expression equals 2, the second statement (statement 2) executes, and so on. If the value of the expression is zero, or greater than the total number of statements (or structures) within the EXECUTE structure, the statement in the ELSE clause executes. If no ELSE clause is present, program execution continues with the next statement following the EXECUTE structure.

EXECUTE structures may be nested within other executable structures and other executable code structures (IF, CASE, LOOP, EXECUTE, and BEGIN) may be nested within an EXECUTE. For those situations where the program's logic could allow using either an EXECUTE, CASE, or an IF/ELSIF structure, the EXECUTE structure will generate more efficient object code, and is the preferred method.

Example:

EXECUTE Transact    !Evaluate Transact

ADD(Customer)      !Execute if Transact = 1

PUT(Customer)      !Execute if Transact = 2

DELETE(Customer)   !Execute if Transact = 3

END                 !End execute

 

EXECUTE CHOICE()    !Evaluate CHOICE() procedure

OrderPart          !Execute if CHOICE() = 1

BEGIN              !Execute if CHOICE() = 2

 SavVendor" = Vendor

 UpdVendor

 IF Vendor <> SavVendor"

  Mem:Message = 'VENDOR NAME CHANGED'

 END

END

CASE VendorType    !Execute if CHOICE() = 3

OF 1

 UpdPartNo1

OF 2

 UpdPartNo2

END

RETURN             !Execute if CHOICE() = 4

END                 !End execute

 

EXECUTE SomeValue

DO OneRoutine

DO TwoRoutine

ELSE

MESSAGE('SomeValue did not contain a 1 or 2')

END

 

See Also:

BEGIN

CASE

IF