Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Peony
Creator III
Creator III

Working with Sub in the cycle

Hi All.

I have  a set of the subroutines, that I using to calculate some moduls load duration. Here they are:

Sub ReloadStart     
                                Let vStart = Num(Now());   End Sub;

Sub ReloadEnd       
                              Let vEnd = Num(Now());     End Sub;

Sub DurationCalc(vModulName)

          Let vDuration = Date(($(vEnd) - $(vStart)),'hh:mm:ss');
          Let vModulName= vModulName;

          For i = 0 to NoOfTables() - 1

          Result_Table:
         Load
          '$(vModulName)' as "Modul Name",
          TableName($(i)) as "Table Name",
          Date('$(vStart)','dd-mm-yyyy hh:mm:ss') as "Reload Start",
          Date('$(vEnd)','dd-mm-yyyy hh:mm:ss') as "Reload End",
         '$(vDuration)' as "Reload Duration"

       Autogenerate 1;
      Next i;

End Sub;

When I set Call ReloadStart ant the beginning of the module and in the end Call ReloadEnd, Call DurationCalc('Some Script Name') the Result_Table gives me for each table inside particular module the same time for start and end load. 

But if I want to calc  when was end of the duration of the each table in the module - I dont understand how to modify the DurationCalc sub. 

What I want to get as the result is no this (this is what I have now):
Capture 1.PNG
But this:

Capture 2.png

Labels (1)
  • Sub

1 Solution

Accepted Solutions
treysmithdev
Partner Ambassador
Partner Ambassador

You won't be able to track the individual tables end time in a single pass. You will need to define the vEnd each time a table completes.

 

I would suggest doing something like the following:

Let vReloadStart = Num(Now());


Sub DurationCalc(pModulName,pTableName, pTableStart)

    Let DC.ReloadEnd = Num(Now());

	If Len(NoOfRows('Result_Table')) = 0 Then
    
    	Result_Table:
        Load
        	Date(Null(),'dd-mm-yyyy hh:mm:ss') 						as [Reload Start],
        	Date(Null(),'dd-mm-yyyy hh:mm:ss') 						as [Reload End],
        	Time(Null(),'hh:mm:ss') 								as [Reload Duration],
        	Time(Null(),'hh:mm:ss') 								as [Total Reload Duration]
        AutoGenerate
        	(0);
            
     End If;
     
     
    Concatenate(Result_Table)
    Load
        '$(pModulName)'                                             as "Modul Name",
        '$(pTableName)'                                             as "Table Name",
        Num(NoOfRows('$(pTableName)'),'#,##0')						as "Table Rows",
        Num(NoOfFields('$(pTableName)'),'#,##0')					as "Table Fields",
        Date('$(pTableStart)','dd-mm-yyyy hh:mm:ss')                as "Reload Start",
        Date('$(DC.ReloadEnd)','dd-mm-yyyy hh:mm:ss')               as "Reload End",
        Interval('$(DC.ReloadEnd)' - '$(pTableStart)','hh:mm:ss')   as "Reload Duration",
        Interval('$(DC.ReloadEnd)' - '$(vReloadStart)','hh:mm:ss')  as "Total Reload Duration"
    Autogenerate 
        (1);

    DC.ReloadEnd=;

EndSub;


Let vStart = Num(Now()); 

TestA:
Load
	Rand() as Random
AutoGenerate
	(5000000);
    
    
Call DurationCalc('ModuleTest','TestA','$(vStart)');


Let vStart = Num(Now()); 

TestB:
Load
	Rand() as Randomize,
    1 as Flag
AutoGenerate
	(15000000);
    

Call DurationCalc('ModuleTest','TestB','$(vStart)');
Blog: WhereClause   Twitter: @treysmithdev

View solution in original post

2 Replies
treysmithdev
Partner Ambassador
Partner Ambassador

You won't be able to track the individual tables end time in a single pass. You will need to define the vEnd each time a table completes.

 

I would suggest doing something like the following:

Let vReloadStart = Num(Now());


Sub DurationCalc(pModulName,pTableName, pTableStart)

    Let DC.ReloadEnd = Num(Now());

	If Len(NoOfRows('Result_Table')) = 0 Then
    
    	Result_Table:
        Load
        	Date(Null(),'dd-mm-yyyy hh:mm:ss') 						as [Reload Start],
        	Date(Null(),'dd-mm-yyyy hh:mm:ss') 						as [Reload End],
        	Time(Null(),'hh:mm:ss') 								as [Reload Duration],
        	Time(Null(),'hh:mm:ss') 								as [Total Reload Duration]
        AutoGenerate
        	(0);
            
     End If;
     
     
    Concatenate(Result_Table)
    Load
        '$(pModulName)'                                             as "Modul Name",
        '$(pTableName)'                                             as "Table Name",
        Num(NoOfRows('$(pTableName)'),'#,##0')						as "Table Rows",
        Num(NoOfFields('$(pTableName)'),'#,##0')					as "Table Fields",
        Date('$(pTableStart)','dd-mm-yyyy hh:mm:ss')                as "Reload Start",
        Date('$(DC.ReloadEnd)','dd-mm-yyyy hh:mm:ss')               as "Reload End",
        Interval('$(DC.ReloadEnd)' - '$(pTableStart)','hh:mm:ss')   as "Reload Duration",
        Interval('$(DC.ReloadEnd)' - '$(vReloadStart)','hh:mm:ss')  as "Total Reload Duration"
    Autogenerate 
        (1);

    DC.ReloadEnd=;

EndSub;


Let vStart = Num(Now()); 

TestA:
Load
	Rand() as Random
AutoGenerate
	(5000000);
    
    
Call DurationCalc('ModuleTest','TestA','$(vStart)');


Let vStart = Num(Now()); 

TestB:
Load
	Rand() as Randomize,
    1 as Flag
AutoGenerate
	(15000000);
    

Call DurationCalc('ModuleTest','TestB','$(vStart)');
Blog: WhereClause   Twitter: @treysmithdev
Peony
Creator III
Creator III
Author

Your solution is make sense for my case! Thank you for this idea. It is great!