Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld, June 24-25, 2020. Free virtual event for DI and DA gurus. Register Today
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Champion
Champion

ErrorCode - seemingly quite easy ...

Hi,

I want to build several LOADs for tables with data about errors in the underlying files - but I cannot be sure whether these files really exist - so what I did up to now is, I set the ERRORMODE to 0 so QlikView would continue with the code and then I tried to build my own error-handling-code - but something about it seems to be wrong: The paths are all defined - the first file I am trying to load really does not exist and the messagebox appears all right - but is the variable ERRORCODE reset after that?

Something seems to be wrong because the messagebox appears after the second file, too - and that one does exist, so there should be no error except if there's an error in the code itself - see here:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

SET ErrorMode = 0; // Hier schalten wir die QlikView-Fehlerbehandlung aus, dann müssen wir selbst eine individuelle Fehlerbehandlung aufbauen.
Abrechnung_syn_Fehler1:
LOAD
*
From $(v_filepath_syn_Pflegefehler1_qvd) (qvd);

IF $(Errorcode) = 8 THEN // Dieser Code steht dafür, dass die betr. qvd-Datei nicht gefunden wurde.
  Tmp: LOAD MsgBox('Fehlertyp1 (weder Zeit noch Volumen) kommt nicht vor.', 'Fehlerinfo', 0,64,0) as Usermsg AutoGenerate 1;
DROP TABLE Tmp;
ENDIF
 
Abrechnung_syn_Fehler2:
LOAD
*
FROM $(v_filepath_syn_Pflegefehler2_qvd) (qvd);

IF $(Errorcode) = 8 THEN  // Dieser Code steht dafür, dass die betr. qvd-Datei nicht gefunden wurde.
  Tmp: LOAD MsgBox('Fehlertyp2 (ComCode passt nicht zum PackageType) kommt nicht vor.', 'Fehlerinfo', 0,64,0) as Usermsg AutoGenerate 1;
DROP TABLE Tmp;
ENDIF

The second table, as I said, does exist and QlikView loads all the data from the qvd_file - but still the messagebox is displayed, as if the ERRORCODE variable was not reset to 0 inbetween ...

=> Do I have to take into account the ScriptErrorCount, too, or can I somehow reset that?

Thanks a lot!

Best regards,

DataNibbler

1 Solution

Accepted Solutions
Highlighted

Re: ErrorCode - seemingly quite easy ...

Yes, you could.

But as I said before, IMHO the best way to approach the task of reporting volatile values & states is to use a SUBroutine. That will also do away with the repetition of the MessageBox LOAD statements all over your script.

For example:

SUB CheckError(ErrorNum, TableName, Position)

  IF ErrorNum <> 0 THEN
    Tmp:

    LOAD MsgBox('Error $(ErrorNum) occurred while trying to load table [$(TableName)] at script location [$(Position)]', 'Table LOAD Error !', 0,64,0)

    AUTOGENERATE 1;
    DROP TABLE Tmp;
  END IF

END SUB

:

SET ErrorMode = 0;

Abrechnung_syn_Fehler1:
LOAD *
FROM [$(v_filepath_syn_Pflegefehler1_qvd)] (qvd);


CALL CheckError(ScriptError, 'Abrechnung_syn_Fehler1', 'Step 1');

:


