Creating a test cube including rules and data

Example files with this article:
  • Creating a test cube
  • Introduction

    Some of the generic (data copy) processes at the Bedrock TM1 code base require a 24-dimension cube, if you want to edit the process properly (in the absence of a product like Vizier that I have never used). For example, the process Bedrock.Cube.Data.Copy. This cube can be very simple, even without any data nor rules - yet it has to exist if you want to make real modifications to the processes. Since I do value my time and other TM1 developer’s time, below you can find my TI script to build such a 24-dimensional cube. There will be very little data in it, but the cube will contain rules built at run-time. I will foresee data a N-level, C-level and also textual data. Where possible both hard-coded data as well as rules-driven data.

    Turbo Integrator code

    When you study the Turbo Integrator coding below, you will notice practical (working !) code for, among others:

    1. creating a cube with 24 dimensions
    2. inserting elements of all types in the resp. dimensions, using a naming syntax
    3. writing data to this new cube
    4. using While … End constructs (loops) in TI
    5. outputting text to a file in the TM1 data directory, without double quotes
    6. generating TM1 rules at random, attaching the rules to the cube
    7. creating subsets in the dimensions, including dynamic subsets with MDX expressions
    8. creating views on the same cube to have quick access to the hard-coded and rules calculated cell contents

    Here is the code in the Prolog tab:

    # Wim Gielis # http://www.wimgielis.com
    ##### # TI code to generate a 24-dimensional cube, including data and rules, numbers and texts # 09/15/12 #####
    vCube='myCube'; CubeDestroy(vCube); m=1; While(m<=24); vDim='v'|NumberToString(m); DimensionDestroy(vDim); DimensionCreate(vDim); # test elements DimensionElementInsert(vDim, '', 'Consolidation_'|vDim, 'C'); DimensionElementInsert(vDim, '', 'Element 1_'|vDim, 'N'); DimensionElementInsert(vDim, '', 'Element 2_'|vDim, 'N'); DimensionElementInsert(vDim, '', 'Element 3_'|vDim, 'N'); DimensionElementInsert(vDim, '', 'Element 4_'|vDim, 'N'); If(m=24); DimensionElementInsert(vDim,'', 'Element 5_'|vDim, 'S'); EndIf; DimensionElementComponentAdd(vDim, 'Consolidation_'|vDim, 'Element 1_'|vDim, 1); DimensionElementComponentAdd(vDim, 'Consolidation_'|vDim, 'Element 2_'|vDim, 1); DimensionElementComponentAdd(vDim, 'Consolidation_'|vDim, 'Element 3_'|vDim, 1); m=m+1; End; # create the cube CubeCreate(vCube, 'v1', 'v2', 'v3', 'v4', 'v5', 'v6', 'v7', 'v8', 'v9', 'v10', 'v11', 'v12', 'v13', 'v14', 'v15', 'v16', 'v17', 'v18', 'v19', 'v20', 'v21', 'v22', 'v23', 'v24'); # Creating a rules file vRulesFile=vCube | '.rux'; DatasourceASCIIQuoteCharacter = ''; # writing rules to a .rux file in the TM1 data directory AsciiOutput(vRulesFile, 'Skipcheck;'); AsciiOutput(vRulesFile, ''); AsciiOutput(vRulesFile, '###############################################################################'); AsciiOutput(vRulesFile, '# Rule at N-level'); AsciiOutput(vRulesFile, '# (On the N-level elements Element3 in all dimensions)'); AsciiOutput(vRulesFile, '###############################################################################'); AsciiOutput(vRulesFile, ''); AsciiOutput(vRulesFile, '[''Element 3_v1'', ''Element 3_v2'', ''Element 3_v3'', ''Element 3_v4'', ''Element 3_v5'', ''Element 3_v6'', ''Element 3_v7'', ''Element 3_v8'', ''Element 3_v9'', ''Element 3_v10'', '); AsciiOutput(vRulesFile, '''Element 3_v11'', ''Element 3_v12'', ''Element 3_v13'', ''Element 3_v14'', ''Element 3_v15'', ''Element 3_v16'', ''Element 3_v17'', ''Element 3_v18'', ''Element 3_v19'', ''Element 3_v20'', '); AsciiOutput(vRulesFile, '''Element 3_v21'', ''Element 3_v22'', ''Element 3_v23'', ''Element 3_v24'']=N:3;'); AsciiOutput(vRulesFile, ''); # CODE IS NOT REPRODUCED FULLY - DOWNLOAD THE PRO FILE ON THIS PAGE TO HAVE THE FULL CODE AsciiOutput(vRulesFile, ''); AsciiOutput(vRulesFile, 'Feeders;'); AsciiOutput(vRulesFile, ''); AsciiOutput(vRulesFile, '# Feeder for rule 1'); AsciiOutput(vRulesFile, '###################'); AsciiOutput(vRulesFile, ''); AsciiOutput(vRulesFile, '[''Element 1_v24'']=>[''Element 3_v24''];');

    Here is the code in the Epilog tab:

    # create a default subset in every dimension
    m=1;
    While(m<=24);
      vDim='v'|NumberToString(m);
      SubsetCreateByMDX('Default', '{TM1SUBSETALL( [' | vDim | '] )}');
      m=m+1;
    End;
    
    
    # Attaching the rules file to the cube
    If( FileExists( vRulesFile ) = 1 );
      RuleLoadFromFile(vCube, vRulesFile);
    EndIf;
    
    
    # creating views
    
    # 0. default view and view to be used in data copy processes
    ViewCreate(vCube,'Default');
    ViewCreate(vCube,'z_TI_View');
    
    # fill the cube now that the elements exist and create views if useful
    
    # 1. A hard-coded 1 on all elements Element 1 in every dimension
    CellPutN( 1, vCube, 'Element 1_v1', 'Element 1_v2', 'Element 1_v3', 'Element 1_v4', 'Element 1_v5', 'Element 1_v6',
    'Element 1_v7', 'Element 1_v8', 'Element 1_v9', 'Element 1_v10', 'Element 1_v11', 'Element 1_v12', 'Element 1_v13',
    'Element 1_v14', 'Element 1_v15', 'Element 1_v16', 'Element 1_v17', 'Element 1_v18', 'Element 1_v19', 'Element 1_v20',
    'Element 1_v21', 'Element 1_v22', 'Element 1_v23', 'Element 1_v24');
    
    vTemp='Hard-coded number 1';
    ViewCreate(vCube, vTemp);
    m=1;
    While(m<=22);
      vDim='v'|NumberToString(m);
      SubsetCreateByMDX(vTemp, '{[' | vDim | '].[Element 1_' | vDim | ']}');
      ViewSubsetAssign(vCube, vTemp, vDim, vTemp);
      m=m+1;
    End;
    ViewSubsetAssign(vCube, vTemp, 'v23', 'Default');
    ViewSubsetAssign(vCube, vTemp, 'v24', 'Default');
    
    # CODE IS NOT REPRODUCED FULLY - DOWNLOAD THE PRO FILE ON THIS PAGE TO HAVE THE FULL CODE
    

    Wrap up

    Next to interesting Turbo Integrator aspects, this code helped me in creating test cases for several Bedrock data copy processes.




    Homepage

    Section contents

    About Wim

    Wim Gielis is a Business Intelligence consultant and Excel expert

    Other links