15 Replies Latest reply: Feb 27, 2015 3:57 AM by Joseph Simmons RSS

    Trouble with an IF THEN clause

    Friedrich Hofmann

      Hi,

       

      I'm still having trouble with an app I have to check the presence of files (and their number and name) in a certain directory - that's just to make sure the correct nr. of files with the correct names is there because some other apps depend on that, and to send email_alerts to the responsibles if that is not the case.

       

      One part of the code in this app is conditionalized to only run on Fridays - it checks a specific subdirectory where the files for the next week should always be stored, and it isn't reasonable to expect those files to be there before Friday. So I want the check to only run on a Friday.

      What happened today - and the two last weeks - was that the code did not run on Fridays. When I go through it in the Debugger, it jumps straight to the ENDIF (at the very end of the tab), so the code inbetween is seemingly not being executed.

      I can post the code here (I'll attach it) though it won't work for you, there is a number of filepath_variables involved.

       

      Can anybody help me with that?

      Thanks a lot!

      Best regards,

       

      DataNibbler

        • Re: Trouble with an IF THEN clause
          Marcus Sommer

          Hi DataNibbler,

           

          weekday returned a numeric value - therefore it should be:

           

          IF Weekday(Today(0)) = 4 THEN

          ...

           

          - Marcus

            • Re: Trouble with an IF THEN clause
              Friedrich Hofmann

              Hi,

               

              that crossed my mind too - but I tested it both on the GUI (there the Weekday() fct did return 'Fri') and also in the script - I tested in a small test_app with just some arbitrary load in that same IF THEN clause - and that worked ... Now I'll try putting it in a qvs file for an INCLUDE - maybe there is too much happening inside that clause (there is a loop and some variables and whatnot)

               

              Best regards,

               

              DataNibbler

                • Re: Trouble with an IF THEN clause
                  Marcus Sommer

                  Hi DataNibbler,

                   

                  this could be - I think it will be depend on the settings from:

                   

                  SET DayNames='Mo;Di;Mi;Do;Fr;Sa;So';

                   

                  - Marcus

                    • Re: Trouble with an IF THEN clause
                      Friedrich Hofmann

                      Yep, sure it depends on that - but the settings are just so (Mon;Tue;Wed;Thu;Fri;Sat;Sun)

                      Best regards,

                       

                      DataNibbler

                        • Re: Trouble with an IF THEN clause
                          Friedrich Hofmann

                          Hmm ... it seems to work. The INCLUDE is seemingly being executed.

                          Let's see what things look like next Friday ...

                            • Re: Trouble with an IF THEN clause
                              Joseph Simmons

                              If it is working fine for you locally but failing when run from the server, could it be an issue with server time settings?

                              When it ran on the server, it may not have been Friday for it and correctly skipped the code, maybe check the run on Thur/Sat

                                • Re: Trouble with an IF THEN clause
                                  Friedrich Hofmann

                                  Hi Joe,

                                   

                                  yes, that sounds good. The strange thing is, I tested it locally on Friday - and it worked fine. Then I tried starting the script through QMC - so it was run on the server - and that worked fine, too ...

                                  It was the same the week before as far as I can remember.

                                  So it cannot be that the server settings are generally different. Also, this app is run at 6am, so there can be no confusion about the day, either ...

                                   

                                  The flipside of it also works - the code should not be run on any other day, and it isn't ...

                                  Strangely, though, the closing ENDIF is not logged - the line with the IF THEN clause is in the log and from the next lines I can tell that the specific code for Fridays has been skipped. The ENDIF is not in the log, though ...

                                  That is not normal, is it?

                                   

                                  Best regards,

                                   

                                  DataNibbler

                                   

                                  P.S.: I use Today(0) for the weekday_check - so it should be updated at reload of the script, no? And, as I said, the app is reloaded at 6am.

                                    • Re: Trouble with an IF THEN clause
                                      Marcus Sommer

                                      Hi DataNibbler,

                                       

                                      put several trace-statements in the script - inside and outside from if-loop - to check what your variables return and which statements are executed and which not.

                                       

                                      - Marcus

                                      • Re: Trouble with an IF THEN clause
                                        Joseph Simmons

                                        Hi Data,

                                         

                                        that does sound quite strange.

                                        QV version, is what you are running locally the same as the server?

                                         

                                        The job starts at 6am? or it reaches that section of code at 6am? And that's 6am according to QMC not your local machine yea?

                                        Today(0) means date at the script start time I believe, if the job starts before midnight and that code isn't reached until 6am, I think that might cause an issue.

                                         

                                        Like Marcus says though, trace the whole thing and see what is/isn't showing

                                         

                                        Joe

                                          • Re: Trouble with an IF THEN clause
                                            Friedrich Hofmann

                                            Hi Joe and Marcus,

                                             

                                            the other issue is solved, so here I go again.

                                             

                                            @ Joe

                                            Today(0) would of course return wrong results if the code started before midnight, but the script starts at 6am - I have none running for 6hrs, that would be quite strange for QlikView is really fast. i have one running for 20min, but that is the longest.

                                             

                                            I have also had the thought of introducing TRACE statements - and I now have a variable automatically highlighting the end of one script_tab and the beginning of the next, so I can also use that.

                                             

                                            Thanks a lot!

                                            Best regards,

                                             

                                            DataNibbler

                                              • Re: Trouble with an IF THEN clause
                                                Friedrich Hofmann

                                                Okay - those TRACE commands clearly show me that the code for Fridays is indeed skipped.

                                                I will try changing that to Monday to see if it runs then.

                                                The alert on the GUI is set to fire only on Fridays separately - otherwise it would fire every day because when the code is not run, the field that alert is set to check doesn't exist.

                                                Best regards,

                                                 

                                                DataNibbler

                                                 

                                                P.S.: Now I've changed it to Monday and as expected, the code is then run, both locally and on the server. I've also inserted a TRACE statement to show me what the weekday_check returned.

                                                I'll change it back now and wait for Friday ...

                                                  • Re: Trouble with an IF THEN clause
                                                    Joseph Simmons

                                                    Change it to Tues so we can see what the trace statements show during a proper over night run sooner maybe? Saves waiting until Fri.

                                                    If it just worked fine on the server and locally today but then overnight during the 6am load doesn't work, that does point more to some timing issue.

                                                      • Re: Trouble with an IF THEN clause
                                                        Friedrich Hofmann

                                                        Hi Joe,

                                                         

                                                        the same thing just happened again - the code was not executed this morning at 6am and the alarm fired because

                                                        the field it was set to look for didn't exist.

                                                        I just have an idea. Maybe someone can confirm that:

                                                         

                                                        => In the log, the TRACE command I built in just before that (it also uses >> Weekday(Today(0)) << )

                                                              read "Thu"

                                                        => Could it be, though the script doesn't say so, that Today(0), like Now(0) does not react right during the
                                                              script_reloading process, but only the next time round?

                                                              => In that case, the code, when reloaded at 6am on Friday, would use the result of Today() from the last
                                                                    script_run, which was on Thursday, and that particular block of code would not get executed.

                                                              <=> The alert on the GUI instead uses >> Weekday(Today()) << so that is evaluated immediately and of course

                                                                      it returns Friday and the alert fires correctly.

                                                         

                                                        So how could I fix this? Could I use a different parameter in the script to make that function Today() in the script evaluate immediately?

                                                         

                                                        Thanks a lot!

                                                         

                                                         

                                                        Best regards,

                                                         

                                                        DataNibbler

                                                         

                                                        P.S.: Unfortunately, that is very hard to check for the day will remain the same all day ;-) Could I try with a derivative of Now(0)?