Page 1 of 1

Using EXPAND function for dynamic code

Posted: Thu Jan 15, 2015 1:28 pm
by fleaster
Ok, so I know you can use EXPAND to extract variables dynamically... e.g. :

Code: Select all

Ref = 'V1' ;
Customer = EXPAND( '%' | Ref | '%' );
...this works, but if I want to add an additional piece of code to the mix:

Code: Select all

Ref = 'Trim(V1)' ;
Customer = EXPAND( '%' | Ref | '%' );
...it errors out with : Variable "Trim(V1)" not found

So what I'd like to know is if there is a way/syntax to leverage the EXPAND function to pass more complex code for variables in a TI process?

Note: this is in the context where you may have different file layouts, and different treatment for each field e.g. you may want to Trim Field1, take the 1st 3 characters of Field2, do an IF function on Field3 etc etc - so wanted to see if there is a way this could be parameterized via lookup cube containing the code strings

Thanks!

Matt

Re: Using EXPAND function for dynamic code

Posted: Thu Jan 15, 2015 1:45 pm
by BrianL
Sorry, EXPAND will only replace variable names with their contents. It cannot be used to run arbitrary TI code.

Re: Using EXPAND function for dynamic code

Posted: Thu Jan 15, 2015 2:01 pm
by fleaster
dang... ok there goes my plans for world domination :(

Re: Using EXPAND function for dynamic code

Posted: Thu Jan 15, 2015 3:21 pm
by lotsaram
Not clear what you want to do but you can nest Expand functions, e.g. inner expand derives variable name from concatenation of root string and integer counter, outer expand returns the value of the returned variable name from the inner.

Re: Using EXPAND function for dynamic code

Posted: Thu Jan 15, 2015 11:32 pm
by fleaster
So this is in the case if you wanted to retrieve a range of variables like "V1", "V2", "V3" etc...

...my issue is if you want to store more complex formula strings i.e. I have multiple import files which have the same field layouts, but depending on the source of the file, the treatment of the same field may be different

e.g. for Field #1, I may want to Trim it for one file, for another I want to assign "NA" if it's blank, for another I may want to add a fixed prefix etc:
"Trim(V1)" / "IF(V1@='','NA',V1)" / " 'abc123' | V1"

Now it's easy enough to add multiple IF functions, but these would be hardcoded - so am trying to see if the formula strings can be held in a parameter cube so that whenever a new file comes up, we can just update the parameters instead of amending the code.

Re: Using EXPAND function for dynamic code

Posted: Sat Jan 17, 2015 5:41 pm
by lotsaram
Expand just allows for getting the value of a variable from a string of the variable name. You can't "expand" strings into functional code though as the function is limited to variables only.

Your idea is interesting though. Provided that the set of possible conditions and treatments per field was known in advance then it would be possible to build a process with the kind of logic you are talking about, just by testing values and if statements no need for expand. Of course it wouldn't be infinitely flexible like what you are really talking about but maybe it's an option.

Re: Using EXPAND function for dynamic code

Posted: Sun Jan 18, 2015 11:59 pm
by RJ!
Would the JAVA extensions help in this case?

i.e. solve the "expand" in JAVA and bring it back to TI?