String While Loop

Post Reply
Mems
Posts: 58
Joined: Thu Apr 14, 2011 12:27 pm
OLAP Product: TM1
Version: v10.2.2
Excel Version: 2010
Location: South Africa

String While Loop

Post by Mems »

I have to add string data to a cube.

The code has to do the following - scan through cube, if the combination of location and classification exist on a line item .
Then itemskip else, add the string values to the next open line item.

The sequence number below is based on the following logic. Each planning entity has 200 line items.
eg will be 'Aviation_1'

I played around with the below code and got 2 answers. Either data gets stored at the seqnumber 200 or at all of the seqnumber.

Code: Select all

nCount = 1;
nMax = 200;
WHILE( nCount <= nMax );

sSNR = Subst(sSeqNumber,1,Scan('_',sSeqNumber))|NumbertoString(ncount);

		IF(CellGetS(sTargetCube,
		CellGetS(sParamCube,'CurrentReportingPeriod','Value'),sExpType,
		sReportingVersion,
		sSNR ,'Locations') @= sLocation 
		&
		CellGetS(sTargetCube,
		CellGetS(sParamCube,'CurrentReportingPeriod','Value'),sExpType,
		sReportingVersion,
		sSNR ,'Classification') @= sClassification));

ITEMSKIP;

ELSE;

		IF(CellGetS(sTargetCube,
		CellGetS(sParamCube,'CurrentReportingPeriod','Value'),sExpType,
		sReportingVersion,
		sSNR ,'Locations') @= '');

		CellPutS(sLocation,sTargetCube,
		CellGetS(sParamCube,'CurrentReportingPeriod','Value'),sExpType,
		sReportingversion,
		sSNR ,'Locations');

ENDIF;

	nCount = nCount + 1;
END;
Any advice.
MEMS
User avatar
jim wood
Site Admin
Posts: 3961
Joined: Wed May 14, 2008 1:51 pm
OLAP Product: TM1
Version: PA 2.0.7
Excel Version: Office 365
Location: 37 East 18th Street New York
Contact:

Re: String While Loop

Post by jim wood »

Moved to the right forum - Admin Team
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
rmackenzie
MVP
Posts: 733
Joined: Wed May 14, 2008 11:06 pm

Re: String While Loop

Post by rmackenzie »

Are you not missing an ENDIF ?
Robin Mackenzie
User avatar
Steve Rowe
Site Admin
Posts: 2464
Joined: Wed May 14, 2008 4:25 pm
OLAP Product: TM1
Version: TM1 v6,v7,v8,v9,v10,v11+PAW
Excel Version: Nearly all of them

Re: String While Loop

Post by Steve Rowe »

I'd also be inclined not to itemskip out of a while loop, just from a desire to treat TM1 and TI "gently"
Technical Director
www.infocat.co.uk
Wim Gielis
MVP
Posts: 3240
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: String While Loop

Post by Wim Gielis »

Steve Rowe wrote:I'd also be inclined not to itemskip out of a while loop, just from a desire to treat TM1 and TI "gently"
I like the use of the Break function to stop the execution of loops.
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Mems
Posts: 58
Joined: Thu Apr 14, 2011 12:27 pm
OLAP Product: TM1
Version: v10.2.2
Excel Version: 2010
Location: South Africa

Re: String While Loop

Post by Mems »

Thanks gents the break section worked perfectly!!

Its a bit hard coded at the moment, but it works.

Code: Select all

nCount = 1;
nMax = 200;
WHILE( nCount <= nMax );

sSNR = Subst(sSeqNumber,1,Scan('_',sSeqNumber))|NumbertoString(ncount);

		IF(CellGetS('Budget Entry - Information',
		CellGetS('Global Control','CurrentReportingPeriod','Value'),'Operational',
		ATTRS('Planning Entity',sPE,'Version'),
		sSNR ,'Locations') @= sLocation 
		&
		CellGetS('Budget Entry - Information',
		CellGetS('Global Control','CurrentReportingPeriod','Value'),'Operational',
		ATTRS('Planning Entity',sPE,'Version'),
		sSNR ,'Classification') @= sClassification);


BREAK;

ENDIF;

ASCIIOUTPUT('Info1.csv',sSNR,SloCation,sClassification);

IF(ncount = 200);

ASCIIOUTPUT('Info2.csv',sSNR,SloCation,sClassification);


nCountempty = 1;
nMax = 200;
WHILE( nCountempty <= nMax );

sSNRempty = Subst(sSeqNumber,1,Scan('_',sSeqNumber))|NumbertoString(ncountempty);

		IF(CellGetS('Budget Entry - Information',
		CellGetS('Global Control','CurrentReportingPeriod','Value'),'Operational',
		ATTRS('Planning Entity',sPE,'Version'),
		sSNRempty ,'Locations') @= '');

ASCIIOUTPUT('Info3.csv',sSNRempty,SloCation,sClassification);




BREAK;

ENDIF;




	nCountempty = nCountempty + 1;

END;

		CellPutS(sClassification,'Budget Entry - Information',
		CellGetS('Global Control','CurrentReportingPeriod','Value'),'Operational',
		ATTRS('Planning Entity',sPE,'Version')
		,sSNRempty ,'Classification');

		CellPutS(sLocation,'Budget Entry - Information',
		CellGetS('Global Control','CurrentReportingPeriod','Value'),'Operational',
		ATTRS('Planning Entity',sPE,'Version')
		,sSNRempty ,'Locations');

CellPutN(CellGetN(sTgtCube,'Actuals',sYear,vExpType,sMonth,ATTRS('Planning Entity',sPE,'Version'),sLocation,sClassification,sSeqNumber,'Value')+value,
sTgtCube,'Actuals',sYear,vExpType,sMonth,ATTRS('Planning Entity',sPE,'Version'),sLocation,sClassification,sSeqNumber, 'Value');

ASCIIOUTPUT('Info4.csv',sSNRempty,SloCation,sClassification);
ENDIF;



	nCount = nCount + 1;

END;
I'm sure some of you folks could narrow this down to a few line, but I am happy :D :D :D :D :D :D :D :D :D
MEMS
Wim Gielis
MVP
Posts: 3240
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.1.5
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: String While Loop

Post by Wim Gielis »

You're welcome, glad it helps.
Best regards,

Wim Gielis

IBM Champion 2024-2025
Excel Most Valuable Professional, 2011-2014
https://www.wimgielis.com ==> 121 TM1 articles and a lot of custom code
Newest blog article: Deleting elements quickly
Post Reply