Structure of a module

A module defines a set of program elements such as functions, report routines, types, constants and variables.

Syntax

The declaration order of elements defined in a program module is constrained. Define module elements in the following way:
[ compiler-options
| import-statement [...]
| schema-statement
| globals-inclusion
| constant-definition [...]
| type-definition [...]
| variable-definition [...]
]

[ MAIN-block ]

[ dialog-block
| function-block
| report-routine
    [...] ]
]
  1. compiler-options are described in OPTIONS (Compilation).
  2. import-statement imports an external module, see Importing modules.
  3. schema-statement defines a database schema for the compilation.
  4. globals-inclusion includes a globals file.
  5. constant-definition defines constants.
  6. type-definition defines user types.
  7. variable-definition defines variables.
  8. MAIN-block declares the main block of the program.
  9. dialog-block declares a declarative dialog.
  10. function-block declares a function.
  11. report-routine declares a report routine.

Usage

A module defines a set of program elements that can be used by other modules when defined as PUBLIC, or to be local to the current module when defined as PRIVATE. Program elements are user-defined types, variables, constants, functions, report routines, and declarative dialogs.

A module can import other modules with the IMPORT FGL instruction. A module can define functions, reports, module variables, constants and types, as well as declarative dialogs.

Program modules are written as .4gl source files and are compiled to .42m files. Compiled modules (.42m files) can be linked together to create a program. However, linking is supported for backward compatibility only. The preferred way is to define module dependencies with the IMPORT FGL instruction. For better code re-usability, module elements can be shared by each other by qualifying module variables, constants, types, and functions with PRIVATE or PUBLIC keywords. PUBLIC module elements can be referenced in other modules.

Example

OPTIONS SHORT CIRCUIT 
IMPORT FGL cust_data
SCHEMA stores

PRIVATE CONSTANT c_title = "Customer data form"
PUBLIC TYPE t_cust RECORD LIKE customer.*
PRIVATE DEFINE cust_arr DYNAMIC ARRAY OF t_cust

MAIN
    ...
END MAIN

DIALOG cust_dlg()
    INPUT BY NAME cust_rec.*
       ...
    END INPUT
END DIALOG

FUNCTION cust_display()
   ...
END FUNCTION

FUNCTION cust_input()
   ...
END FUNCTION

REPORT cust_rep(row)
   ...
END REPORT