Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

Not applicable

Can create a function ?

Hi,

I try to know how I can call a function.

ex:

I make a table:

LOAD

    *

FROM

    Documents



and now I want to use this table in each other table I have without copy/past. Until now I put this table into a variable and I wonder if is it work.

Regards

Tags (3)
19 Replies

Re: Can create a function ?

Not sure that I understand your question.  Could you clarify ?

Not applicable

Re: Can create a function ?

Actually I try to show all error that my apply can make. And I have this:

SET vError = FIRST 1 CONCATENATE(ERROR) LOAD

  COUNTRY_CODE,

  '$(NbRows)' as NB_ROWS,

  '$(ScriptErrorCount)' as ERROR_SEQ_NUMBER,

  '$(#ScriptError)' as ERROR_ID,

  '$(ScriptError)' as ERROR_NAME,

  '$(ScriptErrorDetails)' as ERROR_DETAIL,

  '$(ScriptErrorList)' as ERROR_LIST,

  now() as ERROR_DATE

resident COUNTRY;



I want to put this script into every table I have to check and put into a table. And i wonder if this way to work is correct or there's other way to make it.

Re: Can create a function ?

Simply use an alias as a name for the table:

MyTable:

LOAD

    *

FROM

    Documents;

Now you can use MyTable for example:

Load * resident MyTable;

undergrinder
Valued Contributor II

Re: Can create a function ?

Hi!

If you specify your problem, then we may help you.

You can create a function with a VB like script.

eg:

Sub function ()

    LOAD

        *

    FROM

        Documents

end sub


call function



In Chart and function guide there is some example (https://help.qlik.com/sense/en-us/pdf/Script%20Syntax%20and%20Chart%20Functions%20Guide.pdf)

I'm not sure, that is it, what you want.

HTH

G.

Re: Can create a function ?

Variables can hold a single value, it doesn't store the table.

You have load the table and keep a name for that and use as needed.

To use previously loaded table into memory then

Load *

Resident TableName;

Not applicable

Re: Can create a function ?

Then, I have to write this table each time I have to use? Because, actually I have to manage a lot of table and if I put this table in each table, the day that I have to correct it will be a little complexe no ?

Re: Can create a function ?

What is your expectation, how you are going to use this table?

Not applicable

Re: Can create a function ?

SET vError = FIRST 1 CONCATENATE(ERROR) LOAD

  COUNTRY_CODE,

  '$(NbRows)' as NB_ROWS,

  '$(ScriptErrorCount)' as ERROR_SEQ_NUMBER,

  '$(#ScriptError)' as ERROR_ID,

  '$(ScriptError)' as ERROR_NAME,

  '$(ScriptErrorDetails)' as ERROR_DETAIL,

  '$(ScriptErrorList)' as ERROR_LIST,

  now() as ERROR_DATE

resident COUNTRY;


//**********************************************************************//


my_table1:

load

    *

From

    Documents;


SET vError;


my_table2:

load

    *

From

    Documents;


SET vError;


my_table3:

load

    *

From

    Documents;


SET vError;


/****************************************************/


I have this, I want to know if there's something to call  "SET vError" as a variable can only have a single value.

Is it mandatory to put "SET vError" table in every tables ?

MVP & Luminary
MVP & Luminary

Re: Can create a function ?

In general such an approach will work with:

SET vError = "CONCATENATE(ERROR)

LOAD FIRST 1

  COUNTRY_CODE,

  '$(NbRows)' as NB_ROWS,

'$(ScriptErrorCount)' as ERROR_SEQ_NUMBER,

  '$(#ScriptError)' as ERROR_ID,

  '$(ScriptError)' as ERROR_NAME,

'$(ScriptErrorDetails)' as ERROR_DETAIL,

  '$(ScriptErrorList)' as ERROR_LIST,

  now() as ERROR_DATE

resident COUNTRY;"

and called simply with:

$(vError)

but the syntax-checker won't recognize them as correct and it is not flexible. Therefore I suggest you to put this into a include-variable and extended it to a generic table like:

include-file:

let vLoadTable = TableName(NoOfTables() - 1);

CONCATENATE(ERROR)

LOAD FIRST 1

  COUNTRY_CODE,

  '$(NbRows)' as NB_ROWS,

'$(ScriptErrorCount)' as ERROR_SEQ_NUMBER,

  '$(#ScriptError)' as ERROR_ID,

  '$(ScriptError)' as ERROR_NAME,

'$(ScriptErrorDetails)' as ERROR_DETAIL,

  '$(ScriptErrorList)' as ERROR_LIST,

  now() as ERROR_DATE

resident $(vLoadTable);

and adds maybe some more useful informations like documentname(), today() ... and so on - see for include: The $(Include) which you $(Must_Include) into your toolkit

- Marcus