Inserting Rows Using PeopleCode
When inserting rows using PeopleCode, you can either use the Insert method with a record object or create a SQL Insert statement using the SQL object. If you do a single insert, use the Record Insert method. If you are in a loop and,therefore, calling the insert more than once, use the SQL object. The SQL object uses dedicated cursors and, if the database you are working with supports it, bulk insert.
A dedicated cursor means that the SQL gets compiled only once on the database, so PeopleTools looks for the meta-SQL only once. This can increase performance.
For bulk insert, inserted rows are buffered and sent to the database server only when the buffer is full or a commit occurs. This reduces the number of round-trips to the database. Again, this can increase performance.
The following is an example of using the Record Insert method:
&REC = CreateRecord(Record.GREG); &REC.DESCR.Value = "Y" | &I; &REC.EMPLID.Value = &I; &REC.Insert();
The following is an example using a SQL object to insert rows:
&SQL = CreateSQL("%INSERT(:1)"); &REC = CreateRecord(Record.GREG); &SQL.BulkMode = True; For &I = 1 to 10 &REC.DESCR.Value = "Y" | &I; &REC.EMPLID.Value = &I; &SQL.Execute(&REC); End-For;