Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

how to identify if a field is present in the load statement?

I have am using loop to load 5 similar files. There is one field called [Critical Care Customers] that is present in only one file and is missing in the rest of the files. If this field is missing in any of the files i need to create this field  in the script such as null () as [Critical Care Customers] in rest of the files while loading.

Can anybody please suggest how to go about this?

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

first

SET ErrorMode = 0;

--> Set it back to default later if needed

then

"LOAD your table with "all" fields..." --> can be done multiple times...

if ($(ScriptError) = 11) then

do an alternative LOAD Statement... for example without the missing field

View solution in original post

13 Replies
Anil_Babu_Samineni

Can you use for that variable like

Trace $(Variable);

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
Anonymous
Not applicable
Author

Peter_Cammaert
Partner - Champion III
Partner - Champion III

If all files have a similar file name, you can just perform a CONCATENATE LOAD * FROM, and QlikView will do all merging by itself.


Imagine we're reading a set of 5 Excel files with a name consisting of a prefix and a YearMonth pattern::

MergedTable

LOAD * FROM 'Invoices2017??.xlsx' (options);

The safer method would be to use a CONCATENATE LOAD * in your FOR loop, as this rechnique will provide more safeguards for merging tables with a different layout.

Anonymous
Not applicable
Author

I am already concatenating the files. The file have a lot of fields and we are not loading all the fields , hence we have stated explicity in the load statement the fields that we want to load. If I add this field then it shows field not found when the QV starts loading the new files where this field does not exist.

so i wanted to add in the script if this field is not present then just load null for this field.

Anonymous
Not applicable
Author

did you try SetErrorMode = 0 ?

if ScriptError =11 then you could add a  separate LOAD without the missing field...

Anonymous
Not applicable
Author

can you please elaborate more on this?

Anonymous
Not applicable
Author

first

SET ErrorMode = 0;

--> Set it back to default later if needed

then

"LOAD your table with "all" fields..." --> can be done multiple times...

if ($(ScriptError) = 11) then

do an alternative LOAD Statement... for example without the missing field

swuehl
MVP
MVP

You probably know in which file you expect the field?

I would suggest using a loop to load your files, and then check the file name just before the LOAD statement and create a variable conditionally like

FOR EACH vFile IN ...

IF vFile LIKE '*Test* THEN

      LET vField = '[Critical Care Customers]';

ELSE

     LET vField = 'Null() as [Critical Care Customers]';

ENDIF

LOAD FieldA,

          FieldB,

          $(vField)

FROM vFile;

NEXT  vFile

Anonymous
Not applicable
Author

Set ErrorMode = 0;

TEMP:
LOAD * INLINE [
F1, F2
A, 1
B, 2
C, 3
]
;

NoConcatenate

LOAD F1,F2,F3 Resident TEMP;

if $(ScriptError)=11 then

LOAD F1,F2 Resident TEMP;

ENDIF;

Set ErrorMode = 1;