# Programs using more than one module

Program a general word for the “finished product” — a set of procedures which can be run. A program may consist of one module containing one or more procedures:

It may also consist of a number of modules containing various procedures:

A procedure in one module can call procedures in another module, provided this module has been loaded with the `LOADM` command. `LOADM` needs the filename of the module to load.

For example, if an OPL module `MAIN` has these two procedures:

        PROC main:
              LOADM "library"
              pthis:                 REM run pthis: in this module
              pother:                REM run pother: in "library"
              PRINT "Finished"
              PAUSE 40
              UNLOADM "library"
        ENDP

        PROC pthis:
              PRINT "Running pthis:"
              PRINT "in this module"
              PAUSE 40
        ENDP

and a module called `LIBRARY` has this one:

        PROC pother:
              PRINT "Running pother:"
              PRINT "in module called LIBRARY"
              PAUSE 40
        ENDP

then running `MAIN` would display `Running pthis:` and `in this module`; then display `Running pother:` and `in module called LIBRARY`; and then display `Finished`.

You would usually only need to load other modules when developing large OPL programs.

You can use `LOADM` up to seven times, to load up to seven modules.

If you want to load any further modules, you must first unload one of those currently loaded, by using `UNLOADM` with the filename. To keep your program tidy, you should `UNLOADM` a module as soon as you have finished using it.

If there is an error in the running program, you will only be positioned in the Program editor at the place where the error occurred if you were editing the module concerned (and you ran the program from there).

In spite of its name, `LOADM` does not "load" the whole of another module into memory. Instead, it just loads a block of data stored in the module which lists the names of the procedures which it contains. If such a procedure is then called, the procedure will be searched for, copied from file into memory and the procedure will then be run.

The modules are searched through in the order that they were loaded, with the module loaded last searched through last. You may make considerable improvements in speed if you as few modules as possible loaded at a time (so avoiding a long search for each procedure) and if you load the modules with the most commonly called procedures first.