Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to create TXT file from variable?

Hello everybody,

my client would like to create TXT file from QlikView with number 0 or 1 (depends on if condition). I was searching for some solution, but I found nothing.

Is it possible to create only file with one of these numbers?

I tried this - but I think it is not good:

LET vNotification_file#1=if( if( InWeek(Today(),date(if( $(vActualDate)<= $(vActualDate2), vActualDate2, vActualDate)),0),

date(date(if( $(vActualDate)<= $(vActualDate2), vActualDate2, vActualDate)))=today(),

  date(date(if( $(vActualDate)<= $(vActualDate2), vActualDate2, vActualDate))+2)=today()),

'0 ','1 ');

- then I manually created empty TXT file

Tab1:

LOAD @1 as not1,

$(vNotification_file#1)

from

$(vPathDATA)not.txt

(txt, codepage is 1250, no labels, delimiter is '\t', msq);

Tab2:

LOAD

$(vNotification_file#1)

Resident Tab1;

Store Tab2 into $(vPathDATA)Notification_file#1.txt(txt);

This gives me number 1 in TXT file.

Many thanks.

Maros

1 Solution

Accepted Solutions
Gysbert_Wassenaar

MyTable:

LOAD $(vNotification_file#1) as FieldNameHere

Autogenerate 1;

STORE MyTable into MyFile.txt;

But perhaps this is easier: execute cmd.exe /c echo $(vNotification_file#1) > myfile.txt;


talk is cheap, supply exceeds demand

View solution in original post

10 Replies
Gysbert_Wassenaar

MyTable:

LOAD $(vNotification_file#1) as FieldNameHere

Autogenerate 1;

STORE MyTable into MyFile.txt;

But perhaps this is easier: execute cmd.exe /c echo $(vNotification_file#1) > myfile.txt;


talk is cheap, supply exceeds demand
Not applicable
Author

Thanks.

I tried this before - bud it gives me this output:

FieldNameHere

1

What i need is only this output:

1

Thank you

Gysbert_Wassenaar

Then use the second option I posted. Saving a table in a text file with the STORE command always (yes, really, really always, no exceptions, I ain't kidding) with a header row that contains the field names.


talk is cheap, supply exceeds demand
Not applicable
Author

I was replying to 1st option - "MyTable and STORE". I dont want the header in txt file. I need only value.

The 2nd oprtion - execute is not good for thie solution.

marcus_sommer

Why not the second option?

Not applicable
Author

I tried it with execution, it works. Thanks

carlcimino
Creator II
Creator II

How would you do this to a specific location using a variable?  I tried the below and it ran but did not produce the file.

LET vDataPath = '\\file path\';

execute cmd.exe /c echo > $(vDataPath)BAR_FILE_IND_TEST.txt (txt);

evan_kurowski
Specialist
Specialist

It's always been an item on the wishlist, to be able to have STORE write (txt) verbatim to disk.

Another tricky issue was when contents of the data contained characters like double-quotes, output rows were automatically wrapped with exterior and escaped quotes.

It would be neat to have a pure verbatim STORE option, making it possible to read or form lines of code in script, and  output a new valid programmatic file. (Imagine loading, tagging, & re-sequencing XML files or something.  course hope this wouldn't get abused)


I upvoted this in IDEA forum

marcus_sommer

There are several issues. Your path contains spaces and needs therefore quotes to be valid. Further you don't use Qlik to store data else you used it to execute the windows command-line to do it (by "abusing" their logging-feature respectively call it a workaround). This means you need to specify also a content and the file musn't have a fileformat entry esle just an extension. This means your code should more look like:

LET vDataPath = '\\file path\';

execute cmd.exe /c echo $(YourFileContent) > "$(vDataPath)BAR_FILE_IND_TEST.txt";

- Marcus