3 Replies Latest reply: Jan 14, 2015 2:26 PM by Clever Anjos RSS

    Custom function in Include file

      I know you can have sub routines in an Include file such as...

       

      sub something(param1, param2)

        ...qlikview code

      end sub

       

      Can you put a custom function in an Include file such as...

       

      function GetSP(DocLibrary, DocName)

          Let vTitle = Title;

          Let vLeafName = LeafName;

          Tab1:

             load max(TimeLastWritten) as MAXTimeLastWritten

             from X:\TSollenberger\_QVDs\Layer1\PRD_SP_DocumentInfo.qvd (qvd)

               where tp_Title = '$(vDocLibrary)'

               and LeafName = '$(vDocName)';

       

          LET v_MAXTimeLastWritten = Date(peek('MAXTimeLastWritten'), '$(TimestampFormat)');

       

          GetSP = vMAXTimeLastWritten

       

      end function

       

      Thanks in advance for any assistance.

        • Re: Custom function in Include file
          Ernesto García

          Hi there.

           

          As far as I know there are no user-defined functions in the script, only subroutines.

           

          You can, however, define your functions in a macro module and call them from your script.

           

          Kind regards,

          Rrnesto.

          • Re: Custom function in Include file
            Marcus Malinow

            As Ernesto mentions, functions can be written as macros, however I personally try to avoid macros. One way to achieve something similar might be to write a subroutine, and use it to set a variable. This can then be used in your script.

            • Re: Custom function in Include file
              Clever Anjos

              Easy way is using a Sub, as you are used to setting a variable

               

              Sub GetSP(DocLibrary, DocName)

                  Let vTitle = Title;

                  Let vLeafName = LeafName;

                  Tab1:

                     load max(TimeLastWritten) as MAXTimeLastWritten

                     from X:\TSollenberger\_QVDs\Layer1\PRD_SP_DocumentInfo.qvd (qvd)

                       where tp_Title = '$(vDocLibrary)'

                       and LeafName = '$(vDocName)';

               

                  LET v_MAXTimeLastWritten = Date(peek('MAXTimeLastWritten'), '$(TimestampFormat)');

               

                  LET vGetSPReturn = vMAXTimeLastWritten

               

              end Sub