21. 4GL Statement Glossary : Callproc : Coding 4GL Procedures
 
Share this page                  
Coding 4GL Procedures
Use the procedure statement when coding a 4GL procedure in a source-code file.
procedure identifier [( [ variable =typedeclaration
  {,  variable = typedeclaration} ] ) ]=
[ declare variable = typedeclaration
  {, variable = typedeclaration} ]
[begin | {
    statement; {statement;}
end | }]
The variables listed in parentheses after the procedure name (identifier) are keyword parameters; you can place values in them when the procedure is called by another frame or procedure. The 4GL procedure statement recognizes record types in variable declarations.
You can also declare local variables. To do this, use the keyword declare following the procedure header. Variables defined in this declare section cannot have values passed to them through the call parameter lists either positionally or by keyword. Their scope is local; limited to the procedure in which they are defined.
All form fields and table field columns are accessible as keyword parameters for 4GL frames and procedures. To declare a data type, use this syntax:
simpletype [(length[,scale])] [with|not null];
recordtype;
array of recordtype;
array of type of table tablename;
array of type of form formname;
array of type of tablefield form.tablefield;
Any parameter in the 4GL procedure that is not passed a value receives a default value of either "0" or an empty string, according to its data type. However, any parameter specified in the callproc statement must exist as named in the procedure being called. (Parameter names are 4GL names.)
A 4GL procedure can be global or local to its source file, as discussed in the following subsections.
Using Local 4GL Procedures
A local 4GL procedure is a series of 4GL source statements that appear in the source file for a user‑defined frame or a global procedure. The ABF Frame Catalog has no record of local procedures.
You must declare and define each local procedure in the source file. The declaration specifies the procedure's return type; the definition specifies the actions that the procedure performs.
You must declare local 4GL procedures in one of the following places:
The declare section of the global procedure (if the source file is for a global procedure)
The declare section of the initialize statement (if the source file is for a frame)
You can mix procedure and variable declarations within these locations. Each local procedure declaration takes one of the following forms:
identifier = procedure returning typedeclaration
This syntax indicates the type of the value the procedure is expected to return.
Procedures can return simple data types (for example, integer or varchar) only; they cannot return complex data types (such as arrays).
identifier = procedure returning none
or
identifier = procedure
These two forms are equivalent and indicate that the local procedure returns no value.
You must define local 4GL procedures at the end of the source file, as follows:
If the source file defines a global procedure, the local procedure definitions must follow the definition of the global procedure.
If the source file defines a frame, the local procedure definitions must follow all the activations for the frame.
Each local procedure definition consists of a procedure statement, using the syntax shown at the beginning of this section.
Note:  Procedure names are case sensitive. Be sure the call statement, declaration, and definition use exactly the same name.
Local 4GL procedures:
Cannot use forms statements if the local procedure is inside of a 4GL global procedure.
Can use some forms statements if the local procedure is inside of a 4GL frame. The following forms statements, with some restrictions, can be used:
clear, redisplay, validate, and validrow are unrestricted
resume must be inside of a submenu (either run submenu or display submenu) loop
resume field, resume next, resume entry, and resume menu must be inside of a display submenu loop
Cannot declare hidden columns in table fields.
Cannot be called from a different source file.
Can refer to fields or local variables declared in the frame or global procedure at the beginning of the source file, except when local variables of the same name are declared in the local procedure.
For example:
    procedure my_global_proc = 
    declare
       x = integer,
       y = integer,
       my_local_proc = procedure
    begin
    . . .
    end
    procedure my_local_proc = 
    declare
      y = integer
    begin
      . . .
    end
A reference to x within the body of "my_local_proc" refers to the x declared in "my_global_proc." However, a reference to y within the body of "my_local_proc" refers to the y declared in "my_local_proc;" the local procedure cannot refer to the y declared in the global procedure.
Can use "*" or all in various statements (such as select, insert, and update) to refer to all visible fields in a form or table field.
Such references always retrieve all visible fields, even if the local procedure defines a variable with the same name as one of the visible fields.
Using Global 4GL Procedures
You must declare a global 4GL procedure on the ABF Create a Procedure frame, specifying the name of a source file that contains the procedure. The 4GL code that defines the procedure must appear at the beginning of the source file that you specify.
The fields, table fields, form, and variables that you declare in a global procedure are available to local procedures. The only exception is when a local procedure defines a variable of the same name as used in a global procedure.
Global 4GL procedures do not use forms. Therefore, the following 4GL forms-control statements related to form display and table fields--clear, redisplay, resume, validate, and validrow--are not available within a global 4GL procedure or within a local 4GL procedure in the same file. Also, the following statements are available with arrays only; you cannot use them with table fields: clearrow, deleterow, insertrow, and unloadtable.