Object Scope in PSL

PSL rules assume that any object in scope will not be changed within a called procedure unless it is explicitly passed to that procedure. The compiler cannot enforce this; therefore, you should carefully review all Public scope objects.

Objects passed as parameters can be modified and destroyed within the called procedure. As a rule, procedures should not destroy or instantiate objects passed in as formal parameters unless specifically designed as a generalized instantiation utility. PSL tests certain Record type objects that are received as formal parameters and inserts run-time error processing if the passed object is destroyed.

Individual array references to an object can be passed as parameters, as can individual property references.

PSL generates code to perform a run-time check on Record type objects which contain multiple nodes that are passed as parameters to ensure that existing objects are not re-instantiated. If an existing object is re-instantiated, the following warning will be thrown:

Possible run-time error RECEXISTS

Example

The following example demonstrates a compile error received when attempting to reference an object that is out of scope.

      type ResultSet rs=Db.select(“CID,BAL,IRN”,”DEP”)

      while rs.next() do DATA

      quit

 

DATA //set variables

      set CID=rs.getCol(1)

      set BAL=rs.getCol(2)

      set IRN=rs.getCol(3)

 

------------------------------------------------------------

Compile Errors:

set CID=rs.getCol(1)

-E-Undefined method: getCol

At source code line: 11 in subroutine: SUB

 

set BAL=rs.getCol(2)

-E-Undefined method: getCol

At source code line: 12 in subroutine: SUB

 

set IRN=rs.getCol(3)

-E-Undefined method: getCol

At source code line: 13 in subroutine: SUB

To correct these errors, the column values or the object itself must be passed to the DATA sub-procedure.