Using RecordRef to Work with Multiple Tables
<p>I have a group of tables that I need to the integer key from and I would like to be able to pass in any of them into a single and get the next value for the key.</p>

<p>I believe that RecordRef is the way to do this, but the code so far doesn't seem quite right.</p>

<p>I am trying to build a function that will take a table record and then return an integer value, that integer value will be the next record for the primary key.  IE: if the last record's key is is 62825 the function will return 62826.</p>

<pre><code>FunctionA
BEGIN
  Id := GetNextId(SalesRecord);  //Assignment not allowed
END;

FunctionB
BEGIN
  Id := GetNextId(CreditMemoRecord);  //Assignment not allowed
END;

GetNextId(pTableReference: RecordRef) rNextId : Integer
BEGIN
  CASE pTableReference.NUMBER OF
    DATABASE::SalesRecord: BEGIN
      //Find last Record
      pTableReference.FINDLAST;
      lFieldRef := pTableReference.FIELD(1); //Set to the PK field
    END;
    DATABASE::CreditMemoRecord: BEGIN
      //Find last Record
      pTableReference.FINDLAST;
      lFieldRef := pTableReference.FIELD(10); //Set to the PK field
    END;
    ... //do more here
  END; //CASE

  EVALUATE(rNextId,FORMAT(lFieldRef.VALUE)); //Get the integer value from FieldRef
  rNextId := rNextId + 1; //Add one for the next value
  EXIT(rNextId);  //return the value
END;  
</code></pre>

<p>With this code I am getting the error "Assignment is not allowed for this variable." on the Function Call to GetNextId</p>

<p>Idea of the Table Structure:  </p>

<pre><code>Table - SalesRecord
FieldId, Fieldname, Type, Description
1 id integer PK
2 text1 text(30)
3 text2 text(30)
4 dec1 decimal
5 dec2 decmial

Table - CreditMemoRecord
FieldId, Fieldname, Type, Description
10 id integer PK
20 text1 text(30)
30 text2 text(30)
40 dec1 decmial
50 dec2 decmial
</code></pre>