Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

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
amartinez35
Valued Contributor

Re: error handling script getting error(Script line error)

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');

Not applicable

Re: error handling script getting error(Script line error)

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

Re: error handling script getting error(Script line error)

Please help me urgent basic.

Not applicable

Re: error handling script getting error(Script line error)

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

Re: error handling script getting error(Script line error)

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

amartinez35
Valued Contributor

Re: Re: error handling script getting error(Script line error)

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

amartinez35
Valued Contributor

Re: error handling script getting error(Script line error)

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

Not applicable

Re: error handling script getting error(Script line error)

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

Re: error handling script getting error(Script line error)

Hi,

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

Regards

Ashish

Community Browser