Page 1 of 1
TM1 function to import a text file
Posted: Wed May 28, 2014 4:38 pm
by vins
Hi All,
I have a TI process which has a data source as "File1.csv" file. I have a requirement to use other file say "File2.csv" in the same TI process.
I Google it and searched to get some function to get this approach. Is there any TM1 function which can import a file within a TI process.
Thanks
Re: TM1 function to import a text file
Posted: Wed May 28, 2014 4:50 pm
by tomok
If the question is can you have one file for the data source and in that same process open up another file, as a second data source, and pull values from the second file into the TI as well then the answer is no.
Re: TM1 function to import a text file
Posted: Wed May 28, 2014 5:19 pm
by Wim Gielis
As Tom said, no.
You could for instance make a second process with File2.csv as the source.
The TI process reads the file and sets up a cube (or similar) to hold the contents of the file or do other manipulations.
Then execute the existing process using the cube as a way to pull data.
Re: TM1 function to import a text file
Posted: Wed May 28, 2014 5:29 pm
by declanr
If the files are in the same format and the TI is to do the same thing to them you can recursively call the TI from itself and use the datasource functions to change the file it looks at (just make sure to add a stop into the recursion.)
Or do a join on the files if possible and query them instead of reading as an ascii source.
Re: TM1 function to import a text file
Posted: Thu May 29, 2014 7:45 am
by Duncan P
It you want to import File2 for use in Proc1 then in what form do you expect it to be available within Proc1? If you just want the file as a raw string then it is possible to write a TI to do that.
If you just want to process File2 during the execution of Proc1 but don't need the results directly in Proc1 then just use ExecuteProcess to call Proc2.
If File1 and File2 are of the same structure and you want to process them in turn then, within a process (called e.g. OuterProc), have an outer process that uses WildcardFileSearch to iterate over "File*.csv" and pass the names you get back to e.g. InnerProc as a parameter. InnerProc should set the name as its datasource and process as normal. This is a little cleaner than recursion for large numbers of files and and leaves you less exposed to stack size limits in the TI execution engine.
Re: TM1 function to import a text file
Posted: Thu May 29, 2014 8:40 am
by dan.kelleher
Just thought I'd add my 2 cents:
If you want to make a TI process dynamic in terms of what file it uses as a data source, set up your process with "File1.csv" as the data source and create a text parameter on the Parameters tab (e.g. psFileName). This will be populated as "File1.csv" or "File2.csv" as appropriate at run-time by whichever way you want to initiate your process (chore, wrapper TI process, command line, Java).
Then put something like the below in your Prolog tab so it's executed before the data source is opened:
Code: Select all
# Obtain TM1 instance directory information
# =================================
vsLogPath = GetProcessErrorFileDirectory;
vsTM1ParentPath = DELET( vsLogPath, SCAN( 'tm1logfiles\', vsLogPath), 12);
# Set data source
# =============
vsDataSource = vsTM1ParentPath | 'filestoimport\' | psFileName;
DatasourceNameForServer = vsDataSource;
This assumes your .csv files are located in a folder in the same directory as the logging directory, but you can change it as necessary.
Dan