getRecord Method

Class: Db

Description

This method retrieves a single record from the database and instantiates an object. The system copies the record from the database into the object incrementally as it references its properties. Use this method to create a new object in modify mode.

As of Profile v6.3, this method supports lowercase variables, object.property, and system variables within the host variable syntax. PSL maps these variables and object references into uppercase host variables.

Use of the Db.select method is preferred over Db.getRecord if either of the following conditions exist:

Use of the Db.selectDbSet method is preferred over Db.getRecord if any of the following conditions exist:

You should still use the Db.getRecord method when instantiating a single Record<Class> object versus a set of Record<Class> objects. To retrieve multiple records simultaneously, use the Db.select method. To define a new object in create mode, use the Class.new method.

Declaration of Record Class Object

type RecordTABLE objectName = Db.getRecord(...)

Syntax

Db.getRecord(literal String table,literal String accessKeys,

literal boolean classNew)

Parameters

table

A valid database table name.

accessKeys

A comma-separated list of access keys for the table. This parameter can also specify an assignment (e.g., "ACN=:CIFNUM") or a column reference (e.g., DEP.ACN).

When using this method to instantiate a literal scope variable, the access keys must be either string literals or literal variables.

classNew

An option that indicates whether a new object is instantiated if the record does not exist. Valid values include 1 to instantiate or 0 to not instantiate.

The classNew PSL source logic optimizes database IO by eliminating the requirement to use the Db.isDefined method in many cases. This parameter can be used in conjunction with the getMode method, which determines whether the record was instantiated.

For example, you should always check the mode when using getRecord to retrieve DEP or LN records. The generated code for a getRecord for a RecordDEP checks the class of the object. If the class is "L", the code interprets that as a class.new, even though a record with the keys exists as a loan record. If you do not check the mode and actually save the record, a Record.bypassSave removes the loan record and inserts a deposit record.

Returns

An object of type RecordTABLE (e.g., RecordDEP, RecordLN).

When Became Available

v6.4

Examples

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

set NAM = cif.nam

set DOB = cif.dob

set TAXID = cif.taxid

___________________________________________________________

type RecordHIST hist = Db.getRecord("HIST","CID=:CID,TSEQ=:TSEQ")

set TAMT = hist.tamt

set TLO = hist.tlo

set TSO = hist.tso

___________________________________________________________

type RecordACH ach = Db.getRecord("ACH","COID=:COID",1)

if ‘ach.getMode() W !,”Record not found so create new one”

 

*ACN, CID, COID,and TSEQ must be defined prior to these

getRecord statements.