String Comparison in TI

Post Reply
appleglaze28
Regular Participant
Posts: 269
Joined: Tue Apr 21, 2009 3:43 am
OLAP Product: Cognos TM1, Planning
Version: 9.1 SP3 9.4 MR1 FP1 9.5
Excel Version: 2003

String Comparison in TI

Post 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;



Attachments
textfile security.JPG
textfile security.JPG (17.12 KiB) Viewed 11813 times
csjean
Posts: 40
Joined: Mon Mar 01, 2010 2:53 pm
OLAP Product: TM1
Version: 9.5 9.5.1 9.5.2
Excel Version: 2007

Re: String Comparison in TI

Post 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.
Cheers!

--
Claude-Sebastien Jean
Senior Consultant in Information Technology
Keyrus Canada
www.keyrus.ca
ajain86
Community Contributor
Posts: 132
Joined: Thu Oct 15, 2009 7:45 pm
OLAP Product: TM1
Version: 9.4.1 9.5 9.5.1
Excel Version: 2003 2007

Re: String Comparison in TI

Post 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;
Ankur Jain
ajain86
Community Contributor
Posts: 132
Joined: Thu Oct 15, 2009 7:45 pm
OLAP Product: TM1
Version: 9.4.1 9.5 9.5.1
Excel Version: 2003 2007

Re: String Comparison in TI

Post 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;
Ankur Jain
appleglaze28
Regular Participant
Posts: 269
Joined: Tue Apr 21, 2009 3:43 am
OLAP Product: Cognos TM1, Planning
Version: 9.1 SP3 9.4 MR1 FP1 9.5
Excel Version: 2003

Re: String Comparison in TI

Post 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;
ajain86
Community Contributor
Posts: 132
Joined: Thu Oct 15, 2009 7:45 pm
OLAP Product: TM1
Version: 9.4.1 9.5 9.5.1
Excel Version: 2003 2007

Re: String Comparison in TI

Post 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')@<>'');
Ankur Jain
csjean
Posts: 40
Joined: Mon Mar 01, 2010 2:53 pm
OLAP Product: TM1
Version: 9.5 9.5.1 9.5.2
Excel Version: 2007

Re: String Comparison in TI

Post 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.
Cheers!

--
Claude-Sebastien Jean
Senior Consultant in Information Technology
Keyrus Canada
www.keyrus.ca
appleglaze28
Regular Participant
Posts: 269
Joined: Tue Apr 21, 2009 3:43 am
OLAP Product: Cognos TM1, Planning
Version: 9.1 SP3 9.4 MR1 FP1 9.5
Excel Version: 2003

Re: String Comparison in TI

Post 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 beIF (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.
Attachments
status.JPG
status.JPG (40.56 KiB) Viewed 11715 times
Post Reply