EGL Reference Guide for iSeries

Program part in EGL source format

You declare a program part in an EGL file, which is described in EGL source format. When you write that file, do as follows:

The next example shows a called program part with two embedded functions, along with a stand-alone function and a stand-alone record part:

  Program myProgram type basicProgram (employeeNum INT)
  { 
    includeReferencedFunctions 
  }
 
    // program-global variables
      employees record_ws;
      employeeName char(20);
 
 
    // a required embedded function
    Function main() 
      // initialize employee names
      recd_init();
 
      // get the correct employee name
      // based on the employeeNum passed
      employeeName = getEmployeeName(employeeNum);
    end
 
    // another embedded function
    Function recd_init()
      employees.name[1] = "Employee 1";
      employees.name[2] = "Employee 2";
    end
  end
 
  // stand-alone function
  Function getEmployeeName(employeeNum INT) returns (CHAR(20))
 
    // local variable
    index BIN(4);
    index = 2;
    if (employeeNum > index)
      return("Error");
    else
      return(employees.name[employeeNum]);
    end
 
  end
 
  // record part that acts as a typeDef for employees
  Record record_ws type basicRecord
    10 name CHAR(20)[2];
  end

For other details, see the topic for a particular type of program.


Related concepts
Parts
Program part


Related reference


Basic program in EGL source format
EGL source format
Function part in EGL source format
Text UI program in EGL source format

Basic program in EGL source format

An example of a basic program is as follows:

program myCalledProgram type basicProgram
  (buttonPressed int, returnMessage char(25))
	
	function main()
    returnMessage = "";
    if (buttonPressed = 1)
      returnMessage = "Message1";
    end
 
	  if (buttonPressed = 2)
      returnMessage = "Message2";
    end
	end
end

The syntax diagram for a program part of type basicProgram is as follows:



Syntax diagram for a program part of type basicProgram

Program programPartName ... end
Identifies the part as a program part and specifies the name and type. If the program name is followed by a left parenthesis, the program is a called basic program.

If you do not set the alias property (as described later), the name of the generated program is either programPartName or, if you are generating COBOL, the first eight characters of programPartName.

For other rules, see Naming conventions.

mainBasicProperties
The properties for a main basic program are optional:

For details, see Program properties.

parameter
Specifies the name of a parameter, which may be a data item, record, or form; or a dynamic array of records or data items. For rules, see naming conventions.

If the caller's argument is a variable (not a constant or literal), any changes to the parameter change the area of memory available to the caller.

Each parameter is separated from the next by a comma. For other details, see Program parameters.

calledProperties
The called properties are optional:

For details, see Program properties.

programData
Variable and use declarations, as described in Program data other than parameters.
mainFunctionPart
A required function named main, which takes no parameters. (The only program code that can take parameters is the program itself and functions other than main.)

For details on writing a function, see Function part in EGL source format.

functionPart
An embedded function, which is private to this program. For details on writing a function, see Function part in EGL source format.


Related concepts
EGL projects, packages, and files
Overview of EGL properties and overrides
Parts
Program part
Syntax diagram


Related reference
EGL source format
Function part in EGL source format
Naming conventions
Program data other than parameters
Program parameters
Program part in EGL source format
Program part properties
Use declaration

Text UI program in EGL source format

The syntax diagram for a program part of type textUIProgram is as follows:



Syntax diagram for a program part of type textUIProgram

Program programPartName ... end
Identifies the part as a program part and specifies the name and type. If the program name is followed by a left parenthesis, the program is a called basic program.

If you do not set the alias property (as described later), the name of the generated program is either programPartName or, if you are generating COBOL, the first eight characters of programPartName.

For other rules, see Naming conventions.

mainTextUIProperties
The properties for a main text UI program are optional:

For details, see Program properties.

parameter
Specifies the name of a parameter, which may be a data item, record, or form; or a dynamic array of records or data items. For rules, see naming conventions.

If the caller's argument is a variable (not a constant or literal), any changes to the parameter change the area of memory available to the caller.

Each parameter is separated from the next by a comma. For other details, see Program parameters.

calledProperties
The called properties are optional:

For details, see Program properties.

programData
Variable and use declarations, as described in Program data other than parameters.
mainFunctionPart
A required function named main, which takes no parameters. (The only program code that can take parameters is the program itself and functions other than main.)

For details on writing a function, see Function part in EGL source format.

functionPart
An embedded function, which is not available to any logic part other than the program. For details on writing a function, see Function part in EGL source format.

An example of a Text UI program is as follows:

Program HelloWorld type textUIprogram
	{}
	use myFormgroup;
	myMessage char(25);
		
	function main()
		while (eventKey not pf3)
			myTextForm.msgField = "                 ";
		    myTextForm.msgField=myMessage;
		    converse myTextForm; 
		    if (eventKey is pf3)
				    exit program;
		    end
		    if (eventKey is pf1)
		   	    myMessage = "Hello Word";
		    end	 
		end								
	end
end


Related concepts
EGL projects, packages, and files
Overview of EGL properties and overrides
Parts
Program part
Segmentation in text applications
Syntax diagram


Related reference
EGL source format
Function part in EGL source format
Naming conventions
Program data other than parameters
Program parameters
Program part in EGL source format
Program part properties
Use declaration


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]