Error 88 on Sales Order Entry Lines

We are experiencing an error 88 on Sales Order Lines.  The error occurs only on large orders with numerous lines, especially when adding inventory items to the order on the fly.  The line prewrite script is failing and referencing different UDT objects declared by the Set command.  The failure normally occurs on MoveFirst of MoveNext commands for the UDT objects.  The prewrite script is lengthy and sets numerous new objects for other table reading, prior to writing the SO line record.  If an error occurs, all data on the lengthy order is lost.  How can we better manage the object resources to avoid the crashes?