Introduction to Program parts

A program part is a main logic part with one entry point. A program part defines the central logic in a runtime program.

Each Program part contains a main() function, which represents the logic that runs at program start up. A program can include other functions and can access functions that are outside of the program. The function main() can invoke those other functions. Any function can give control to other programs.

Program parts use stereotypes to specialize code for user interfaces. The BasicProgram is the only stereotype that is part of the core EGL package. A BasicProgram can access databases or files, perform calculations, and use most EGL statements. Some UI technologies offer additional stereotypes.

Many properties are available at the program level that affect code behavior. The properties that are available depend on UI and data access technologies.

Main versus called programs

Main programs are programs that are defined without parameters. Main programs run when they are started by system command or a transfer from another main program. Called programs are programs that are defined with parameters. You invoke called programs from other programs via the call statement. Called programs handle parameters at the program level. Called programs must have a main() function with no parameters. The following example shows a called program:
  Program custProcessing1 type basicProgram (customerNum INT)
  
    // required main() function
    function main()
      // get the correct customer name
      // based on the customer number passed
      customerName = getCustName(customerNum);
      ...
    end

    // another function
    Function getCustName(customerNum INT) returns (CHAR(25))
      ...
    end

  end
The form of the program declaration determines whether the program is main or called. If the declaration includes parameters (or even empty parentheses), it declares a called program. To change a called program to a main program, remove the parameter list, including the parentheses. For example, the following lines declare called programs:
program custProcessing1 type basicProgram (customerNum INT)
program custProcessing1 type basicProgram ()
The following code declares a main program:
program custProcessing1 type basicProgram
The length of the argument that you use when you call a program must match the length of the equivalent parameter in the program declaration. Consider the following example:
customerName CHAR(30)
...
call custProcessing1(customerName);
Assume the following declaration for the called program:
program custProcessing1 type basicProgram (custName CHAR(80) inout)

Because EGL passes a pointer to the customerName variable, the custName variable has an actual length of only 30 characters. If you write to positions 31 - 80 of the custName variable, which is legal in the program, you might overwrite random memory. Note that the EGL debugger gives you a warning when such undefined behavior is about to occur.

For more information about called programs, see Transfer of control across programs.


Feedback