(The long discussion makes the code formatting look compressed, but I'm sure you get the idea)


Best,


Peter

View solution in original post

11 Replies
Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Ah, yes, I can reset it.

The strange thing is that I need that $-evaluation to - evaluate - the variable, otherwise it is red (recognized as a fieldname) - but to reset it, I don't, it does turn grey (recognized as a variable)  ...

Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Hello,

that is really strange: It worked in the beginning - now it doesn't. The errorcode can't have suddenly changed, no? Still, the qvd_file for that particular kind of error does not exist - so the errorcode should be 8 (for a not_found file), no?

I'll have a closer look at that. Maybe one of you can help me there?

Thanks a lot!

Best regards,

DataNibbler

P.S.: I do get a Scripterrorcount of 2 and a "File not found" error - but the errorCode is not displayed prior to my query ...

Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Strange - now I replaced the >>ErrorCode<< by >>ScriptError<< and it works again. But why did that work before and then suddenly it stopped working? Really strange that is ...

P.S.: Well, it does NOT work - somehow that ScriptError, once set to 8 ("file not found") is not reset and after the next LOAD (where i load another table with erroneous data, which DOES exist), the same query still returns TRUE and the same message is triggered saying that the error_type does not exist, but that is not true ...

Can someone help me with that?

I already have a Script_line >> SET ScriptError = NULL() << inbetween the LOADs ...

Highlighted

Re: ErrorCode - seemingly quite easy ...

For me it works like a charm, with these modifications:

  • I added NOCONCATENATE to the second LOAD. Never hurts.
  • I replaced your Error test with this:

    IF ScriptError = 8 THEN ...

I even tested both situations: File1 exists/File2 doesn't and File1 doesn't exist/File2 does. Output was according to expectations.

ErrorCode (or Errorcode) doesn't ring a bell .You probably defined it yourself some time along your tests.

ScriptError can be used as is, but only once. This is because really every script statement resets ScriptError to 0 if a statement could be completed without errors.

Best,

Peter

Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Thanks Peter!

I also couldn't find >>ErrorCode<< in the script - only in the editor, when you click the tab >>variables<< and check >>system variables<<, there it is. No idea why I used that in the first place.

ScriptError is reset with every statement? So I do not have to reset it myself. Great.

I guess there is/was some syntax_error in the LOAD_statement - I see some details in the debugger (not all, a TRACE does not work).

I tried without the $() too, like you are doing, but then the word >>ScriptError<< turns red instead of grey, no? That means it's being interpreted as a field afaIk - well, I'll try to do it as you have tested. Let's see, said the blind 😉

Best regards,

DataNibbler

Strange - it doesn't work for me: A >> TRACE ScriptError << without the $() does not work (it did not work with >> $(ScriptError) <<, either) - and the query >> IF ScriptError = 8 THEN << does not return TRUE - the lines inbetween that query are not executed though I see the text >> File not found << in the debugger - even twice, that's strange. It says >> File not found File not found<< in the debugger.

Highlighted

Re: ErrorCode - seemingly quite easy ...

The syntax for the TRACE statement is:

TRACE string;

meaning that string is a non-delimited string that is not evaluated as an expression. So

TRACE ScriptError;

will simply print 'ScriptError' and not the value contained in variable ScriptError. $-sign substitution on the other hand is always executed before the statement is analysed in detail, so that one will work.

Except that either TRACE itself - if it is placed before the IF statement that tries to display a MessageBox - will reset the ScriptError variable to 0 and as a result the IF will not be correctly executed, or TRACE will always display 0 if you place the TRACE statement after the IF, and the IF-block statements succeed.

The best way to retain the value of ScriptError for more than one subsequent statement is to immediately and always CALL a SUBroutine and pass along the required Error variables as parameters. Especially when you need more than one variable.

Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Hi Peter,

well, I tried the TRACE with the $() before - and it doesn't work now, either - it just displays the word "ScriptError" in green, nothing else.

Moreover, if every single line of code whatsoever resets the >>ScriptError<< variable, why does the second query for >> ScriptError = 8 << also return TRUE when the qvd_file to load there does exist?

Oops - it works now. There must have been some syntax error.

Well, that TRACE still doesn't, but the queries seem to work now - the message for the first qvd (which does not exist) appears, the second one (where the file does exist) does not appear anymore.

Still, I wonder how I could get that TRACE to work - and why the >> ScriptErrorList << (displayed in the debugger) lists the error twice and says >> File not found File not found <<  - and why the script_editor clearly does not really recognize that variable - the keyword appears in red without the $() (which usually means that QlikView recognizes the word as a field_name, no?)

Highlighted

Re: ErrorCode - seemingly quite easy ...

Just to prove my point, put this at the end of your script after the LOAD of your second table:

LET vNumRows = NoOfRows('Abrechnung_syn_Fehler2');

TRACE >>>> Table [Abrechnung_syn_Fehler2] - $(vNumRows) loaded;


Check whether that one works. Don't forget to put a semicolon after the string parameter. TRACE is still a statement.

Highlighted
Champion
Champion

Re: ErrorCode - seemingly quite easy ...

Hi Peter,

well, TRACE in general does work of course, I am using it elsewhere - and the NoOfRows() for that second qvd_file is positive, nearly 6.000. Only the TRACE for that ScriptError_variable does not work.

Maybe I could feed that ScriptError into another variable to retain it?

Best regards,

DataNibbler

P.S.: Yep, that works - I have to use that right after the LOAD of course to avoid the variable being reset, and I'd have to query the manual variable then as the other one has been reset already ... but it says "File not found", not the numeric value. Maybe that is the key to that particular TRACE ...

Let's see.