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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Import a txt file in difficult format

Hi,

I have an Oracle report that we run daily that I want to load into Qlikview.

The format of this file makes it rather difficult to import. I have attached an example of the Oracle file and the resulting table I'm looking for.

  • The data in the resulting table need to extracted from three lines in the original file (line 1, 9, 10, 11 and 12).
  • Line 1 is used in both lines in the resulting table
  • Line 9 and 10 is used in the first line in the resulting table
  • Line 10 and 11 is used in the second line in the resulting table

It's not an option to simplify the format before exporting it from Oracle.

How do I write the code for this?

Best Regards,
Jonas

6 Replies
nathanfurby
Specialist
Specialist


jonahed79 wrote:The format of this file makes it rather difficult to import


No kidding Stick out tongue

I have never had to worry about something like this so thought I'd give it a go out of interest. I used the Transformation Steps in the Load wizard (again, something I've never had to do) and managed to produce the output you required. See the attached qvw.

But the solution is unworkable in real world as the only way it can make sense of the file is by using 'space' as the delimiter. This means that the load would just fall over unless all the fields (Vendor, Item, Buyer etc.) were strictly enforced to have no spaces or a set number of spaces in the text.

I am no expert when it comes to this kind of load but I imagine that handling this kind of file it just not practical. If it was me then I would output the Oracle query/report to a csv file or, better yet, get the SQL code used for the query and run it directly via ODBC.

prieper
Master II
Master II

Good day Jonas,

you may give it a try with a code similar to this:

Report:
LOAD
*
WHERE
WILDMATCH(Data, '??-???-*'); // only rows containing Date
LOAD
IF(ODD(LineNo), PREVIOUS(ReportRow) & ReportRow) AS Data; // concatenate 2 lines
LOAD
@1:n AS ReportRow,
RecNo() AS LineNo
FROM
[.\Report.txt]
(fix, codepage is 1252);

Vendor:
LOAD
MID(@1:n, 8, 69) AS Vendor
FROM
[.\Report.txt]
(fix, codepage is 1252)
WHERE
WILDMATCH(@1:n, 'Vendor:*');


This should result in a table containing only one line per Purchase-Order in fixed format, which need to be cutted into fields (and fieldnames) etc. The other table may contain the vendor (or other site-information as in the header of the report) and can be added with JOIN to the datatable.

HTH
Peter

Not applicable
Author

Hi Nathan,

Thanks for your reply! I just found an alternate solution so I haven't had a chance to test yours. I used the 'peek' function to get the correct result.

I'll try yours soon to see if it's simpler.

Best Regards,
Jonas

---

tmpPastDue:
LOAD if(@6:12='Vendor:',@14:79,peek('tmpVendor')) as tmpVendor,
if(@3:3='-',makedate('20' & num#(right(@1:9,2)),num#(applymap('Months_cap',mid(@1:9,4,3))), if(mid(@1:9,2,1)='-',num#(left(@1:9,1)),num#(left(@1:9,2)))),peek('tmpDueDate')) as tmpDueDate,
if(@11:34 like '*,*',@11:34,peek('tmpBuyer')) as tmpBuyer,
@11:32 as tmpItem
FROM Pastdue.txt (fix, codepage is 1252);

PastDue:
LOAD tmpVendor as [Past Due Vendor],
tmpDueDate as [Past Due Due Date],
tmpBuyer as [Past Due Buyer],
tmpItem as [Past Due Item Number]
RESIDENT tmpPastDue
WHERE isnum(mid(tmpItem,7,2));

drop table tmpPastDue;

nathanfurby
Specialist
Specialist

Hi Jonas - I doubt my solution will be any better - not very robust as I mentioned.

Can you attach the text file you used with the example you posted. I tried it with the first file you attached and it didn't work. Thanks

Not applicable
Author

Sorry about that Nathan,

I simplified the text file a bit last time I sent it over. I've attached a new text file and a *.qvw file so you can see the solution.

Best Regards,
Jonas

nathanfurby
Specialist
Specialist

Interesting use of the fixed record file type (I've never looked at this before) and the peek function. A few presumptions about the data that you'd have to keep an eye on - but necessary I suppose when you are dealing with such a messy data source Stick out tongue

Many thanks Jonas.