Page 1 of 1

IF Statement

Posted: Mon Feb 27, 2017 3:28 pm
by ravi
Hi All,
I am trying code with two if statements one- IFCellsupdatable and other one if CellputN IFvAccount.
I am not able to save and execute TI process after the multiple try "END" out of place problem. I thought to take your suggestion to know where I am making mistake.

IF(CellIsUpdateable(TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod) =1);
ELSE;
IF(vAccount @= '620000' );
CellPutN(Value,TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod);
ENDIF;
IF(CellIsUpdateable(TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod)=1);
ELSE;
IF(vAccount @= '640000' );
CellPutN(Value,TargetCube, elmCurrency, elmSource, vAccount, elmLOB2, elmEntity2, elmVersion, elmMeasure, elmPeriod);

ENDIF;

END;

Thanks

Re: IF Statement

Posted: Mon Feb 27, 2017 4:27 pm
by Steve Rowe
End is for while loops not if statements....

Re: IF Statement

Posted: Mon Feb 27, 2017 6:02 pm
by Mark RMBC
If simply removing the End makes that code logical then I really do not know as much as I think i do, and I don't think I know that much anyway!

Assuming you have provided all the code and not just some snippet then I reckon the code needs to look something like or along the lines of,

IF(CellIsUpdateable(TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod) =1);
IF(vAccount @= '620000' );
CellPutN(Value,TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod);
Elseif(vAccount @= '640000' );
CellPutN(Value,TargetCube, elmCurrency, elmSource, vAccount, elmLOB2, elmEntity2, elmVersion, elmMeasure, elmPeriod);
ENDIF;
ENDIF;

Though other than the obvious what concerns me is, and again assuming this is the code in all its glory, that if you are hard coding the vAccount why wouldn't you simply hard code '620000' and '640000' in the CellPutN rather than have the if? Also you have 2 celisupdateables in your code which are identical, yet the cellputn's are different?

Actually given these concerns forget about my code above because the CellisUpdateable makes no sense to me!

Apologies if I have in anyway confused the matter.

Regards, Mark

Re: IF Statement

Posted: Mon Feb 27, 2017 6:43 pm
by ravi
Hi Mark,

Sorry for any confusion. I used the Cellsupdatable function - just make sure we do not get the rule applies to cell error while running the TI.
after one more try- I changed the code &(Ampersand)

IF(CellIsUpdateable(TargetCube,
elmCurrency,
elmSource,
vAccount,
elmLOB1,
elmEntity1,
elmVersion,
elmMeasure,
elmPeriod) =1 & vAccount @= '620000');

CellPutN(Value, TargetCube, elmCurrency, elmSource, vAccount, elmLOB1, elmEntity1, elmVersion, elmMeasure, elmPeriod);

ENDIF;

This works fine now- thank you

Re: IF Statement

Posted: Tue Feb 28, 2017 2:06 pm
by pandinus
Performance wise it might be better to split the IF statement:

Code: Select all

IF(vAccount @= '620000');
  IF(CellIsUpdateable(...)=1);
    # Do things
  ENDIF;
ENDIF;
This way the CellIsUpdateable check is only performed when vAccount equals 620000 and not for every item in your Data tab.

Of course the absolute impact on performance will probably be negligible, but every little bit helps...