Previous Topic: IF StatementNext Topic: INVERT Statement


INITIATE Statement

The INITIATE statement runs a CA Ideal program asynchronously online.

This statement has the following format:

INITIATE pgm‑name [USING INPUT parm]
pgm‑name

The name of the CA Ideal program to execute as an asynchronous task. The specified program must be a valid resource of the program that contains this statement and must not contain a TRANSMIT statement. A non‑ideal subprogram cannot be invoked by INITIATE, although it can be CALLed by the CA Ideal program that was INITIATEd.

parm

The name of a field that contains data or a literal to pass as an input‑only parameter to the program specified as pgm‑name. Only one parameter can be passed to pgm‑name and that parameter cannot be a group field.

The asynchronous task uses the same selected system as the current run. Therefore, the initiated program must be in the same system as the main program executed by the RUN command. When the asynchronous subprogram completes, a message is sent to the initiating session indicating that the asynchronous task completed. You can use the SET ASYNCMSG command to suppress this message.

Example

The following code is part of an inventory update procedure. On the INCOMING panel where the user enters the data on the incoming shipments of stocked items (some of which were backordered), the PF5 key is defined to print a report of all outstanding orders for a back‑ordered product. With the INITIATE statement, you can produce this report as an asynchronous task so you can proceed to other tasks online.

<<PROCESS‑INCOMING>> PROCEDURE
   TRANSMIT INCOMING
   SELECT FIRST ACTION
      WHEN $PF3
         QUIT PROCEDURE
      WHEN $PF5
         DO UPDATE‑ITEM
         INITIATE PRTORDER USING INPUT INCOMING.ITEM‑ID
      WHEN $ENTER‑KEY
         DO UPDATE‑ITEM
      WHEN NONE
         DO ERROR
   ENDSEL
ENDPROC

The PRTORDER program uses the ITEM‑ID entered with the other inventory data on the panel INCOMING to find the orders that included that item.