Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
nandhaadjame200
Contributor II
Contributor II

Need to loop my script with set of values & pass the same into a variable name across the script

Need to loop my script with set of values & pass the same into a variable name across the script for internal usage. I think to go with for each loop, but please help to implement the same and also help to exit the for loop once list of values to variables completed. Also i faced an issue when i tried this, like my next block code is not executed, so i concluded it as my for loop implementation is having issue. So, please help me to implement it from scratch.

Thanks in advance.

My Base Script:

Set vTable = ''; // Need to send different values & based on the values my script should loop & execute.

If Alt(FileSize('$(vQVDRoot)\*Files.qvd'), 0) <= 0 then
set vFirstLoad=3;
ElseIf Alt(FileSize('$(vQVDRoot)\$(vTable)Log.qvd'), 0) <= 0 then
set vFirstLoad=1;
ElseIf Alt(FileSize('$(vQVDRoot)\$(vTable)Log.qvd'), 0) > 0 then
If Alt(FileSize('$(vQVDRoot)\*Files.qvd'), 0) > 0 then
set vFirstLoad=0;
End If
End If

if(vFirstLoad=1) then

For each LogFile in filelist( vQVDRoot & '\*Files.qvd')
Log:
LOAD SubField([File],'\',-1) as [File_Name],
SubField(FileBaseName('$(LogFile)'),'\',-1) as [SourceFileName],
'$(LogFile)' as [FileLocation], [File],
[FileUploadDate]
From [$(LogFile)] (qvd);
Next;

Elseif(vFirstLoad=0) then

FOR Each File in filelist ('$(vQVDRoot)\*Files.qvd')
CurrentFileList:
Load '$(File)' as [File], Date(now()) as [FileUploadDate]
autogenerate 1;
next File

OldFileList:
LOAD [File] as [History]
FROM '$(vQVDRoot)\$(vTable)Log.qvd' (qvd);

NoConcatenate
NewFiles:
Load [File] as [NewFile]
resident CurrentFileList
Where not exists([History], [File]);

If(Count([NewFiles])>0) then
Log:
LOAD *
FROM [$(vQVDRoot)\$(vTable)Log.qvd] (qvd);

For each LogFile in filelist('$(vQVDRoot)'&'\*Files.qvd')
Concatenate(Log)
LOAD SubField([File],'\',-1) as [File_Name],
SubField(FileBaseName('$(LogFile)'),'\',-1) as [SourceFileName],
'$(LogFile)' as [FileLocation], [File],
[FileUploadDate]
FROM '$(LogFile)' (qvd);

SET Concatenate = concatenate;

Next;
End if;
Elseif(vFirstLoad=3) then
Trace Log File Does not Exist!;
END IF

If(vFirstLoad=3) then
Trace Log File Does not Exist!;
Elseif(vFirstLoad=1) then
STORE Log into [$(vQVDRoot)\$(vTable)Log.qvd] (qvd);

Drop table Log;
Elseif(vFirstLoad=0) then
If(Count([NewFiles])>0) then
STORE Log into [$(vQVDRoot)\$(vTable)Log.qvd] (qvd);

Drop Tables Log,CurrentFileList,OldFileList,NewFiles;
End If;
End if;

Thanks

Nandhakumar

Labels (2)
0 Replies