Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Logic does not fulfill condition

Hi,

I'm checking the structure of files with predefined column names.

Condition:

I'm getting csv files into one folder from where qv app is checking structure of file (Below Code) and if its structure is correct then it has to move this files into another folder.

Requirement is to raise error if any file has problem else rest files has to be move.

Issue:

1) When I'm getting mismatch error of fields in one or more csv files it holds every csv file in that folder even a correct csv also.

2) when two csv has a same field mismatch its giving only one name of csv.

For Each File in FileList('$(vPath)\' & 'data_level_*.csv')
$(File):
LOAD *
FROM [$(File)](txt, codepage is 1252, embedded labels, delimiter is ',', msq);
Next File;


Let vTableName = TableName(0);
Let vNoOfColumns = NoOfFields('$(vTableName)');
Trace $(vTableName);
Let vFieldList = '';

for i = 1 to $(vNoOfColumns)
set vFieldList = 'ReportingDate','Engine','SiteCode','CountryCode','DataLevel';
next i;

Trace $(vFieldList);

set k = 0;
for i= NoOfTables() - 1 to 0 step - 1
Let vTableName = TableName($(i));
Let vNoOfColumns = NoOfFields('$(vTableName)');
Trace $(vNoOfColumns);
for j=1 to $(vNoOfColumns)
vFieldNameFieldName($(j),'$(vTableName)');
vFieldCheck = WildMatch('$(vFieldName)',$(vFieldList));
if $(vFieldCheck) = 0 then
MisMatch1:
Load
'$(vFieldName)'
as MisMatch_Field,
'$(vTableName)'
as MisMatch_TABLE_NAME
AutoGenerate(1);

k= k+1;
ENDIF

Trace $(vTableName) -> $(vFieldName);
next j;
next i;

NoConcatenate
MisMatch:
Load
MisMatch_Field,
Subfield(MisMatch_TABLE_NAME,'\',4)as MisMatch_TABLE_NAME
Resident MisMatch1;

DROP Table MisMatch1;
Store MisMatch into C:\IncomingData\MisMatch.txt(txt);
'Raiseerror' as Error;

if k=0 THEN
EXECUTE cmd.exe /c md "$(vFiles)\Governance" 2> nul;
EXECUTE cmd.exe /c MOVE /Y "$(vPath)\data_level_*.csv" "$(vFiles)\Governance";

4 Replies
Anil_Babu_Samineni

May be try this?

SET ErrorMode = 1;

Load * Inline [

Welcome_Error

'$(ErrorMode)'

];

IF Welcome_Error = 1

<Your Code>

Else

LOAD

MsgBox ('Message X', 'msgbox', 'Continue..', 'Error in your script') as x, 2 as r;

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
Not applicable
Author

Hi Anil Babu,

here my code has to be correct itself. logic has still some bug which I'm trying to rectify. can you look over it please? if you need some sample data I can give.

Anil_Babu_Samineni

How to find first one? Off course, there might be some logic behind. May be release that?

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
avinashelite

What is the logic your looking for ???

Qlik is not go good at error documenting/handling ...When error mode is set to 0 it stops the execution at the point where error occurred and its doesn't move further ...so setting the Error mode to 1 will ignore the error and continue with the execution ....