Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

error handling script getting error(Script line error)


Hi All,

I am using below script for error handling geeting error message (Script line error).

Please help me.

Set vConcatenate = ;

sub ScanFolder(Root)

          for each FileExtension in 'txt'

                        for each FoundFile in filelist( Root & '\Protection_*.' & FileExtension)


                              set ErrorMode=0;
                              Protection:
                              LOAD
                              ID,
                             Name,
                             Premium,
                                                        
                             FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

                              Set vConcatenate = Concatenate;
                             
                              if ScriptError=11 then
                            
                              next FoundFile
                             
                              else
                             
                             
                              for each FoundFile1 in filelist( Root & '\Protection_*.' & FileExtension)

                             
                              Protection:
                             LOAD
                             ID,
                             Name,
                             Premium,
                             FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

                              Set vConcatenate = Concatenate;
                             
                              next FoundFile1                         
                        
                         endif
                        
                        
      
          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('C:\Production\Life\Data');

Regards

Ashish

9 Replies
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Set vConcatenate = ;

Set vtest = ;

sub ScanFolder(Root)

  for each FileExtension in 'qvd'

    for each FoundFile in filelist('$(Root)\*.$(FileExtension)')

      set ErrorMode=0;

      Protection:

      LOAD
          ID,
          Name,
          Premium             
       FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

     

      Let vtest = ScriptError;

      Set vConcatenate = Concatenate;

                            

      if '$(vtest)'<>'Field Not Found' then     

     

      Set vConcatenate = Concatenate;

          

        for each FoundFile1 in filelist( '$(Root)\*.$(FileExtension)')

      Protection:

      LOAD
          ID,
          Name,
          Premium             
       FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

           Set vConcatenate = Concatenate;

                             

        next FoundFile1                         

                        

      endif

   

    NEXT FoundFile   

  next FileExtension

 

  for each SubDirectory in dirlist('$(Root)\*' )

    call ScanFolder('$(SubDirectory)')

  next SubDirectory

 

end sub

Call ScanFolder('D:\Projets\QlikView\Concours AM-DV\5-QVD');

Help users find answers! Don't forget to mark a solution that worked for you!
Not applicable
Author

Hi,

The above script given me duplicate record.

Duplicate record is comming because it relode one file three time

I want it's relode one file only one time.

Regards

Ashish

Not applicable
Author

Please help me urgent basic.

Not applicable
Author

Hi,

i am wating for your reply it urgent for me.

I culd not find any soluation.

Please help me.

Thanks in advance.

Regards

Ashish

Not applicable
Author

Hi Ashish,

you are using 2 for each loops and loading the same file from the folder, thats y the duplicate issue.

I think the below script should solve your problem.

Set vConcatenate = ;

sub ScanFolder(Root)

          for each FileExtension in 'txt'

                        for each FoundFile in filelist( Root & '\Protection_*.' & FileExtension)

                              set ErrorMode=0;

                              Protection:

                              LOAD

                              ID,

                             Name,

                             Premium,

                                                        

                             FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

                              Set vConcatenate = Concatenate;

                             

                           

                              next FoundFile

          next FileExtension

          for each SubDirectory in dirlist( Root & '\*' )

                    call ScanFolder(SubDirectory)

          next SubDirectory

end sub

Call ScanFolder('C:\Production\Life\Data');

thanks,

Shruthi

Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Hi,

Set vConcatenate = ;

Set vtest = ;

sub ScanFolder(Root)

  for each FileExtension in 'txt'

    for each FoundFile in filelist('$(Root)\*.$(FileExtension)')

      set ErrorMode=0;

      Test:

      LOAD
          ID,
          Name,
          Premium             
      FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

      Let vtest = ScriptError;

      Set vConcatenate = Concatenate;

                        

      if '$(vtest)'<>'Field Not Found' then

      Drop table Test;

      Set vConcatenate = Concatenate;

      

        for each FoundFile1 in filelist( '$(Root)\*.$(FileExtension)')

      Protection:

      LOAD
          ID,
          Name,
          Premium             
      FROM [$(FoundFile1)] (txt, codepage is 1252, embedded labels, delimiter is '\t', msq);

          Set vConcatenate = Concatenate;

                        

        next FoundFile1                    

                    

      endif

    NEXT FoundFile

  next FileExtension

  for each SubDirectory in dirlist('$(Root)\*' )

    call ScanFolder('$(SubDirectory)')

  next SubDirectory

end sub

And now?

Regards,

Aurélien

Help users find answers! Don't forget to mark a solution that worked for you!
Aurelien_Martinez
Partner - Specialist II
Partner - Specialist II

Add   "EXIT For" at the end  (between endif & NEXT FoundFile)

Help users find answers! Don't forget to mark a solution that worked for you!
Not applicable
Author

Hi,

purposely i am using two loop.

Loop1 will be excute upto script error(Filed not found).

Loop2 will be excute for  no error.

Regards

Ashish

Not applicable
Author

Hi,

It again given me duplicate value and load one file three time.

Regards

Ashish