ASCII output file that doesnt overwrite

Post Reply
Jefflinde
Posts: 12
Joined: Wed May 25, 2016 2:28 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

ASCII output file that doesnt overwrite

Post by Jefflinde »

I have a current process that loads salary and has checks in place to write an exception file if there are issues with the account and cost center for the person being loaded. the file is written with the below code. PathName is a variable that we are pulling from the systemprocessinfo cube. the issue i am having is if i run the process twice, the second run overwrites and exceptions from the first. How do i get a time stamp on there? I have a variable called timestamp that is using the NOW function but when i try to append that to the file name nothing works.

IF(DIMIX('ApprovalHierarchy', CostCenter)=0);
ErrorFlag=1;
ErrorMsg='Cost Center Does Not Exist';
ASCIIOutput(PathName|'SalaryLoadExistingEmployee.txt',CostCenter,ErrorMsg);
ITEMSKIP;

Variables from Prolog
PathName=CellGetS('SystemProcessInfo','1','Process');
timestamp = TIME;
tomok
MVP
Posts: 2831
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: ASCII output file that doesnt overwrite

Post by tomok »

It's pretty simple, just change your filename to append the time, formatted as a string, to it. I'm not going to write your code for you. Look up the TI function called FormatDate. You can use that, in conjunction with NOW, to get a date string the way you want it, then just append it to 'SalaryLoadExistingEmployee' and then '.txt' for your filename.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: ASCII output file that doesnt overwrite

Post by Wim Gielis »

Or, as an alternative to FormatDate, consider the Timst function. That's not difficult at all.
Best regards,

Wim Gielis

IBM Champion 2024
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
Wim Gielis
MVP
Posts: 3105
Joined: Mon Dec 29, 2008 6:26 pm
OLAP Product: TM1, Jedox
Version: PAL 2.0.9.18
Excel Version: Microsoft 365
Location: Brussels, Belgium
Contact:

Re: ASCII output file that doesnt overwrite

Post by Wim Gielis »

Here is code for you.

Code: Select all

# Result: 2017-03-26 21:03:19

vNow = Timst( Now, '\Y-\m-\d \h:\i:\s' );
AsciiOutput( 'test.txt', vNow );


# Result: 2017-03-26 21:03:19

q = NewDateFormatter( '' );
vNow = FormatDate( Now, 'y-LL-dd HH:mm:ss', q );

AsciiOutput( 'test.txt', vNow );


# Result: 20170326 210319

q = NewDateFormatter( '' );
vNow = FormatDate( Now, 'yLLdd HHmmss', q );

AsciiOutput( 'test.txt', vNow );

I do like the NewDateFormatter approach as it is so flexible.
You have to call that function only once, at the beginning of the Prolog tab for example.
It has 5 arguments, of which the first HAS to be provided (although you can leave it empty),
the other 4 arguments are optional and can be skipped (knowing the default values you can end up with).

Important notions about NewDateFormatter:
1.
The line of code must be executed BEFORE the first FormatDate or ParseDate function !
If the NewDateFormatter value is initialized for the first time as the last argument in either function, it does not work

2.
Functions like NOW give a result that is to be interpreted with UTC times:
http://www.tm1forum.com/viewtopic.php?t=10196
so the parameter <TimeZone> should be left empty (or be 'Etc/UTC') unless some times from other timezones are to be interpreted
Best regards,

Wim Gielis

IBM Champion 2024
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
Jefflinde
Posts: 12
Joined: Wed May 25, 2016 2:28 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Re: ASCII output file that doesnt overwrite

Post by Jefflinde »

This is perfect. thank you all of you for the great advice. i am pretty new at TM1 if you could not tell from question. I am slowing figuring out all the quirks.

thanks again everyone.
Jefflinde
Posts: 12
Joined: Wed May 25, 2016 2:28 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Re: ASCII output file that doesnt overwrite

Post by Jefflinde »

Ok, one more question. is there a process that creates a new file instead of adding to an existing one. Or maybe i am doing it wrong which is very likely. My process is now erring out because the file name with date can not be found.

thank you

Jeff
User avatar
Steve Rowe
Site Admin
Posts: 2410
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: ASCII output file that doesnt overwrite

Post by Steve Rowe »

This most often happens because the file you are writing to is open in another application (excel). When its says it can't find it what it means is I can't write to this location.
Technical Director
www.infocat.co.uk
tomok
MVP
Posts: 2831
Joined: Tue Feb 16, 2010 2:39 pm
OLAP Product: TM1, Palo
Version: Beginning of time thru 10.2
Excel Version: 2003-2007-2010-2013
Location: Atlanta, GA
Contact:

Re: ASCII output file that doesnt overwrite

Post by tomok »

Jefflinde wrote:Ok, one more question. is there a process that creates a new file instead of adding to an existing one. Or maybe i am doing it wrong which is very likely. My process is now erring out because the file name with date can not be found.
Have you verified that the file name you are creating is valid? How about the path, is it valid? If TM1 says the file can not be found that likely means because it could not create it. Probably because 1) you didn't specify a valid path, 2) the account the TM1 service runs under does not have windows security rights to the folder you specified, or 3) the file name you created is not a valid Windows file name.
Tom O'Kelley - Manager Finance Systems
American Tower
http://www.onlinecourtreservations.com/
Jefflinde
Posts: 12
Joined: Wed May 25, 2016 2:28 pm
OLAP Product: TM1
Version: 10.2.2
Excel Version: 2013

Re: ASCII output file that doesnt overwrite

Post by Jefflinde »

Thanks again everyone. i had a semi colon in the file name that i could not see until i dumped the string into a text editor. so i deleted and retyped it. All is now right in my little world.
Post Reply