Structuring the script

The techniques for adding structure to the script is something that comes naturally to experienced developers. This is because they have often learned it the hard way, through other people's work and spent additional time to understand the script that can be made easier with a couple of simple additions. Again, this is something that won't be covered in user guides but it is a very important skill for new developers to have under their belt.

Getting ready

In this example, we will generate the required data automatically in the script.

How to do it…

  1. Create a new Qlik Sense application and name it Structuring Scripts.
  2. Create a new section in the data load editor called Change Log.
  3. Add the following code:
    /* 
    This application demonstrates the importance of adding structure to the back end script of your applications 
    
    Change Log:
    
    [10/06/2015] Philip Hand: Initial build 
    
    */
  4. Create another section called Calendar and add the following script:
    /*===========================================================
    Section: Calendar Tab;
    DESCRIPTION: Generates every date between the periods vMinDate & vMaxDate;
    DEVELOPERS: Philip Hand, Neeraj Kharpate;
    //==========================================================*/
    TRACE START:~~~~Loading Calendar Tab~~~~;
    
    Let vMinDate=DATE(Floor(MakeDate(2009,1,1)),'DD/MM/YYYY');
    Let vMaxDate=DATE(Floor(Today()));
    TRACE Calendar date range set to $(vMinDate) & $(vMaxDate);
    
    Let vDiff=vMaxDate-vMinDate+1;
    Calendar:
    Load
    DateID,
    Year(DateID)                       As Year,
    Month(DateID)                      As Month,
    Date(DateID)                       As Date,
    Day(DateID)                        As Day,
    Week(DateID)                       As Week;
    Load
    RecNo()-1+$(vMinDate)              As DateID
    AutoGenerate($(vDiff));
    
    
    TRACE END:~~~~Loading Calendar Tab~~~~;
  5. Finally, save the data and load the script.

How it works…

The first tab gives an overview of the application and calls out any key information that a new developer who is seeing the script for the first time will find useful. It also includes a change log to track the changes.

The second tab has a high-level description of the contained code and the developers who have worked on it. Finally, we can make use of the TRACE statements to write information into the execution window. This allows you to see each action being performed during script execution and is a useful tool to debug errors.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset