Analytic Model Metadata Classes Examples

The following are some examples of the most general cases of using the Analytic Model Metadata classes.

The following code creates an analytic model definition “from scratch” without retrieving an existing definition from the Application Designer, adds parts such as dimensions, cubes, and cube collections, then saves the definition.

import PT_ANALYTICMODELDEFN:*;

Function CreateGENXModel
   
   Local PT_ANALYTICMODELDEFN:AnalyticModelDefn &Model;
   Local PT_ANALYTICMODELDEFN:UserFunctionDefn &UserFunc;
   Local PT_ANALYTICMODELDEFN:DimensionDefn &Dim;
   Local PT_ANALYTICMODELDEFN:CubeDefn &Cube;
   Local PT_ANALYTICMODELDEFN:CubeCollectionDefn &CubeColl;
   Local array of string &arr;
   
   &ACEMODELID = QE_ACE_META_WK.QE_ACE_MODELID.Value;
   
   &Model = create PT_ANALYTICMODELDEFN:AnalyticModelDefn(&ACEMODELID);
   
   &Model.Create();
   
   /* Model Properties */
   
   
   &Model.Description = QE_ACE_META_WK.DESCR;
   &Model.LongDescription = QE_ACE_META_WK.DESCR200;
   &Model.MaxDelta = QE_ACE_META_WK.QE_ACE_MAXDELTA_FL;
   &Model.MaxIterations = QE_ACE_META_WK.QE_ACE_MAXITER_FLD;
   
   If (QE_ACE_META_WK.QE_ACE_CIRCWARN_FL.Value = 0) Then
      &Circ = True;
   Else
      &Circ = False;
   End-If;
   
   If (QE_ACE_META_WK.QE_ACE_RESOLVE_FLD.Value = 0) Then
      &Resolve = True;
   Else
      &Resolve = False;
   End-If;
   
   &Model.ResolveCircularDeps = &Resolve;
   &Model.CircularFormulaWarn = &Circ;
   
   
   /* Add User Functions */
   
   &UserFunction = &Model.AddUserFunction("FILTERPRODUCTS");
   &Rule = &UserFunction.GetRule();
   &Rule.RuleString = "IF( ((UNIT_COST = 0) .AND. (UNITS_SOLD = 0) .AND. (PROD_SALES =0 )) , RETURN(0), RETURN(1))";
   &UserFunction.SetRule(&Rule);   


   /* Add the Dimensions */
   &Dim = &Model.AddDimension("MONTH");
   
   &Dim = &Model.AddDimension("PRODUCTS");
   &Dim.TotalMemberName = "TOTAL";
   
   &Dim = &Model.AddDimension("PROD_CAT");
   
   &Dim = &Model.AddDimension("REGION");
   
   /* Add the cubes */
   &Cube = &Model.AddCube("PROD_SALES");
   &Cube.FormatType = &Cube.AnalyticModel_Format_Number;
   &Cube.IsVirtual = False;
   &Cube.CalcAggregates = False;
   &Cube.Rule = "UNIT_COST * UNITS_SOLD";
   &Cube.AttachDimension("MONTH");
   &Cube.AttachDimension("PRODUCTS");
   &Cube.AttachDimension("REGION");
   
   &Cube = &Model.AddCube("SALES");
   &Cube.FormatType = &Cube.AnalyticModel_Format_Number;
   &Cube.IsVirtual = False;
   &Cube.CalcAggregates = False;
   
   &Cube = &Model.AddCube("TGT_COST");
   &Cube.FormatType = &Cube.AnalyticModel_Format_Number;
   &Cube.IsVirtual = False;
   &Cube.CalcAggregates = False;
   &Cube.AttachDimension("PRODUCTS");
   
   &Cube = &Model.AddCube("UNITS_SOLD");
   &Cube.FormatType = &Cube.AnalyticModel_Format_Number;
   &Cube.IsVirtual = False;
   &Cube.CalcAggregates = False;
   &Cube.AttachDimension("MONTH");
   &Cube.AttachDimension("PRODUCTS");
   &Cube.AttachDimension("REGION");
   
   &Cube = &Model.AddCube("UNIT_COST");
   &Cube.FormatType = &Cube.AnalyticModel_Format_Number;
   &Cube.IsVirtual = False;
   &Cube.CalcAggregates = False;
   &Cube.AttachDimension("MONTH");
   &Cube.AttachDimension("PRODUCTS");
   &Cube.AttachDimension("REGION");
   
   /* Add Cube Collections */
   &CubeColl = &Model.AddCubeCollection("REG_SALES_IN");
   &CubeColl.RecordName = "QE_BAM_FACT_TBL";
   &CubeColl.AttachCube("PROD_SALES");
   &CubeColl.AttachCube("UNITS_SOLD");
   &CubeColl.AttachCube("UNIT_COST");
   &CubeColl.SetFieldMapping("MONTH", "QE_BAM_MONTH_FLD", False);
   &CubeColl.SetPersistAggregate("MONTH", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("MONTH", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("PRODUCTS", "QE_BAM_PRODUCT_FLD", False);
   &CubeColl.SetPersistAggregate("PRODUCTS", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("PRODUCTS", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("REGION", "QE_BAM_REGION_FLD", False);
   &CubeColl.SetPersistAggregate("REGION", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("REGION", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("PROD_SALES", "QE_BAM_PRDSALES_FL", True);
   &CubeColl.SetFieldMapping("UNITS_SOLD", "QE_BAM_SALES_FLD", True);
   &CubeColl.SetFieldMapping("UNIT_COST", "QE_BAM_UNIT_FLD", True);
   
   &CubeColl = &Model.AddCubeCollection("REG_SALES_PROD");
   &CubeColl.RecordName = "QE_BAM_CCSMOKE";
   &CubeColl.AttachCube("PROD_SALES");
   &CubeColl.AttachCube("UNITS_SOLD");
   &CubeColl.AttachCube("UNIT_COST");
   &CubeColl.SetFieldMapping("MONTH", "QE_BAM_MONTH_FLD", False);
   &CubeColl.SetPersistAggregate("MONTH", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("MONTH", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("PRODUCTS", "QE_BAM_PRODUCT_FLD", False);
   &CubeColl.SetPersistAggregate("PRODUCTS", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetFilter("PRODUCTS", "FILTERPRODUCTS");
   &CubeColl.SetDimSort("PRODUCTS", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("REGION", "QE_BAM_REGION_FLD", False);
   &CubeColl.SetPersistAggregate("REGION", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("REGION", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("PROD_SALES", "QE_BAM_PRDSALES_FL", True);
   &CubeColl.SetFieldMapping("UNITS_SOLD", "QE_BAM_SALES_FLD", True);
   &CubeColl.SetFieldMapping("UNIT_COST", "QE_BAM_UNIT_FLD", True);
   
   &CubeColl = &Model.AddCubeCollection("TGT_COST_PROD");
   &CubeColl.RecordName = "QE_BAM_CC_TRGT";
   &CubeColl.AttachCube("TGT_COST");
   &CubeColl.SetFieldMapping("PRODUCTS", "QE_BAM_PRODUCT_FLD", False);
   &CubeColl.SetPersistAggregate("PRODUCTS", &CubeColl.AnalyticModel_AggrType_None);
   &CubeColl.SetDimSort("PRODUCTS", False, "", False, "", False, "");
   &CubeColl.SetFieldMapping("TGT_COST", "QE_BAM_TARGET_FLD", True);
   
   &Model.Save();
   /* &Valid = &Model.Validate(); */
   
   QE_ACE_META_WK.QE_BAM_PCSTATUS = "The Model " | &ACEMODELID | " was created and saved.";
   
End-Function;