Eport to ASCII files
-
- Posts: 16
- Joined: Mon Jan 09, 2012 1:59 pm
- OLAP Product: Tm1
- Version: 10.1
- Excel Version: XP
Eport to ASCII files
I have a Ti process which exports data to a text file.
Instead of one big file, I would like it to create several smaller files changing on the department code.
ie: one file per department
The data is NOT in the order of the department code.
Any ideas?
Instead of one big file, I would like it to create several smaller files changing on the department code.
ie: one file per department
The data is NOT in the order of the department code.
Any ideas?
- jim wood
- Site Admin
- Posts: 3961
- Joined: Wed May 14, 2008 1:51 pm
- OLAP Product: TM1
- Version: PA 2.0.7
- Excel Version: Office 365
- Location: 37 East 18th Street New York
- Contact:
Re: Eport to ASCII files
If I was doing this I would order the data source by department. (Easily done if a view is the source). Then the rest is easy. Generate a variable for the file name based on the department and update the ascii out to use the variable as the file source. Job done.
Struggling through the quagmire of life to reach the other side of who knows where.
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
Go Build a PC
Jimbo PC Builds on YouTube
OS: Mac OS 11 PA Version: 2.0.7
-
- MVP
- Posts: 3706
- Joined: Fri Mar 13, 2009 11:14 am
- OLAP Product: TableManager1
- Version: PA 2.0.x
- Excel Version: Office 365
- Location: Switzerland
Re: Eport to ASCII files
Did you look at this very recent thread?
http://www.tm1forum.com/viewtopic.php?f=3&t=6744
It would seem to contain an answer for you.
http://www.tm1forum.com/viewtopic.php?f=3&t=6744
It would seem to contain an answer for you.
-
- Posts: 16
- Joined: Mon Jan 09, 2012 1:59 pm
- OLAP Product: Tm1
- Version: 10.1
- Excel Version: XP
Re: Eport to ASCII files
So easy! Two minutes and it's working.
Interestingly enough I didn't have to order the source and its coming out correctly.
Thank you!
Interestingly enough I didn't have to order the source and its coming out correctly.
Thank you!
-
- Posts: 16
- Joined: Mon Jan 09, 2012 1:59 pm
- OLAP Product: Tm1
- Version: 10.1
- Excel Version: XP
Re: Eport to ASCII files
Although the files all export great, it looks like my headers aren't getting inserted.
If I export one big file, the headers are inserted, but not when I export several files.
This is the code(simplified) in the Data tab:
If (Headers = 0);
Headers = 1;
AsciiOutput(Dir | vmapdept | '.csv','Year','Month','Account','Account No','Account Description','Accpac Dept');
Endif;
AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccID,vAccount,vaccdesc,vbranch);
If I export one big file, the headers are inserted, but not when I export several files.
This is the code(simplified) in the Data tab:
If (Headers = 0);
Headers = 1;
AsciiOutput(Dir | vmapdept | '.csv','Year','Month','Account','Account No','Account Description','Accpac Dept');
Endif;
AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccID,vAccount,vaccdesc,vbranch);
-
- Site Admin
- Posts: 1458
- Joined: Wed May 28, 2008 9:09 am
Re: Eport to ASCII files
You need to write the header for each departmental output file - loop through a subset of dept and write the header to the relevant file.
-
- Posts: 16
- Joined: Mon Jan 09, 2012 1:59 pm
- OLAP Product: Tm1
- Version: 10.1
- Excel Version: XP
Re: Eport to ASCII files
Think I am missing something. Still not exporting with the headers.
I set my counters to 0 in the prolog and then have this in DATA:
#### loop through adding the headers to each file####
sDimName = 'departments';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
#### Set the headers in the output file ####
If (Headers = 0);
Headers = 1;
AsciiOutput(Dir | vmapdept | '.csv','Year','Month','Account No','Account Description','Accpac Dept','Mapped TM1 Dept','Source','Type','User','Batc
h No','Transaction Description','Amount');
Endif;
#### Set the headers in the output file ####
nCounter = nCounter + 1;
END;
#### loop through adding the headers to each file####
#### Exports out all the ASCII files ####
#To not include balance sheet accounts
#IF(VAccount @> '1000');
#AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccount,vaccdesc,vbranch,vmapdept,vsource,vtype,vuser,vbatch,vdesc,vamt);
#ENDIF;
#### Exports out all the ASCII files ####
I set my counters to 0 in the prolog and then have this in DATA:
#### loop through adding the headers to each file####
sDimName = 'departments';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
#### Set the headers in the output file ####
If (Headers = 0);
Headers = 1;
AsciiOutput(Dir | vmapdept | '.csv','Year','Month','Account No','Account Description','Accpac Dept','Mapped TM1 Dept','Source','Type','User','Batc
h No','Transaction Description','Amount');
Endif;
#### Set the headers in the output file ####
nCounter = nCounter + 1;
END;
#### loop through adding the headers to each file####
#### Exports out all the ASCII files ####
#To not include balance sheet accounts
#IF(VAccount @> '1000');
#AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccount,vaccdesc,vbranch,vmapdept,vsource,vtype,vuser,vbatch,vdesc,vamt);
#ENDIF;
#### Exports out all the ASCII files ####
-
- Site Admin
- Posts: 1458
- Joined: Wed May 28, 2008 9:09 am
Re: Eport to ASCII files
You are looping round department, but using the department from the data source for the filename. Use the department you are looping round.
-
- MVP
- Posts: 3706
- Joined: Fri Mar 13, 2009 11:14 am
- OLAP Product: TableManager1
- Version: PA 2.0.x
- Excel Version: Office 365
- Location: Switzerland
Re: Eport to ASCII files
David beat me to it. But here is the complete answer.
Your approach is good EXCEPT that you are not changing the value of your vmapdept variable which I assume you are getting from the data source and will correspond to your "Mapped TM1 Dept" field in the output, and your logic would be better if the While loop was within the test for 1st record condition.
I would suggest that you declare SEPARATE variable for the department file name and set this on each pass through the loop, assuming you only have N level departments in the extract then the code should test for this also. Presently it looks like you are putting in headers but the header row is being repeated and being added only in the first file.
This should fix it:
Your approach is good EXCEPT that you are not changing the value of your vmapdept variable which I assume you are getting from the data source and will correspond to your "Mapped TM1 Dept" field in the output, and your logic would be better if the While loop was within the test for 1st record condition.
I would suggest that you declare SEPARATE variable for the department file name and set this on each pass through the loop, assuming you only have N level departments in the extract then the code should test for this also. Presently it looks like you are putting in headers but the header row is being repeated and being added only in the first file.
This should fix it:
Code: Select all
#### test for the first record of data source ####
If( Headers = 0 );
Headers = 1;
#### loop through adding the headers to each file####
sDimName = 'departments';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
sDept = DimNm(sDimName, nCounter);
#### Set the headers in the output file ####
If( DType(sDimName, sDept) @= 'N' );
AsciiOutput(Dir | sDept | '.csv','Year','Month','Account No','Account Description','Accpac Dept','Mapped TM1 Dept','Source','Type','User','Batch No','Transaction Description','Amount');
Endif;
#### increment the department counter ####
nCounter = nCounter + 1;
END;
EndIf;
-
- Posts: 16
- Joined: Mon Jan 09, 2012 1:59 pm
- OLAP Product: Tm1
- Version: 10.1
- Excel Version: XP
Re: Eport to ASCII files
Starting to feel like I'm not completly undertsanding. Clearly, because now the first file it exports is 100% and thereafter they just have headers.
Starting feel most blonde, but really appreciating the help!
I assume its now got something to do with where I put the actual data ascii output part???
#### test for the first record of data source ####
If( Headers = 0 );
Headers = 1;
#### loop through adding the headers to each file####
sDimName = 'departments';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
sDept = DimNm(sDimName, nCounter);
#### Set the headers in the output file ####
If( DType(sDimName, sDept) @= 'N' );
AsciiOutput(Dir | sDept | '.csv','Year','Month','Account No','Account Description','Accpac Dept','Mapped TM1 Dept','Source','Type','User','Batch No','Transaction Description','Amount');
Endif;
#### increment the department counter ####
nCounter = nCounter + 1;
END;
EndIf;
#### Exports out all the ASCII files ####
#To not include balance sheet accounts
IF(VAccount @> '1000');
AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccount,vaccdesc,vbranch,vmapdept,vsource,vtype,vuser,vbatch,vdesc,vamt);
ENDIF;
#### Exports out all the ASCII files ####
Starting feel most blonde, but really appreciating the help!
I assume its now got something to do with where I put the actual data ascii output part???
#### test for the first record of data source ####
If( Headers = 0 );
Headers = 1;
#### loop through adding the headers to each file####
sDimName = 'departments';
nCounter = 1;
nMaximum = DimSiz(sDimName);
WHILE(nCounter <= nMaximum);
sDept = DimNm(sDimName, nCounter);
#### Set the headers in the output file ####
If( DType(sDimName, sDept) @= 'N' );
AsciiOutput(Dir | sDept | '.csv','Year','Month','Account No','Account Description','Accpac Dept','Mapped TM1 Dept','Source','Type','User','Batch No','Transaction Description','Amount');
Endif;
#### increment the department counter ####
nCounter = nCounter + 1;
END;
EndIf;
#### Exports out all the ASCII files ####
#To not include balance sheet accounts
IF(VAccount @> '1000');
AsciiOutput(Dir | vmapdept | '.csv',vyear,vmo,vAccount,vaccdesc,vbranch,vmapdept,vsource,vtype,vuser,vbatch,vdesc,vamt);
ENDIF;
#### Exports out all the ASCII files ####