Passing Objects

All PeopleCode objects can be passed as function parameters. You can pass complex data structures between PeopleCode functions (as opposed to passing long lists of fields). If a function is passed an object, the function works on the actual object, not on a copy of the object.

In the following simple example, a reference to the Visible property is passed, not the value of Visible. This enables the MyPeopleCodeFunction either to get or set the value of the Visible property:

MyPeopleCodeFunction(&MyField.Visible);

In the following example, the function Process_Rowset loops through every row and record in the rowset passed to it and executes an Update statement on each record in the rowset. This function can be called from any PeopleCode program and can process any rowset that is passed to it.

Local Rowset &RS;
Local Record &REC;

Function Process_RowSet(&ROWSET as Rowset);

   For &I = 1 To &ROWSET.Rowcount
      For &J = 1 To &ROWSET.Recordcount
         &REC = &ROWSET.GetRow(&I).GetRecord(&J);
         &REC.Update();
      End-For;
   End-For;  
End-Function;

&RS = GetLevel0();

Process_RowSet(&RS);

The following function takes a rowset and a record passed in from another program. GetRecord does not take a variable for the record; however, you can use the @ symbol to dereference the record name.

Function Get_My_Row(&PASSED_ROWSET, &PASSED_RECORD)

   For &ROWSET_ROW = 1 To &PASSED_ROWSET.RowCount
      &UNDERLYINGREC = "RECORD." | &PASSED_ROWSET.DBRecordName;
      &ROW_RECORD = &PASSED_ROWSET.GetRow(&ROWSET_ROW).GetRecord(@&UNDERLYINGREC);
    
      /* Do other processing */
     
   End-For;

End-Function;