FIX, REMOVE and CLEARBLOCK, You may end up with No data ;)


The FIX…ENDFIX command block restricts database calculations to a subset of the database. All commands nested between the FIX and ENDFIX statements are restricted to the specified database subset.

What I know about FIX is, it takes the union of the members which are in different FIX or (Hypothetically) are repeated in the same fix, so even if you mention FIX("E1","E1","E1") it will work on "E1" and just once, not thrice!.

Say you have fully populated data cube and you need to delete the data for one Entity(say E1), the fastest thing you will probably write is:

FIX(@REMOVE(@RELATIVE("Entity",0), "E1")
  CLEARBLOCK ALL;
ENDFIX

Yes, its done! This will remove the data for all the level 0 entities but not for E1. This will happen assuming there is no alternate hierarchy.
------------------------------------------------------------------------------------------------------------

Lets go in detail: the hierarchy I am going to use for this is following:



Here I need to delete the data for E1. I wrote below script (I should have taken @relative of "Main" instead of "Entity").

FIX(@REMOVE(@RELATIVE("Entity",0),"E1"))
CLEARBLOCK ALL; 
ENDFIX


Executing above script has deleted all data, including E1 as well. Now, lets find the reason why. Here are the essbase logs after executing the above:

Clearing all data blocks from [(ALL)] partition with fixed members [Entity(E2, E3, E4, E5, E6, E1, E2, E3, E1, E2)]

Even if we have removed E1 from the first list (info: Remove function takes two arguments, two lists, and removes the members from the first list which are present in the second list), its still considering E1 in the fix and will clear the blocks of that! What Essbase has done here is:
First list (@RELATIVE("Entity",0)) gave: E1,E2, E3, E4, E5, E6, E1, E2, E3, E1, E2
Second one gave: E1
Now, because of Remove function it has removed E1 from the fist list(but just one occurrence not all!) and here is the result which you can see in the logs as well:
 E2, E3, E4, E5, E6, E1, E2, E3, E1, E2

While writing the script I thought that it will remove all the occurrences of E1 from the first list.  However, Base Members and Shared Members are treated differently by essbase, it has removed only one occurance and deleted the data for E1 as well and I was doomed!

Now, I wrote the members directly in the List1 (same set of member which I got earlier using @relative zero of entity):
FIX(@REMOVE(@LIST("E1","E2","E3","E4","E5","E6","E1","E2","E1","E2","E3"),@LIST("E1")))
CLEARBLOCK ALL; 
ENDFIX

What you will find the logs is:
Clearing all data blocks from [(ALL)] partition with fixed members [Entity(E2, E3, E4, E5,E6)]

So this time Essbase has removed all the occurrences of E1 from the first list!!!

Now Lets do this:
FIX(@REMOVE(@RELATIVE("Entity",0),@LIST(@RELATIVE("Shared1",0), @RELATIVE("Shared2",0), "E1")))
CLEARBLOCK ALL; 
ENDFIX

List 1: E1,E2,E3,E4,E5,E6,E1(Shared),E2(Shared),E3(Shared),E1(Shared),E2(Shared)
List 2: E1(Shared),E2(Shared),E3(Shared),E1(Shared),E2(Shared),E1

Here is a part of the logs:
Clearing all data blocks from [(ALL)] partition with fixed members [Entity(E2, E3, E4, E5, E6)]

Here is the conclusion: Base Members and Shared Members are treated differently by essbase. Even though when we look in the logs we cant distinguish them by name, Essbase shows them with the same name.

Little more to add:
Even if Essbase shows the member name many times in the Fix but when Essbase actually performs operations it doesn't visit the same block twice. To prove this:

FIX(@REMOVE(@RELATIVE("Entity",0),"E1"))
"A1"=1;
ENDFIX

Here are the logs after the execution of this:

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012668)
Calculating [ Account(A1)] with fixed members [Entity(E2, E3, E4, E5, E6, E1, E2, E3, E1, E2)]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E1]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E2]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E3]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E4]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E5]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012672)
Calculator Information Message: Executing Block - [E6]

[Tue Dec 09 05:49:02 2014]Local/R_Test/Rdb/admin@Native Directory/10348/Info(1012579)
Total Calc Elapsed Time for [2.csc] : [0.032] seconds


Cheers.!!!
Rahul S.

Comments

  1. You can use EXCLUDE instead of @REMOVE. This works fine with Shared members. If you want to do something funky then try @MERGE. MERGE will give you a unique list. you can then try remove :) (not tried this though)

    ReplyDelete
    Replies
    1. Exclude behaves the same way, give it a shot :)

      Delete
    2. If your entity has alternate hierarchies with shared members then in that case @RELAVITVE() will give E1 since it is a level0 member and is shared.

      There is a function called @SHARE which can be used to remove both the primary instance and shared instance like below
      @REMOVE(@RELATIVE("Entity",0),@LIST(@SHARE("E1"),"E1")) This will remove the stored instance and shared instance and will leave you with the remaining list...

      Delete
    3. Exactly! Cameron and Cekvin have discussed this in detail.
      However the point is still same, you have to remove the same member more than once in order to get rid of that completely. Somewhat I tried to explain in second last example.

      Cheers.

      Delete
    4. I think it's because we are talking about @RELATIVE("Entity",0) where it gives all the members relative to a specific hierarchy irrespective of whether the level0 is stored / shared. Have you checked how does the same script behaves if we use @LEVMBRS("Entity",0). Because, if we use @RELATIVE then we can just use only that particular hierarchy(ies) that we want excluding the Shared hierarchy. If it is mix of Stored and shared then it's a different story where we have to use @SHARE

      Delete
  2. Tried a couple of use cases for merge, same results...will try more.

    ReplyDelete
  3. @REMOVE works in a away where the second list will only remove the first instance of the member. Because we are saying remove E1 Stored Member by default. I think we may have to explicity mention to remove the shared instances as well. If we look at @SHARE n the technical reference example, then it talks of @SHARE along with @IDESCENDANTS in @REMOVE to remove all the shared instances....
    I am not sure why it behaves that way...may be it was meant to create that way and since Shared members are just pointers and we may have to explicitly force essbase to exclude using @SHARE which will exclude all the indexes as well while considering the blocks

    ReplyDelete

Post a Comment

Popular posts from this blog

Multiple Navigation Flows are Active

The Member Does Not Exists For The Specified Cube

"Smart View handled an unknown exception thrown by Microsoft Office" Error on Vista, Windows 7, Windows 2008