Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

error handle in For loop

Hi All,

i have the below For loop:

  let i = 0;
for i = 0 to vcount-1
 
NoConcatenate
datesinfo:
load distinct TRADE_DATE resident bodata;
 
NoConcatenate
datesinfo1:
load distinct Date(TRADE_DATE,'YYYYMMDD') as tddate resident datesinfo;
drop table datesinfo;
 
Let vdate = peek('tddate',i,'datesinfo1');
drop table datesinfo1;
  fillsdata:
load * from $(vfillxcelFileName)$(vfoldername)\$(vdate)\*.csv;
 
Concatenate
load * from fillsdata.qvd (qvd);
store fillsdata into fillsdata.qvd (qvd);
drop table fillsdata;
 
next

IF lets say file is not available on $(vdate), how to handle the for loop, where expectation is if file is not found, continue with For loop to search for files on rest of the days

thanks,

Sukhwant

2 Replies
Miguel_Angel_Baeyens

I think we have already replied to this issue in your previous post: import data from multiple excel files in a folder

Anyway, you have several options. Use DoDir() for example to load each file individually, so you can control or even ignore the file that does not exist and load only those who exist.

Or use the ScriptError and ErrorMode variables according to your needs.

annapochyla
Partner - Contributor III
Partner - Contributor III

Try using ErrorMode and ScriptError inside If (otherwise qlik will exit for loop after first error)

set ErrorMode=0;

fillsdata:

LOAD FieldName Inline [FieldName];

for i=1 to 4

    if 1 then

        NoConcatenate

        a_fillsdata:

        LOAD *

        FROM  $(vfillxcelFileName)$(vfoldername)\$(vdate)\*.csv;

    end if

    if ScriptError=0 then

        Concatenate(fillsdata)

        LOAD

            *

        resident a_fillsdata;

        drop Table a_fillsdata;

    endif

next i

exit SCRIPT;