Try OpenEdge Now
skip to main content
Programming Interfaces
Database Administration Entity Interface Reference : IPartitionPolicy interface : IPartitionPolicy examples : Creating a policy for a table with data
 
Creating a policy for a table with data
The following code shows how to create a policy for a table that contains data:
using OpenEdge.DataAdmin.*.
using OpenEdge.DataAdmin.Error.DataAdminErrorHandler.
using OpenEdge.DataAdmin.Lang.Collections.IIterator.

block-level on error undo, throw.

define variable service as DataAdminService no-undo.

define variable policy as IPartitionPolicy no-undo.
define variable errorHandler as DataAdminErrorHandler no-undo.
define variable tbl as ITable no-undo.
define variable idx as IIndex no-undo.

service = new DataAdminService(ldbname(1)).
tbl = service:GetTable("Order").
policy = service:NewPartitionPolicy("OrderPolicy").
policy:Table = tbl.
policy:HasRange = true.

/* create fields from index (can of course just add fields to the Fields collection directly) */
idx = tbl:Indexes:Find("slsdateidx").
policy:Fields:AddAll(idx:Fields).

policy:DefaultAllocation = "None".
policy:DefaultDataArea = service:GetArea("TenantExpensive").
policy:DefaultIndexArea = service:GetArea("TenantExpensive").
policy:DefaultLobArea = service:GetArea("TenantExpensive").

policy:AddDetailsFromData().

run updateandshowDetails(policy).

service:CreatePartitionPolicy(policy).

catch e as Progress.Lang.Error :
errorHandler = new DataAdminErrorHandler().
errorHandler:Error(e).
end catch.
finally:
delete object service no-error.
end finally.

procedure updateAndShowDetails :
define input parameter pPolicy as IPartitionPolicy no-undo.
define variable detail as IPartitionPolicyDetail no-undo.
define variable iter as IIterator no-undo.
iter = pPolicy:Details:Iterator().
do while iter:HasNext() with frame x down:
detail = cast(iter:Next(),IPartitionPolicyDetail).
/* set date to last of year */
Detail:SetValue(2,31/12/2014).
disp detail:Values[1] @ x1 as char
detail:Values[2] @ x2 as char
with frame x width 80.
down with frame x.
end.
end.
The example above runs an internal updateAndShowDetails illustrating how you can edit the details before they are committed. The updateAndShowDetails changes the OrderDate value to the end of the year and displays the two values. The AddDetailsFromData creates details with the highest value found in the data.
The following example adds the fields from an index. You can also add the fields directly as follows:
...
policy:Fields:Add(tbl:Fields:Find("SalesRep")).
policy:Fields:Add(tbl:Fields:Find("OrderDate")).
...