ICubeInstanceStorage.SaveMatrixEx

Syntax

SaveMatrixEx(Matrix: IMatrix; ValueFlags: Array);

SaveMatrixEx(Matrix: Prognoz.Platform.Interop.Matrix.IMatrix; ValueFlags: Array);

Parameters

Matrix. Matrix containing values that must be saved back to cube.

ValueFlags. Flags array of elements containing changed values. Only the matrix elements are saved to cube, which flag corresponds with one of the values in this array.

Description

The SaveMatrixEx method saves data matrix to cube by several flags of changed values.

Example

Executing the example requires that the repository contains a cube with the STD_CUBE identifier. The cube contains three dimensions with the FACTS, CALENDAR and COUNTRY identifiers.

Add links to the Cubes, Dimensions, Matrix, Metabase system assemblies.

Sub UserProc;
Var
    MB: IMetabase;
    CubInst: ICubeInstance;
    Des: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Matr: IMatrix;
    Iter: IMatrixIterator;
    Coord: IMatrixCoord;
    Sto: ICubeInstanceStorage;
    i: Integer;
    ValueFlags: Array 
Of Integer;
Begin
    MB := MetabaseClass.Active;
    CubInst := MB.ItemById(
"STD_CUBE").Open(NullAs ICubeInstance;
    Des := CubInst.Destinations.DefaultDestination;
    
//Cube selection
    Sels := Des.CreateDimSelectionSet;
    Sels.FindById(
"FACTS").SelectElement(0False); //Fact
    Sels.FindById("CALENDAR").SelectElement(0False); //Calendar
    Sels.FindById("COUNTRY").SelectAll; //Countries
    //Get values matrix by specified selection
    Matr := Des.Execute(Sels);
    Iter := Matr.CreateIterator;
    Coord := Matr.CreateCoord;
    
For i := 0 To Matr.DimensionCount - 1 Do
        Coord.Item(i) := 
0;
    
End For;
    
//Change value by the first country
    Iter.PutCoord(Coord);
    Iter.Value := Iter.Value + 
1;
    Iter.ValueFlag := 
1;
    
//Change coordinate
    Coord.Item(2) := 1;
    
//Change value by the second country
    Iter.PutCoord(Coord);
    Iter.Value := Iter.Value + 
2;
    Iter.ValueFlag := 
2;
    
//Flags array of changed data, by which saving is executed
    ValueFlags := New Integer[2];
    ValueFlags[
0] := 1;
    ValueFlags[
1] := 2;
    
//Object for saving data to cube
    Sto := Des.CreateStorage(CubeInstanceStorageOptions.None);
    
//Data saving handler
    Sto.SaveMatrixCallback := New TCubeSaveCallback.Create;
    
//Save values
    Sto.SaveMatrixEx(Matr, ValueFlags);
End Sub UserProc;

Class TCubeSaveCallback: CubeCallback
    
Public Sub OnAfterSave(Argument: ICubeCallbackSaveArgument);
    
Var
        Matr: IMatrix;
        Iter: IMatrixIterator;
        i: Integer;
    
Begin
        Debug.WriteLine(
"---Data is saved---");
        Debug.WriteLine(
"Changed data flags, by which saving is executed:");
        
For Each i In Argument.ValueFlags Do
            Debug.Write(i.ToString + 
" ");
        
End For;
        Debug.WriteLine(
"");
        Debug.WriteLine(
"Saved matrix:");
        Matr := Argument.ValueMatrix;
        Iter := Matr.CreateIterator;
        Iter.Move(IteratorDirection.First);
        
While Iter.Valid Do
            Debug.Write(iter.Value + 
" ");
            Iter.Move(IteratorDirection.Next);
        
End While;
        Debug.WriteLine(
"");
        Debug.WriteLine(
"Changed values:");
        Matr := Argument.FilteredMatrix;
        Iter := Matr.CreateIterator;
        Iter.Move(IteratorDirection.First);
        
While Iter.Valid Do
            Debug.Write(iter.Value + 
" ");
            Iter.Move(IteratorDirection.Next);
        
End While;
        Debug.WriteLine(
"");
    
End Sub OnAfterSave;
End Class TCubeSaveCallback;

Imports Prognoz.Platform.Interop.Cubes;
Imports Prognoz.Platform.Interop.Dimensions;
Imports Prognoz.Platform.Interop.ForeSystem;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.Metabase;

Public Shared Sub Main(Params: StartParams);
Var
    MB: IMetabase;
    CubInst: ICubeInstance;
    Des: ICubeInstanceDestination;
    Sels: IDimSelectionSet;
    Matr: IMatrix;
    Iter: IMatrixIterator;
    Coord: IMatrixCoord;
    Sto: ICubeInstanceStorage;
    i: Integer;
    ValueFlags: Array 
Of Integer;
Begin
    MB := Params.Metabase;
    CubInst := MB.ItemById[
"STD_CUBE"].Open(NullAs ICubeInstance;
    Des := CubInst.Destinations.DefaultDestination;
    
//Cube selection
    Sels := Des.CreateDimSelectionSet();
    Sels.FindById(
"FACTS").SelectElement(0False); //Fact
    Sels.FindById("CALENDAR").SelectElement(0False); //Calendar
    Sels.FindById("COUNTRY").SelectAll(); //Countries
    //Get values matrix by specified selection
    Matr := Des.Execute(Sels, uinteger.MaxValue);
    Iter := Matr.CreateIterator();
    Coord := Matr.CreateCoord();
    
For i := 0 To Matr.DimensionCount - 1 Do
        Coord.Item[i] := 
0;
    
End For;
    
//Change value by the first country
    Iter.PutCoord(Coord);
    Iter.Value := (Iter.Value 
As Double) + 1;
    Iter.ValueFlag := 
1;
    
//Change coordinate
    Coord.Item[2] := 1;
    
//Change value by the second country
    Iter.PutCoord(Coord);
    Iter.Value := (Iter.Value 
As Double) + 2;
    Iter.ValueFlag := 
2;
    
//Flags array of changed data, by which saving is executed
    ValueFlags := New Integer[2];
    ValueFlags[
0] := 1;
    ValueFlags[
1] := 2;
    
//Object for saving data to cube
    Sto := Des.CreateStorage(CubeInstanceStorageOptions.cisoNone);
    
//Data saving handler
    Sto.SaveMatrixCallback := New TCubeSaveCallback();
    
//Save values
    Sto.SaveMatrixEx(Matr, ValueFlags);
End Sub;

Class TCubeSaveCallback: ICubeSaveMatrixCallback
    
Public Sub OnBeforeSave(Argument: ICubeCallbackBeforeSaveArgument);
    
Begin
    
End Sub;

    
Public Sub OnAfterSave(Argument: ICubeCallbackSaveArgument);
    
Var
        Matr: IMatrix;
        Iter: IMatrixIterator;
        i: Integer;
    
Begin
        System.Diagnostics.Debug.WriteLine(
"---Data is saved---");
        System.Diagnostics.Debug.WriteLine(
"Changed data flags, by which saving is executed:");
        
For Each i In Argument.ValueFlags Do
            System.Diagnostics.Debug.Write(i.ToString() + 
" ");
        
End For;
        System.Diagnostics.Debug.WriteLine(
"");
        System.Diagnostics.Debug.WriteLine(
"Saved matrix:");
        Matr := Argument.ValueMatrix;
        Iter := Matr.CreateIterator();
        Iter.Move(IteratorDirection.itdFirst);
        
While Iter.Valid Do
            System.Diagnostics.Debug.Write(iter.Value + 
" ");
            Iter.Move(IteratorDirection.itdNext);
        
End While;
        System.Diagnostics.Debug.WriteLine(
"");
        System.Diagnostics.Debug.WriteLine(
"Changed values:");
        Matr := Argument.FilteredMatrix;
        Iter := Matr.CreateIterator();
        Iter.Move(IteratorDirection.itdFirst);
        
While Iter.Valid Do
            System.Diagnostics.Debug.Write(iter.Value + 
" ");
            Iter.Move(IteratorDirection.itdNext);
        
End While;
        System.Diagnostics.Debug.WriteLine(
"");
    
End Sub;
End Class;

After executing the example a matrix with cube data is obtained. The values are changed by some coordinates, following which the updated matrix is saved back to the cube. Data saving is handled in the TCubeSaveCallback custom class. Saved data is marked with various changed data flags.

See also:

ICubeInstanceStorage