habibullah.sayyed wrote: ↑
Sat Aug 03, 2019 5:53 am
I want to know what is difference between adding respective variable in prolog and data tab ?
nCounter1 = 1;
nCounter2 = 1;
nCounter3 = 1;
nCounter4 = 1;
My condition is: my variables are in data but I am assigning it in prolog, cause if i keep it in prolog it runs fast so what is the reason?
Some background first.
There are two different types of variables; data source variables, and user defined variables.
The data source variables, as the name suggests, come from the data source. You don't define them as such, other than by specifying the source. These variables are populated with values as each row of data is read from the source. This happens once while executing the code (if any) in the Metadata tab, and then happens once again while executing the code (again if any) in the Data tab. For that reason the values are only available in the Metadata and Data tabs, not the prolog. (Technically, the values of the last row read will still be in the variables in the Epilog tab, but you'd rarely use them there.)
User defined variables are ones like those that you're describing above. They can be defined on any tab, and their value will remain constant until you change them. That is, if you define nCounter1 as being 1 on the Prolog tab, it will still be 1 on the Metadata tab, still 1 on the Data tab, and still 1 on the Prolog tab unless
you have changed it on one of those tabs.
Now to your specific question.
Assigning the variable values in the Prolog does not serve the same purpose as assigning them in the Data tab.
You assign a value in the prolog if you want to initialise a value that will be updated or used later. If, for example you want to keep track of how many rows of data you have processed on your data tab you might set a variable called nCounterRows to 0 in the Prolog, then at the top of the Data tab update the value:
In the Epilog you will therefore have the value available to write to a cube or to a text file.
However if you are setting
in the Data
tab instead, you are setting it back to 1 for each and every row of data
that your process reads. This only makes sense if you are doing something in the Data tab that needs to start counting again from 1 each time a new record is read from the data source.
As for why initialising in the Prolog is so much faster... think about it. The Prolog code executes once, and once only. The Data code executes for every single row of data in your data source. Initialising the value of a variable doesn't take much time, but as the number of data rows goes up, and up, and up, that time adds up.