Previous Topic: DELETE StatementNext Topic: EJECT Statement


DO Statement

The DO statement invokes another named procedure in the same program. Control is transferred to the named procedure and, when this procedure is completed, execution resumes with the statement that follows the DO statement in the invoking procedure.

This statement has the following format:

DO  {ERROR           }
    {procedure_name  }
   
ERROR

Invokes the error procedure and makes the $ERROR functions available. You can code this statement anywhere in the program procedure. You are responsible for resolving the error with a PROCESS NEXT or QUIT RUN statement.

Note: For more information about restrictions that apply to the error procedure, see the Error Procedure topic in this chapter.

procedure_name

The 1‑ to 15‑character name of the invoked procedure.

Example

This example illustrates how DO statements invoke named procedures from another procedure. Each of the named procedures, ADD_REC, DEL_REC, and OTHER_PROC, is invoked when the select condition that precedes it is true.

<<MAIN>> PROCEDURE
      LOOP
         TRANSMIT MAINPNL
      UNTIL TRANSCODE = 'T'
         SET MAINPNL.MSG = ' '
         SELECT TRANS‑CODE
         WHEN 'A'
           DO ADD_REC
         WHEN 'B'
           DO DEL_REC
         WHEN OTHER
           DO OTHER_PROC
         ENDSEL
      ENDLOOP
ENDPROC
<<ADD‑REC>> PROCEDURE
      TRANSMIT ADDPNL CLEAR
      FOR NEW EMPLOYEE
        SET EMPLOYEE = ADDPNL BY NAME
        SET MAINPNL.MSG = 'EMPLOYEE ADDED'
WHEN DUPLICATE
        SET MAINPNL.MSG = 'RECORD ALREADY ON FILE'
      ENDFOR
ENDPROC