The MAIN block

The MAIN block is the starting point of the program.

Syntax

MAIN
    [ define-statement
    | constant-statement
    | type-statement
    ]
    { [defer-statement]
    | fgl-statement
    | sql-statement
    }
    [...]
END MAIN
  1. define-statement defines function arguments and local variables.
  2. constant-statement can be used to declare local constants.
  3. type-statement can be used to declare local user defined type.
  4. defer-statement defines how to handle signals in the program.
  5. fgl-statement is any instruction supported by the language.
  6. sql-statement is any static SQL instruction supported by the language.

Usage

When the runtime system executes a program, after some initialization, it gives control to the MAIN program block.

The MAIN block typically consists of a set of interruption handling instructions, runtime configuration options, database connection and a call to the main function of the program.

IMPORT cust_module

MAIN
    DEFINE uname, upswd STRING

    DEFER INTERRUPT
    DEFER QUIT

    OPTIONS FIELD ORDER FORM,
            INPUT WRAP,
            HELP FILE "myhelp"

    CALL get_login() RETURNING uname, upswd
    WHENEVER ERROR CONTINUE
    CONNECT TO "stores" USER uname USING upswd
    WHENEVER ERROR STOP
    IF SQLCA.SQLCODE < 0 THEN
       DISPLAY "Error: Could not connect to database."
       EXIT PROGRAM 1
    END IF

    CALL cust_module.customer_input()

END MAIN