DataFlex - Clear a data dictionary but keep its parents
Overview
Often you find yourself creating a collection of child records, but you want them all to have the same parents.
If you only have one parent, then doing Set Constrain_File to Parent.file_number will ensure the parent isn’t cleared, but then other parents are still cleared and you can only have one contrain file.
Code
Procedure Clear_Retain_Parents
// The standard Clear message also clears (non-Constrained) server DDOs.
// This does not.
Handle hoServer
Handle[] hoServerList // the object ids of all this DDO's servers
Integer iCount iMax
Get Data_Set_Server_Count to iMax
Decrement iMax
For iCount from 0 to iMax
Get Data_Set_Server 0 to hoServer
Move hoServer to hoServerList[iCount]
Send Detach_Server hoServer
Loop
Send Clear
For iCount from 0 to iMax
Move hoServerList[iCount] to hoServer
Send Attach_Server hoServer
Loop
End_Procedure