Page 1 of 1

Help: Asciioutput with Row Number

Posted: Wed Jul 28, 2010 9:10 am
by harrytm1
Hi all,

I need to export a file from a cube so that another system can import the data. That system requires each row in the export file to have a unique record ID. Hence, I'm planning to concatenate the file serial number with a running number for each row to make up the Record ID.

FileSerialNo = '100';

So if the file contains 5 rows of records, Record ID for 1st row will be '1001' and for 5th and last row will be '1005'.

I don't think While loop will work in the Metadata script since each row is inserted after each pass through Metadata. How then do I create a running number?

Many thanks in advance!

Re: Help: Asciioutput with Row Number

Posted: Wed Jul 28, 2010 9:17 am
by David Usherwood
Don't use the metadata tab.
In prolog:
counter = 0;

in data:
counter = counter +1;
asciioutput(
prefix | str(counter,4,0),
<rest of data>
);

The counter will increment each time the data tab is executed ie each time you have a record to output.

Re: Help: Asciioutput with Row Number

Posted: Wed Jul 28, 2010 9:37 am
by harrytm1
thanks for the quick reply, i'll give it a try.

Curious, does it mean i have to move all the scripts in Metadata tab to Data tab? What's the difference?

Re: Help: Asciioutput with Row Number

Posted: Wed Jul 28, 2010 9:47 am
by David Usherwood
TI runs through the datasource once for metadata and again for data. The _idea_ is that you update dimensions in the metadata and content in data. (Note attributes are data, not metadata.)
I don't think putting export code in metadata rather than data will break anything, but I wouldn't see it as best practice. But make sure you don't leave anything behind in the metadata tab otherwise you'll pass through the data source twice.

Re: Help: Asciioutput with Row Number

Posted: Thu Jul 29, 2010 2:39 am
by harrytm1
thanks, David. The Ti is working now. Have a great day!