Global Scope of Objects

The Global Scope of an object enables an object to be visible to any subroutine that declares it. Its scope is explicitly controlled within the source code. A global scope object is declared with the qualifier ‘public’ after the type command.

Example

main // Main subroutine

new rs //Scope controlled in PSL source

type Public ResultSet rs = Db.select("CID,LNM","DEP")

do workOnRS

quit

/*

The object ‘rs’ will be deleted because it was explicitly made new in this scope

*/

 

workOnRS // Uses global object rs

type Public ResultSet rs //must be declared to be ‘visible’ in this subroutine

while rs.next write rs.getCol(1)

quit

 

image\msgs.gif

Use global scope objects sparingly. Pass objects as parameters whenever possible.