PERFORM

In this section:

How to:

Reference:

You can use the PERFORM command to pass control to a Maintain Data function. Once that function is executed, control returns to the command immediately following the PERFORM.

Syntax: How to Use the PERFORM Command

The syntax of the PERFORM command is

PERFORM functionname [()] [;]

where:

functionname

Specifies the name of the function to perform.

()

Is optional. If you omit the word PERFORM and only use the function name, parentheses are required.

;

Terminates the command. Although the semicolon is optional, it is recommended that you include it to allow for flexible syntax and better processing. For more information about the benefits of including the semicolon, see Terminating a Command's Syntax.

For example, to perform the function named NextSet, issue the command:

PERFORM NextSet;

Reference: Commands Related to PERFORM

  • CASE/ENDCASE. Defines a Maintain Data function.
  • GOTO. Transfers control to another function or to the end of the current function.

Using PERFORM to Call Maintain Data Functions

When you call a function as a separate statement (that is, outside of a larger expression), if the preceding command can take an optional semicolon (;) terminator but was coded without one, you must call the function in a COMPUTE or PERFORM command. You can use PERFORM for Maintain Data functions only, though not for Maintain Data functions that return a value.

For example, in the following source code, the NEXT command does not end with a semicolon (;), so the function that follows it must be called in a PERFORM command:

NEXT CustID INTO CustStack
PERFORM VerifyCustID();

However, in all other situations, you can call functions directly, without a PERFORM command. For example, in the following source code, the NEXT command ends with a semicolon (;), so the function that follows it can be called without a PERFORM command:

NEXT CustID INTO CustStack;
VerifyCustID();

Note: When calling a function without using a PERFORM command, you must include parentheses.

For more information about terminating commands with a semicolon (;), see Terminating a Command's Syntax.

Using PERFORM With Data Source Commands

A PERFORM can be executed in a MATCH command following an ON MATCH or ON NOMATCH command, or in NEXT following ON NEXT or ON NONEXT. In the following example, the function NotHere is performed after a NOMATCH condition occurs:

ON NOMATCH PERFORM NotHere;

Nesting PERFORM Commands

PERFORM commands can branch to functions containing other PERFORM commands. As each ENDCASE command is encountered, control returns to the command after the most recently executed PERFORM command. In this manner, control eventually returns to the original PERFORM.

Avoiding GOTO With PERFORM

It is recommended that you do not include a GOTO command within the scope of a PERFORM command. See GOTO for information on the incompatibility of the PERFORM and GOTO commands.