Dynamically checking element exists and inserting it

Post Reply
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Dynamically checking element exists and inserting it

Post by BariAbdul »

I was copying data between two cubes ,there are some elements in source cube which doesn't exists in the target ,Which render "dimension name and element invalid key" error.
I wrote a process to check the each dimension and dynamically insert the element if it doesn't exist.I am struck how to map it with source cube for example
vEle= CellGetS(Scube,Dim1,Dim2,Dim3,Dim4....);
I could able to do it by writing multiple IF statements in the metadata tab:

Code: Select all

sGl= CellGetS ( scube , Dim1 , Dim2 , Dim3 , Dim4,........);

IF(dimix('GL', sGl)=0);

     DimensionElementInsert('GL', '', sGl, 'N');
ENDIF;
But If I want make it dynamic by using while loop,Could gurus please correct me if heading wrong way .Thanks a lot. :?

Code: Select all

iDimCount = 1 ;

vCub='Prod_Reporting';

  While(iDimCount<=1);

   DimNo=TABDIM(vCub,iDimCount);

 EleCount=1;

    While(EleCount<=1);

  EleName=DIMNM(DimNo,EleCount);

  IF
     (DIMIX(DimNo,EleName)=0);

      DIMENSIONELEMENTINSERT(DimNo,'',EleName,'N');
   ENDIF;
  EleCount= EleCount+1;
 END;
iDimCount = iDimCount+1;
END;
"You Never Fail Until You Stop Trying......"
User avatar
qml
MVP
Posts: 1098
Joined: Mon Feb 01, 2010 1:01 pm
OLAP Product: TM1 / Planning Analytics
Version: 2.0.9 and all previous
Excel Version: 2007 - 2016
Location: London, UK, Europe

Re: Dynamically checking element exists and inserting it

Post by qml »

The idea is sound, the execution a little less so.

You don't need two nested loops. You only need one. You want to keep looping until TABDIM starts returning an empty string, the result being the loop running once for every dimension in the cube. Then you just want to check whether the element (represented in the appropriate variable, i.e. Dim1, Dim2, etc. - you need to build a dynamic reference for this variable using your loop counter and the EXPAND function) exists in the dimension and if not, add it.

Right now you have two nested loops constructed in such a way that each one will run just once before your exit condition (counter greater than 1) is met. Think exactly what you want to do and the solution will come.

Also, think about where you will put this code.
Kamil Arendt
BariAbdul
Regular Participant
Posts: 424
Joined: Sat Mar 10, 2012 1:03 pm
OLAP Product: IBM TM1, Planning Analytics, P
Version: PAW 2.0.8
Excel Version: 2019

Re: Dynamically checking element exists and inserting it

Post by BariAbdul »

Thanks QML ,Appreciate your help.
"You Never Fail Until You Stop Trying......"
Post Reply