How to Create a Header Row with AsciiOutput
Asciioutput is a great way to export data from TM1. The problem with it is that it does not automatically add a header row at the top of the file with column names. Here is a simple method to add a header line to a text file created by TM1 that can describe the data in columns below.
The column headings are useful for uploading into an external database with confidence that each column is what you expect and also can form the identifiers in a subsequent TI to reload the data into TM1.
Method to Create a Header Row in AsciiOutput
So how do I add a row of column headers into a text file created by TM1? Pretty easily really.
On the Prolog tab I defined a variable, lets call it vHeader and made it equal to 1.
Example of Putting a Header Line into a Text File Output from TM1
So something like this. Note in this example we have defined variables for the path and filenames already and we have variables defined for vData1 etc. as well. This will insert the header row into the first row of the text file:
nHeader = 1;
Data or Metadata Tab
IF ( nHeader = 1); AsciiOutput ( vPath | vFile, 'heading1', 'heading2', 'heading3'… 'headingN'); nHeader = nHeader + 1; ENDIF; AsciiOutput ( vPath | vFile, vData1, vData2, vData3… vDataN);
What this does is set up the variable in the Prolog, then tests if the variable equals 1. This will be true for the first record only. It then inserts into vFile at vPath the header row as defined.
Then the variable is incremented by 1 so it will no longer satisfy the IF test.
Finally, the regular AsciiOutput dumps out the data as required.