Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
antyinteligent
New Contributor

is it possible to nest udfs or use recursion

Hi,

1. Is it possible to nest one udf into another (I wasn't able to do it)? If yes, how?

2. Is it possible to use recursion (this is just a variant of the first question)? If yes, how? -> when I tried it QV expanded the function until it had space and then raised an error: too many iterations or something similar.

Regards

Andrzej

7 Replies

Re: is it possible to nest udfs or use recursion

Please elaborate more practically what you are trying to do and why.

- Marcus

antyinteligent
New Contributor

Re: is it possible to nest udfs or use recursion

hi,

e.g. @recursion: split a string: 'xx xxxxxxxxx xxxx xxxxxxxxxxx xxxxx xxxxxx xxx x x xxxx xxxx' into pieces of 10 characters but so that the split is being done only on spaces

this is just a dummy code to show the concept:

set udf_split= if(len(left($1,index($1,'  ' ,1))<=$2 or len($1)<=$2 or substrincount($1, '  ')=0,

                          trim($1),

                         $(udf_split(left($1,index($1,'  ' ,1),$2))

                              );

FOO:

load

     $(udf_split(dimension)) as MyDim

resident MyTable;

@nesting:

BOO:

load

     $(udf_Outer($(udf_Inner(1,x)))) as Something

resident MyTable;

Re: is it possible to nest udfs or use recursion

This could be done with something like:

load recno() as ID, iterno() as SubID, subfield(String, ' ' , iterno()) as SubString

From Source

while iterno() <= substringcount(String, ' ') + 1;

- Marcus

antyinteligent
New Contributor

Re: is it possible to nest udfs or use recursion

i know it's a bed practice to answer one's comment but i cannot seem to find the edit:

in the udf_split in the 'false' part there should be something storing the left(...) part but that is irrelevant, I'm just interested in the ability to use recursion, the answer can be presented on n!

the output should be something like:

  

xx xxxxxxxxx
123456789101112
xxxx xxxxxxxxxxx
12345678910111213141516
xxxxx xxxxxx
123456789101112
xxx x x xxxx
123456789101112
xxxx
1234

Re: is it possible to nest udfs or use recursion

Sorry, I don't understand what do you want to do. Please give an example in a tabular form like:

source:

Load * inline [

String, OtherFields

.......

],

Output:

F1 ... Fn

values ......

- Marcus

antyinteligent
New Contributor

Re: is it possible to nest udfs or use recursion

1. I really appreciate you're trying to find a workaround but the point is: whether is it possible to use recursion in udfs or nested functions in QV.

2. please imagine:

single dimension, single expression bar chart:

     - dimension name: Animals

     - expression: count(Animals)

Animals:

1. Cat

2. White Cat

3. Very Fluffy White Cat with a Dark spot on the Tail

4. Not So Fluffy Cat

5. Not So Fluffy Cat but also Nice

I have limited space so i would like to use $(udf_split(Animals,9)) instead of Animals and have:

1. Cat

2. White Cat

3.  Very Fluffy

     White Cat

     with a Dark

     spot on the

     Tail

4.  Not So Fluffy

     Cat

5.  Not So Fluffy

     Cat but also

     Nice

regards

Andrzej

Re: is it possible to nest udfs or use recursion

Take a look on this: Re: Loop for Field name.

- Marcus

Community Browser