{INCLUDE _LOGOS_C.HTM}

Introduction to mv/WEB

Part 3 - Subroutines and Common

Now that you can write simple multi-page web applications, you need a structure to build larger applications. mv/WEB gives you two powerful tools to help you build large modular applications:

Using External Subroutines

External web subroutines are good programming practice because they allow you to better manage large applications. With external subroutines, you can independently develop re-usable modules that can be called from many different applications. External subroutine usage also lower the size of individual application modules allowing them to compile faster and not exceed underlying run-time limits.

You define a subroutine in the same manner as you define a program using _SUBROUTINE instead of _PROGRAM on line 1 of the source code item. You can also define a list of parameters that will be passed to and from the subroutine.

_SUBROUTINE APP.FILE SUB1 PARM1,PARM2
...
_RETURN

The subroutine is called from the main-line program (or another subroutine) with the _CALL statement. You would call this subroutine with:

...
_CALL "SUB1" X1,X2
...

The subroutine name is enclosed in quotes allowing you to also specify subroutine names in variables.

In order to call subroutines, both the called subroutine and calling programs must be generated into the same MV data file.

It is not possible to access an mv/WEB subroutine directly from the Coyote web server without running a main-line mv/WEB program.

Declaring Common

Subroutines allow you to pass parameters. You can also declare persistent variables that are accessible by both the main-line program and by subroutines:

_PROGRAM APP.FILE APP2
_CVAR ID
_CVAR D
...

Most programmers prefer to include common variable definitions in included items so that all subroutine will use the same common variables without having to worry about updating multiple files. mv/WEB provides an include syntax to help with this:

_PROGRAM APP.FILE APP2
_INCLUDE FILE BP MASTER.INCLUDE
...

{INCLUDE _GEN_FTR.HTM}