Content of a .4gl module

A module defines a set of program elements.

Syntax

The declaration order of elements defined in a program module must follow this syntax:
[ compiler-options
| package-statement
| import-statement [...]
| schema-statement
| globals-inclusion
]

[ constant-definition
| type-definition
| variable-definition
    [...] ]
]

[ MAIN-block ]

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

After the MAIN block, or when no MAIN block exists in the module, the constants, types, variables, dialog-blocks, functions, methods and report routines can be specified in any order.

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. The imported program elements can be used in the current module.

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.

Modules can be organized in packages.

Example

OPTIONS SHORT CIRCUIT 
IMPORT FGL cust_data
SCHEMA stores

PRIVATE CONSTANT c_title = "Customer data form"

MAIN
    ...
END MAIN

PUBLIC TYPE t_cust RECORD LIKE customer.*

PRIVATE DEFINE cust_rec t_cust

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

PRIVATE DEFINE cust_arr DYNAMIC ARRAY OF t_cust

FUNCTION do_cust_display_array()
    DISPLAY ARRAY cust_arr TO sr.* ...
        ...
    END DISPLAY
END FUNCTION

REPORT cust_report(row t_cust)
   ...
END REPORT