execute command

EXECUTE

Command:

EXECUTE

Syntax:

EXECUTE <code-component-1> <code-component-2> …

Description:

EXECUTE dynamically interprets a program statement contained inside

code-component literal(s) or variable(s), either elementary or group item. Literal keywords such as ACCENT are also permitted as arguments to EXECUTE.

EXECUTE is useful when some program logic component is undetermined prior to program execution. See the section titled Dynamic Statement Creation and Execution in Chapter 8 for practical examples of EXECUTE usage.

An unusual form of recursion is possible by using EXECUTE to call other EXECUTE statements, e.g.:

EXECUTE `EXECUTE statement_var`.

Although this type of recursion may be difficult to conceptualize and use for normal programming, it is supported. The maximum permitted number of nested recursive calls of this nature is 500; bypassing this limit will cause CobolScript to generate a normal error message specific to this recursion.

Moderate caution should be exercised when using EXECUTE to process user input; naturally, it is inadvisable to accept unauthorized user input in the form of a whole code statement for use as an EXECUTE argument; however, since one EXECUTE statement can only process a single code statement, allowing user input for portions of a statement may be appropriate, depending on your objective. The level of flexibility that you permit in user input is directly constrained by how much you wish to restrict user actions; this is therefore your decision to make.

Example Usage:

1 test_var PIC X(n) VALUE `Hello, `.

1 execute_group.

5 `DISPLAY`.

5 ` test_var`.

EXECUTE execute_group `&` ACCENT `world.` ACCENT.

Sample Program:

EXECUTE.CBL