Page 1 of 1

Leading zeros in AsciiOutPut being dropped

Posted: Thu Aug 29, 2019 5:45 am
by CRP0021
Hello everyone,
Just a quick question as I'm dealing with an issue which I'm sure has been solved but can't seem to find anything on this.

I'm doing an ASCIIOUTPUT and one of the fields is an account dimension. This account dimension has 6 digits and various accounts include leading zeros i.e. 000123, 000456, etc.

When exporting to .csv and opening the exported file it drops the leading zeros so the result of this account dim is 123, 456, etc.

Normally I'd output to a .txt and it wouldn't matter but the intent is to grab data from the .csv and copy and paste it to an upload file to an external system.

The account dim that I am exporting is being read from the variables tab on the TI i.e. vAccount.
The ASCIIOutPut looks like this ( sFile, vAccount, aaa, bbb, ccc, etc.)

The .csv I am exporting from TM1 is laid out exactly in the order and format required to make the copy/paste function fairly simple except for this small nuisance of the leading zeros being dropped.

Any advice would be much appreciated!
Cheers

Re: Leading zeros in AsciiOutPut being dropped

Posted: Thu Aug 29, 2019 5:54 am
by Wim Gielis
Do not open the csv with Excel but rather Notepad++

Re: Leading zeros in AsciiOutPut being dropped

Posted: Thu Aug 29, 2019 6:54 am
by lotsaram
I'm pretty sure Wim is correct and this is just Excel trying to be "helpful" by converting anything that looks like a number into a number. This is decidedly unhelpful when dealing with date strings and account numbers.

If you open in notepad you can verify pretty easily that the account numbers are actually written to the file correctly but text editors are not great when you need to do things like insert or remove columns. To be able to edit the file in Excel don't just open it, use the "import from text file" function then you can specify to treat the column as text and not number.

Also be careful if you then save from Excel that your locale setting for CSV delimiter is the same as the original. We always have issues with users replacing commas with semi-colons and vice versa.

Re: Leading zeros in AsciiOutPut being dropped

Posted: Thu Aug 29, 2019 10:48 am
by tomok
Here's a better idea (at least I think so). Don't give your output file the .csv extension, use .txt or anything else. That way when you open it in Excel it will ask you how you want all the columns defined and then you can say "Text" for the Account column, which will leave your leading zeros. When you open a file in Excel with the .csv extension it doesn't ask you the format and just assumes anything numeric is a number and formats it as such, meaning you lose the leading zeros.

Re: Leading zeros in AsciiOutPut being dropped

Posted: Sat Aug 31, 2019 9:35 am
by Wim Gielis
Or, if your goal is to open in Excel rather than Notepad, do an AsciiOutput like for example:

Code: Select all

AsciiOutput( 'test.csv', vCostCenter, '=' | Char(34) | vAccount | Char(34), NumberToString( vValue ));
Ascii character 34 is a double quote so this is equivalent but somewhat more difficult to write:

Code: Select all

AsciiOutput( 'test.csv', vCostCenter, '="' | vAccount | '"', NumberToString( vValue ));
Have a look at DataSourceAsciiDelimiter and DataSourceAsciiQuoteCharacter as well.

Originally posted here: http://www.wimgielis.com/tm1_asciioutputtoexcel_EN.htm