Create date element with date attributes
Posted: Fri Oct 28, 2016 12:02 pm
Greetings all.
I'm building a weekly cash forecast model and I've created a TI process that will roll the week forward every week, creating a new element in the Weekly Forecast Dimension for the following week.
After a lot of trial and error (mainly due to the fact that I first used elements in the format dd/mm/yyyy and now in format yyyy-mm-dd) I've got something that works but I can't help feeling it could be a lot simpler. I'm having to strip the current week's date down to Year, Month and Date, then add 7 to get next week, and then strip the new date back into Year, Month and Date (adding 2000 to the year to get it into 4 digits) to build the date string back up again.
Prolog:
Epilog:
Have I missed a really easy way to do this? (Or should I just shut up and be happy that I've got something that works?!)
I'm building a weekly cash forecast model and I've created a TI process that will roll the week forward every week, creating a new element in the Weekly Forecast Dimension for the following week.
After a lot of trial and error (mainly due to the fact that I first used elements in the format dd/mm/yyyy and now in format yyyy-mm-dd) I've got something that works but I can't help feeling it could be a lot simpler. I'm having to strip the current week's date down to Year, Month and Date, then add 7 to get next week, and then strip the new date back into Year, Month and Date (adding 2000 to the year to get it into 4 digits) to build the date string back up again.
Prolog:
Code: Select all
#
# Create a new element for Next Week's forecasts
#
pOldWeek = CellGetS('Accounting_Period','Current Week','Week');
pNewWeek = CellGetS('Accounting_Period','Next Week','Week');
DimensionElementInsert ( 'FcastWk', '',pNewWeek,'N');
#
# Calculate new value of the following week's date for Next Week attribute on new element
#
pYear = NUMBR(SUBST(pNewWeek,1,4));
pMonth = NUMBR(SUBST(pNewWeek,6,2));
pDate = NUMBR(SUBST(pNewWeek,9,2));
pNewDate = DayNo(DateS(pYear,pMonth,pDate))+7;
pNewDate2 = DATE(pNewDate);
nYear = 2000+NUMBR(STR(YEAR(pNewDate2),4,0));
nMonth = MONTH(pNewDate2);
nDate = DAY(pNewDate2);
sNewDate = DATES(nYear,nMonth,nDate);
Code: Select all
AttrPutS(pOldWeek, 'FcastWk',pNewWeek, 'PriorWk');
AttrPutS(sNewDate, 'FcastWk',pNewWeek, 'NextWk');
CellPutS(pNewWeek,Accounting_Period','Current Week','Week');
CellPutS('READ','}ElementSecurity_FcastWk',pOldWeek,'Manager');
CellPutS('WRITE','}ElementSecurity_FcastWk',pNewWeek,'Manager');