Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Extract the Missing or Mismatch Fields from Table Structure

Hi all,

I'm trying to compare the file structure with required structure and trying to extract the missing fields and stored in .txt file.

I'm working on following script but I'm not getting the exact result. 

Can someone help me through this?

Thanks in advance

FOR Each FoundFile in filelist('$(vSource)'&'\Data_level_*.csv')

LET vFileName = subfield(FoundFile,'\',-1);
LET vReportingDate = mid('$(vFileName)', 18, 6);

[Data]:
LOAD Date,
Engine,
Code,
CodeName,
Level
FROM [$(FoundFile)] (txt, codepage is 1252, embedded labels, delimiter is ',', msq);
Next FoundFile;


Let vTableName = TableName(0);
Let vNoOfColumns = NoOfFields('$(vTableName)');
Trace $(vTableName);
Let vFieldList = '';
for i = 1 to $(vNoOfColumns)
vFieldList = vFieldList&','&chr(39)&FieldName($(i),'$(vTableName)')&chr(39);
next i;
vFieldList = right((vFieldList),len(vFieldList)-1);
Trace $(vFieldList);

for i = NoOfTables() - 1 to 0 step - 1
//for i = 1 to NoOfTables()-1
Let vTableName = TableName($(i));
Let vNoOfColumns = NoOfFields('$(vTableName)');
//Next i;
Trace $(vNoOfColumns);
for j=1 to $(vNoOfColumns)
vFieldNameFieldName($(j),'$(vTableName)');
vFieldCheck = WildMatch('$(vFieldName)',$(vFieldList));

if $(vFieldCheck) =0 then
Load
'$(vFieldName)'
as MisMatch_Field,
'$(vTableName)'
as MisMatch_TABLE_NAME
AutoGenerate(1);

ENDIF

Trace $(vTableName) -> $(vFieldName);

next j;

next i;

5 Replies
Anil_Babu_Samineni

I'm working on following script but I'm not getting the exact result.

May be explore this part?

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
Anil_Babu_Samineni

And this part may be you need

LET vFileName = subfield(FoundFile,'\',-1);


FoundFile should be in '$(FoundFile)'

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

Yes but result won't appear. I'm trying to extract the information for mismatch fields in table.

Anil_Babu_Samineni

May be try this? If not, I would ask you to share sample CSV files (Atleast 2 files)

SET vSource = D:\Prod\Tranformation;

FOR Each FoundFile in filelist('$(vSource)'&'\Data_level_*.csv')

LET vFileName = subfield('$(FoundFile)','\',-1);

LET vReportingDate = mid('$(vFileName)', 18, 6);

[Data]:

LOAD Date,

Engine,

Code,

CodeName,

Level

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

Next FoundFile;

Let vTableName = TableName(0);

Let vNoOfColumns = NoOfFields('$(vTableName)');

Trace $(vTableName);

Let vFieldList = '';

for i = 1 to $(vNoOfColumns)

vFieldList = $(vFieldList) &','&chr(39)&FieldName($(i),'$(vTableName)')&chr(39);

next i;

vFieldList = right((vFieldList),len($(vFieldList))-1);

Trace $(vFieldList);

for i = NoOfTables() - 1 to 0 step - 1

Let vTableName = TableName($(i));

Let vNoOfColumns = NoOfFields('$(vTableName)');

Trace $(vNoOfColumns);

for j=1 to $(vNoOfColumns)

vFieldName =  FieldName($(j),'$(vTableName)');

vFieldCheck = WildMatch('$(vFieldName)',$(vFieldList));

if $(vFieldCheck) =0 then

Load

'$(vFieldName)' as MisMatch_Field,

'$(vTableName)' as MisMatch_TABLE_NAME

AutoGenerate(1);

END IF

Trace $(vTableName) -> $(vFieldName);

next j;

next i;

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,

Its not working still. can you have any solution on that ?