Page 1 of 1

String While Loop

Posted: Thu Mar 26, 2015 7:41 pm
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.

Re: String While Loop

Posted: Thu Mar 26, 2015 8:33 pm
by jim wood
Moved to the right forum - Admin Team

Re: String While Loop

Posted: Thu Mar 26, 2015 11:56 pm
by rmackenzie
Are you not missing an ENDIF ?

Re: String While Loop

Posted: Fri Mar 27, 2015 12:06 am
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"

Re: String While Loop

Posted: Fri Mar 27, 2015 10:37 am
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.

Re: String While Loop

Posted: Fri Mar 27, 2015 2:31 pm
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

Re: String While Loop

Posted: Fri Mar 27, 2015 4:50 pm
by Wim Gielis
You're welcome, glad it helps.