Page 1 of 1

Populating attribute counter

Posted: Tue Mar 02, 2021 5:45 pm
by samiamsz
Hey, so i have an interface whcih allows users to input items which will be added to a dimension,
I have in my control cube an element called "Sequence" with a numeric value of 1. I have an attribute in the dimension called "ID"
now when the TI runs I want to take that 1 and make it the ID for the first element, then add 1 to the current "Sequence numeric value"

so if the user adds 3 items in the interface i want item 1 to have ID 1, item 2 ID 2, item 3 ID "3". and in the control cube the sequence will now contain "4"

Code: Select all

sElem = TRIM(vVal);
IF(sElem @= '' );
   ITEMSKIP;
ENDIF;

IF (DIMIX(dimCust, sElem) = 0);
#While (DIMIX(dimCust, sElem) = 0);
  sSeq = CELLGETN(CC, 'Customer_Seq', 'Value');
  DIMENSIONELEMENTINSERTDIRECT ( dimCust , '', vVal, 'N');
  DIMENSIONELEMENTCOMPONENTADD(DimCust, sForecastGroup, vVal, 1);
   sSeq = sSeq + 1;
  CELLPUTN(sSeq, CC, 'Customer_Seq', 'Value');
  sNs_Id = 'ZZ_' | NUMBERTOSTRING(sSeq);
 ATTRPUTS(sNS_ID, DimCust, vVal, 'NS_ID');
ENDIF;

this is what my METADATA tab has, originally i had all of

Code: Select all

  CELLPUTN(sSeq, CC, 'Customer_Seq', 'Value');
  sNs_Id = 'ZZ_' | NUMBERTOSTRING(sSeq);
 ATTRPUTS(sNS_ID, DimCust, vVal, 'NS_ID');
in the data tab.
when in data i got an error which was trying to populate all the elements with the same ID
when in metadata i got the error that any element after the first one i not foun in the dimension (even though when I checked it was being added)

Re: Populating attribute counter

Posted: Wed Mar 03, 2021 1:46 pm
by PavoGa
samiamsz wrote: Tue Mar 02, 2021 5:45 pm Hey, so i have an interface whcih allows users to input items which will be added to a dimension,
I have in my control cube an element called "Sequence" with a numeric value of 1. I have an attribute in the dimension called "ID"
now when the TI runs I want to take that 1 and make it the ID for the first element, then add 1 to the current "Sequence numeric value"

so if the user adds 3 items in the interface i want item 1 to have ID 1, item 2 ID 2, item 3 ID "3". and in the control cube the sequence will now contain "4"

Code: Select all

sElem = TRIM(vVal);

IF (DIMIX(dimCust, sElem) = 0);
#While (DIMIX(dimCust, sElem) = 0);
  sSeq = CELLGETN(CC, 'Customer_Seq', 'Value');
  DIMENSIONELEMENTINSERTDIRECT ( dimCust , '', vVal, 'N');
  DIMENSIONELEMENTCOMPONENTADD(DimCust, sForecastGroup, vVal, 1);
   sSeq = sSeq + 1;
  CELLPUTN(sSeq, CC, 'Customer_Seq', 'Value');
  sNs_Id = 'ZZ_' | NUMBERTOSTRING(sSeq);
 ATTRPUTS(sNS_ID, DimCust, vVal, 'NS_ID');
ENDIF;
The CELLPUTN in this case is not committed to the cube until the process completes, while the CELLGETN is reading the committed value in the cube. You are reading and writing the same value on every record. This structure is going to be difficult to implement: not even CELLINCREMENTN will solve it because the transaction is uncommitted.

You need to get the value in the PROLOG, store it to a variable there, increment it and write the Attribute in the DATA procedure and write it to the control cube in the EPILOG. This should do it without using the DimensionElementInsertDirect function in the METADATA tab.

PROLOG:

Code: Select all

nSeq = CellGetN(CC,  'Customer_Seq', 'Value');
METADATA:

Code: Select all

...
DimensionElementInsert(dimCust, '', vVal, 'N');
DimensionElementComponentAdd(dimCust, sForecastGroup, vVal, 1);

...
DATA:

Code: Select all

nSeq = nSeq + 1;
sNs_Id = 'ZZ_' | NUMBERTOSTRING(nSeq);
AttrPutS(sNs_ID, DimCust, vVal, 'NS_ID');
EPILOG:

Code: Select all

CELLPUTN(nSeq, CC, 'Customer_Seq', 'Value');
The DIRECT function is for use in the DATA tab when updating from large datasets and the desire is to not run through them twice. So alternatively:

PROLOG: same as above
DATA:

Code: Select all

...
nSeq = nSeq + 1;
sNs_Id = 'ZZ_' | NUMBERTOSTRING(nSeq);

DimensionElementInsertDirect(dimCust, '', vVal, 'N');
DimensionElementComponentAddDirect(dimCust, sForecastGroup, vVal, 1);

AttrPutS(sNs_ID, DimCust, vVal, 'NS_ID');
...
EPILOG:

Code: Select all

CELLPUTN(nSeq, CC, 'Customer_Seq', 'Value');

# this is recommended when using the Direct update functions.
DimensionUpdateDirect(dimCust);
You could use CellIncrementN in the DATA procedure instead of:

Code: Select all

CELLPUTN(nSeq, CC, 'Customer_Seq', 'Value');
But that is running on every record while doing it in the EPILOG is writing it once.