Page 1 of 1

Dynamically checking element exists and inserting it

Posted: Mon Mar 09, 2015 5:31 pm
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;

Re: Dynamically checking element exists and inserting it

Posted: Mon Mar 09, 2015 5:54 pm
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.

Re: Dynamically checking element exists and inserting it

Posted: Tue Mar 10, 2015 2:38 pm
by BariAbdul
Thanks QML ,Appreciate your help.