Page 1 of 1
String Comparison in TI
Posted: Mon Mar 14, 2011 10:03 am
by appleglaze28
I have a problem that maybe you guys can help me out. I want security to be set out once an element is added. So I created a cube with {Groups and a measure as a picklist. The picklist will be the groups available in TM1. The text file as soon in the attachment contains the groups where elements are "WRITE" and the rest is looped as blank or no rights to the element.
I was thinking of firstly doing a conditional statement where the }Groups have attributes and those elements with attributes of "SALES" shall proceed to the next conditional while if not the item is skipped. But I still wasn't able to make out the comparison between the string in the source (attachment) against the DIMNM derived from the looping.
Technically...what's happening is if the Value is not equal to the GroupName it puts an empty on it. However base on the text file they match the group but somehow the code is not recognize the text file and }Groups element as the same.
Wanna know why its not working right.
Code: Select all
pDimension = '}Groups';
index = 1;
NoOfElements= DIMSIZ(pDimension);
GroupName = DIMNM(pDimension, index);
WHILE( index<=NoOfElements);
IF (Value@<>GroupName);
#IF (ATTRS('}Groups', GroupName, 'Department')@='Sales');
CellPutS('','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ELSE;
CellPutS('WRITE','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ENDIF;
#ELSE;
#ITEMSKIP;
#ENDIF;
index = index+1;
END;
Re: String Comparison in TI
Posted: Mon Mar 14, 2011 3:15 pm
by csjean
Hi appleglaze28,
Since you loop through all "}Group" elements with each line of your file, it seems to me that you'll get all <blank> lines except the last line.
If you use the 2 ifs, then you will only get a WRITE if the last line treated is a "Sales" group.
Hope this helps.
Re: String Comparison in TI
Posted: Mon Mar 14, 2011 3:30 pm
by ajain86
You do not need to loop through the }Groups dimension to find out if the string from the file exists in the dimension.
Also, if you want to use your loop, then you will need to put a copy of the GroupName definition inside the While loop so it is updated as you loop through the dimension.
I believe this code should do what you want. Use the DIMIX function.
pDimension = '}Groups';
value = TRIM( value );
IF (DIMIX(pDimension, Value) = 0 );
CellPutS('','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ELSE;
CellPutS('WRITE','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ENDIF;
Re: String Comparison in TI
Posted: Mon Mar 14, 2011 3:30 pm
by ajain86
You do not need to loop through the }Groups dimension to find out if the string from the file exists in the dimension.
Also, if you want to use your loop, then you will need to put a copy of the GroupName definition inside the While loop so it is updated as you loop through the dimension.
I believe this code should do what you want. Use the DIMIX function.
pDimension = '}Groups';
value = TRIM( value );
IF (DIMIX(pDimension, Value) = 0 );
CellPutS('','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ELSE;
CellPutS('WRITE','}ElementSecurity_base_worksheet_so_number',base_worksheet_so_number,Value);
ENDIF;
Re: String Comparison in TI
Posted: Tue Mar 15, 2011 9:16 am
by appleglaze28
Thanks with the help on the previous one...so far all new created elements for my dimension has been created none so I can work with only have WRITE value to be inputted.
Does the loop recognize string? Cause other than that problem I encountered. I have another one whose comparison is a string. Just a lil clarification on why what I did doesn't work would be nice.
So I have a cube which has a status measure for that version has a text, it should move to the next element, however, I think its not moving to the next element. I need to check this so my version data in a version cube wont be lose. This is so I can keep versions of my data from my main data entry cube.
An explanation or alternative way to do this would be very much appreciated.
Code: Select all
NoOfSubmission = DIMSIZ(pStatusDimension);
VersionNo = DIMNM(pStatusDimension, index);
WHILE (index<=NoOfSubmission);
IF(CellGetS(vStatusCubeName,so,VersionNo,'STATUS')@<>'');
IF(CELLISUPDATEABLE(v1CubeName,am,so,VersionNo,value_so_setting)=1);
##### Determines if the cube is updateable, 1 mean its cell can be updated else 0. If Value is 0, then the process will incur and error and will not pass through the succeeding syntax.
IF(VALUE_IS_STRING=0);
##### Determines if the value is numeric or string, 0 mean numeric else string.
CELLPUTN(NValue,v1CubeName,am,so,VersionNo,value_so_setting);
ELSE;
##### Base on the syntax above, the value is numeric therefore CELLPUTN states the value to be inputted is numeric
CELLPUTS(SValue,v1CubeName,am,so,VersionNo,value_so_setting);
ENDIF;
##### Base on the syntax above, numeric value is loaded first then the string.
ENDIF;
ENDIF;
index = index +1;
END;
Re: String Comparison in TI
Posted: Tue Mar 15, 2011 1:16 pm
by ajain86
A loop can definitely work with strings.
You are not using the loops properly. If in a loop a variable will be changing, you need to define it in the loop. From what I understand, your loop is driven by the "VersionNo" variable.
You need to place a copy of its definition inside the loop.
Move the following statement to inside the loop. Place it immediately after the While statement:
WHILE (index<=NoOfSubmission);
VersionNo = DIMNM(pStatusDimension, index);
IF(CellGetS(vStatusCubeName,so,VersionNo,'STATUS')@<>'');
Re: String Comparison in TI
Posted: Tue Mar 15, 2011 8:00 pm
by csjean
ajain86 wrote:A loop can definitely work with strings.
You are not using the loops properly. If in a loop a variable will be changing, you need to define it in the loop. From what I understand, your loop is driven by the "VersionNo" variable.
You need to place a copy of its definition inside the loop.
Move the following statement to inside the loop. Place it immediately after the While statement:
WHILE (index<=NoOfSubmission);
VersionNo = DIMNM(pStatusDimension, index);
IF(CellGetS(vStatusCubeName,so,VersionNo,'STATUS')@<>'');
Hi,
I agree with Ankur.
But, while
moving the statement, you should also
add the statement (on line 1):
Code: Select all
index = 1;
WHILE (index<=NoOfSubmission);
VersionNo = DIMNM(pStatusDimension, index);
IF(CellGetS(vStatusCubeName,so,VersionNo,'STATUS')@<>'');
So your variable will be initialized.
Re: String Comparison in TI
Posted: Wed Mar 16, 2011 4:28 am
by appleglaze28
Thanks...however, I'm just having a lil confusion. I was expecting the loop to go through each element...but it ended up just putting data on the last. ( I tried this out with making my condition be
IF (CellGetS(vStatusCubeName,so,VersionNo,'STATUS')<>@'REJECT');
) When I expected it should put data on all elements that meet the requirements.
Sorry for asking too much help from you guys...never really done looping through an element and loading data. (Still haven't gotten used to the looping for TM1 or programming)
PROLOG
Code: Select all
######### DEFINE CONSTANT VARIABLES #############
index = 1;
pStatusDimension = 'base_submission_version';
vStatusCubeName ='worksheet_status';
vSourceCubeName = 'worksheet';
vTargetCubeName = 'version_worksheet';
pDimensionName = 'base_worksheet_account_manager';
p1DimensionName = 'base_worksheet_so_number';
vSubsetName = am;
v1SubsetName = so;
vViewName = useraccessed;
NoOfSubmission = DIMSIZ(pStatusDimension);
WHILE (index<=NoOfSubmission);
VersionNo = DIMNM(pStatusDimension, index);
IF (CellGetS(vStatusCubeName,so,VersionNo,'STATUS')<>@'REJECT');
ITEMSKIP;
ELSE;
#********TIDY UP VIEW**********
VIEWDESTROY(vSourceCubeName,vViewName);
SUBSETDESTROY(pDimensionName,vSubsetName);
SUBSETDESTROY(p1DimensionName,v1SubsetName);
#******CREATE SUBSET**********
SUBSETCREATE(pDimensionName,vSubsetName);
SUBSETELEMENTINSERT(pDimensionName,vSubsetName,am,1);
SUBSETCREATE(p1DimensionName,v1SubsetName);
SUBSETELEMENTINSERT(p1DimensionName,v1SubsetName,so,1);
#*******CREATE VIEW & ASSIGN SUBSET*********
VIEWCREATE(vSourceCubeName,vViewName);
VIEWSUBSETASSIGN(vSourceCubeName,vViewName,pDimensionName,vSubsetName);
VIEWSUBSETASSIGN(vSourceCubeName,vViewName,p1DimensionName,v1SubsetName);
IF(DTYPE(pDimensionName,am)@='C');
VIEWSETSKIPCALCS(vSourceCubeName,vViewName,0);
ENDIF;
IF(DTYPE(p1DimensionName,so)@='C');
VIEWSETSKIPCALCS(vSourceCubeName,vViewName,0);
ENDIF;
VIEWSETSKIPRULEVALUES(vSourceCubeName,vViewName,0);
ENDIF;
index = index +1;
END;
DATA
Code: Select all
IF(CELLISUPDATEABLE(vTargetCubeName,so,vdate,base_number,am,VersionNo,value_worksheet)=1);
##### Determines if the cube is updateable, 1 mean its cell can be updated else 0. If Value is 0, then the process will incur and error and will not
#pass through the succeeding syntax.
IF(VALUE_IS_STRING=0);
##### Determines if the value is numeric or string, 0 mean numeric else string.
CELLPUTN(NValue,vTargetCubeName,so,vdate,base_number,am,VersionNo,value_worksheet);
ELSE;
##### Base on the syntax above, the value is numeric therefore CELLPUTN states the value to be inputted is numeric
CELLPUTS(SValue,vTargetCubeName,so,vdate,base_number,am,VersionNo,value_worksheet);
ENDIF;
##### Base on the syntax above, numeric value is loaded first then the string.
ENDIF;
I just need the TI to check the status in this cube. If the first submission has a reject then it should use the empty status and load data there and I want the process to stop there. And when the 2nd submission has a reject status...when the process is ran again it should skip the first & second submission. Cause the data shouldnt be overwritten or anything.