Passing Objects

To pass an object, use the following syntax in the calling procedure (actual parameter):

do PROC(.objectName)

This DO statement passes the object identified by the parameter .objectName to the PROC procedure. The PROC procedure declaration must specify a type and identifier of the same type as the parameter being passed.

In the receiving procedure (formal parameter), the object must be correctly declared by identifying the type of object that the procedure is expected to receive along with an ObjectName:

PROC(objectType objectName)

Example

The following example demonstrates the passing of a cif and dep object to the CHECK procedure. Both objects are declared and populated in the calling procedure. The receiving procedure declares both objects as RecordCIF and RecordDEP in the formal parameter list.

      type RecordDEP dep=Db.getRecord(“DEP”,”:CID”)

      type RecordCIF cif=Db.getRecord(“CIF”,”:ACN”)

      

      do CHECK(.dep,.cif)

      quit

      

CHECK(RecordDEP dep, RecordCIF cif)

      set NAM=cif.nam,TAXID=cif.taxid,DOB=cif.dob

      set ODT=dep.odt,BAL=dep.bal,IRN=dep.irn

*CID and ACN must be defined prior to the getRecord statements.

Passing Objects Instantiated from Cache

Do not pass cached objects as parameters. Instead scope and instantiate them inside the procedures that use them. The code is, therefore, more encapsulated and modular and gives the optimizer a chance to reduce arrays into variables.

Example

Assume that a line tag instantiates a RecordTRN object from a Cache object, references the trn.des property, and calls another line tag. The optimal solution is to, within the second line tag, reinstantiate the RecordTRN object from the Cache object. This approach reduces the RecordTRN object into local variables. However, if instead the RecordTRN object is passed as a parameter to the second line tag, the generated code uses the vobj array because reference objects are not reduced when they are actual or formal parameters.

Option 1 -- Reinstating from Cache

#optimize

TAGA(String etc)

type Public Cache %CACHE()

type RecordTRN trn = %CACHE("TRN").getRecord("TRN","ETC = :etc")

type String des = trn.des

 

do TAGB(etc)    // RecordTRN not passed

quit

 

TAGB(String etc)

type Public Cache %CACHE()

type RecordTRN trn = %CACHE("TRN").getRecord("TRN","ETC = :etc")

type String pgm = trn.pgm

quit

Option 2 -- Passing an Object Instantiated from Cache

#optimize

TAGA(String etc)

type Public Cache %CACHE()

type RecordTRN trn = %CACHE("TRN").getRecord("TRN","ETC = :etc")

type String des = trn.des

 

do TAGB(etc,trn)    // RecordTRN is passed

quit

 

TAGB(String etc,RecordTRN trn)

type String pgm = trn.pgm

quit

Object Scope

Refer to the Object Scope in PSL section for details concerning the way PSL manages the scope of objects passed as parameters.