RecordRef.Open(Integer [, Boolean] [, Text]) Method

Version: Available or changed with runtime version 1.0.

Causes a RecordRef variable to refer to a table, which is identified by its number in a particular company.

Syntax

 RecordRef.Open(No: Integer [, Temp: Boolean] [, CompanyName: Text])

Parameters

RecordRef
 Type: RecordRef
An instance of the RecordRef data type.

No
 Type: Integer
The number of the table.

[Optional] Temp
 Type: Boolean

[Optional] CompanyName
 Type: Text
The name of the company to which you want to change. If you omit this parameter, the current company is used.

Remarks

When you use the RecordRef.Open method a new object is created. This object contains references to the open table, filters, and the record itself and all the fields it contains. You can open a table by using the table number or the name of the table that represents the table number. For example, you open the Customer table by using following syntax: RecordRef.Open(18) or RecordRef.Open(Database::Customer). RecordRef.Open(0) is also accepted, whereas passing another non-existent table number will result in a runtime error message.

If you use the CompanyName parameter, then this method works the same as the ChangeCompany Method (Record).

Example 1

The following example uses the Open method to create a RecordRef variable that is named MyRecordRef for the Customer table. The parameters are omitted in this example because there is only one company in this example and the table will not be open as temporary table. The caption and number of records in the table are displayed in a Message box. At the end of the display, the Close Method (RecordRef) closes the table.

var
    MyRecordRef: RecordRef;
    Text000: Label 'The %1 table contains %2 records.'; 
begin    
    MyRecordRef.Open(Database::Customer);  
    Message(Text000, MyRecordRef.Caption, MyRecordRef.Count);  
    MyRecordRef.Close;  
end;

Example 2

This example shows how to use the Open method. In this example, "MyRecordRef" opens table 27 and then "Find('-')" finds the first record in the table. "TempMyRecordRef" opens a temporary table which is empty and therefore the "Find('-')" returns false.

var
    MyRecordRef: RecordRef;
    TempMyRecordRef: RecordRef;
begin  
    MyRecordRef.Open(27,false);  
    TempMyRecordRef.Open(27,true);  
      
    if MyRecordRef.Find('-') then // This is true and will find the first record in the table.  
      Message('MyRecordRef finds')  
    else  
      Message('MyRecordRef does not find');  
      
    if TempMyRecordRef.Find('-') then // This is false because there are no records in a temporary table.  
      Message('TempMyRecordRef finds')  
    else  
      Message('TempMyRecordRef does not find');  
end;

RecordRef Data Type
Get Started with AL
Developing Extensions