Importing data from a text file

Loki

New Member
Hiya.

I have a problem. I've working on a program that has generated a text file like this:

output stream file1 to value(g_body_filepath).
put stream file1 UNFORMATTED variable_1 SKIP.
put stream file1 UNFORMATTED variable_3 SKIP.
put stream file1 UNFORMATTED variable_and-so-forth SKIP.
output stream file1 close.

...and now, later in the program I'd have to read the text from this file and input it to another text file that already has some text, so I'm appending a text file with another. No changes are made to the text in the process.

Unfortunately, I'm unsure how I can accomplish this. Any ideas or pointers?

-- Loki
 
Importing... step 2

Hiya again.

I solved the problem using this:

DEFINE VARIABLE text-string AS CHARACTER NO-UNDO.

INPUT STREAM file2 FROM value(pi_file_body).
REPEAT:
IMPORT STREAM file2 UNFORMATTED text-string.
PUT STREAM file1 UNFORMATTED text-string SKIP.
END.

INPUT CLOSE.

Where pi_file_body is the file I want to copy and stream file1 is the destination file.

However, this method loses empty lines from the source file in the process.

Any ideas on this problem?

Any insight, of course, is greatly appreciated.

-- Loki
 
Iporting... problem solved

Originally posted by Loki

However, this method loses empty lines from the source file in the process.

Any ideas on this problem?


Well, of course like so:

INPUT STREAM file2 FROM value(pi_file_body).
REPEAT:
IMPORT STREAM file2 UNFORMATTED text-string.

IF text-string = "" THEN DO:
PUT STREAM file1 UNFORMATTED SKIP(1).
END.

PUT STREAM file1 UNFORMATTED text-string SKIP.
END.

INPUT CLOSE.

Remarkable, I seem to find answers to all my problems just by posting them here :)
 
Do you need to output the first file?

if not then, the following should work:
Code:
OUTPUT STREAM file1 TO VALUE(pi_file_body) APPEND. 
PUT STREAM file1 UNFORMATTED
    variable_1
    SKIP.
PUT STREAM file1 UNFORMATTED
    variable_3
    SKIP.
PUT STREAM file1 UNFORMATTED
    variable_and-so-forth
    SKIP.
OUTPUT STREAM file1 CLOSE.
if you do, then:
Code:
OUTPUT STREAM file1 TO VALUE(g_body_filepath). 
PUT STREAM file1 UNFORMATTED
    variable_1
    SKIP.
PUT STREAM file1 UNFORMATTED
    variable_3
    SKIP.
PUT STREAM file1 UNFORMATTED
    variable_and-so-forth
    SKIP.
OUTPUT STREAM file1 CLOSE.

.......

INPUT STREAM file1 FROM VALUE(g_body_filepath).
OUTPUT STREAM file2 TO VALUE(pi_file_body) APPEND. 
REPEAT:
    IMPORT STREAM file1 UNFORMATTED
        text-string.
    PUT STREAM file2 UNFORMATTED
        test-string
        SKIP.
END.
OUTPUT STREAM file2 CLOSE.
INPUT STREAM file1 CLOSE.

Originally posted by Loki
Hiya.

I have a problem. I've working on a program that has generated a text file like this:

output stream file1 to value(g_body_filepath).
put stream file1 UNFORMATTED variable_1 SKIP.
put stream file1 UNFORMATTED variable_3 SKIP.
put stream file1 UNFORMATTED variable_and-so-forth SKIP.
output stream file1 close.

...and now, later in the program I'd have to read the text from this file and input it to another text file that already has some text, so I'm appending a text file with another. No changes are made to the text in the process.

Unfortunately, I'm unsure how I can accomplish this. Any ideas or pointers?

-- Loki
 
Back
Top