Page 1 of 1
DataStage BASIC functions with variable number of arguments
Posted: Wed Dec 21, 2005 10:37 am
by ArndW
I recall having programmed my own functions with variable numbers of parameters in the past and am faced with a situation here where being able to do that would save large amounts of run-time; but I can't recall how I did it and haven't found anything on the web about this. Does anyone here know how this might be accomplished?
Thanks in advance,
Posted: Wed Dec 21, 2005 10:42 am
by kcbland
Can't remember either, but there's always the array as an argument trick.
Posted: Wed Dec 21, 2005 10:51 am
by ArndW
I suppose that might be an option - but in my case I'd be calling this function from a transform stage and we can't put DIM statements to allocate an array; a dynamic array might work but would be quite unwieldy in this case. I think if I can't get a variable number of arguments sorted out I'll have to resort to something completely different.
I think making a variable number of options involved a special declaration in the code or the compiler options; and then you had to use ASSIGNED() to figure out which arguments had been passed into the function. And all the internal programs which I might use to see what they had done have been compiled with the -I option so that they cannot be VLISTed

Posted: Wed Dec 21, 2005 10:55 am
by chulett
What about creating the routine as taking a fixed number of parameters and then putting a series of transforms over the top of it that take your 'variable number of arguments'. The transform could default / hard code the 'unused' parameters in that case.

Posted: Wed Dec 21, 2005 11:18 am
by ArndW
Craig,
that's a good approach, I like that idea and hadn't approached it from that angle. But in this it wouldn't work because of the extra performance overhead, this routine gets called ~100 Million times per day so I am trying to tweak performance out of the common call. I found that by adding/removing just 2 parameters the CPU overhead gets changed by over 10%.
Posted: Wed Dec 21, 2005 11:24 am
by chulett
Interesting... good luck with that.
Seriously, let us know what you come up with.
Posted: Wed Dec 21, 2005 11:34 am
by ArndW
I think that I might steer away from variable number of arguments even if I do get an answer; since it is most likely not fully documented. I think I will now have one routine with 12 parameters called one time per stage to set up all the environment, then for each of the ~100million daily rows will call the "real" function with just 2 parameters.
Posted: Wed Dec 21, 2005 1:54 pm
by ray.wurlod
I think Ken was referring to the ol' dynamic array as an argument trick. (Indeed, you can use any delimited string, but a field-mark delimited dynamic array gives you more flexible parsing options as well as the hint mechanism for extra speed.)
Posted: Wed Dec 21, 2005 2:15 pm
by kduke
Arnd
I think the trick is in VB when you call a routine. I think it is easier there.