Data editing > Writing out data > Print files > Printing out individual records
 
Printing out individual records
Quick reference
To write a record or part of a record to a print file, type:
write [file_name] [field] [$text$]
If no file name is specified, the out2 print file is used.
More information
write by itself prints out a whole record in the form it is when the write statement is executed, together with a ruler showing which codes fall in which columns, the line number of the record in the data file and the message ‘write’ indicating that the record was generated by a write statement. Any multicodes in the record are shown as asterisks; you can change this with an option on the filedef statement: see Defining the file type.
If the record contains more than one card, each card is listed separately beneath the ruler. For example, the statement:
write
by itself might give:
Quantum edit report

1 in file
----+----1----+----2-- ... --9----+----0
columns 1 - 100 are |12345
write
2 in file
----+----1----+----2-- ... --9----+----0
columns 1 - 100 are |23456
write
Each write statement produces a line in the default print file, out2, telling you how many records were written out, as follows:
2 (1%) write
Which cards are printed from multi-card records depends upon which cards have been read in so far. Quantum looks at the ‘allread’ variables and writes out cards for those which are true; so for example, if allread1, allread2 and allread3 are true, cards 1, 2 and 3 will be printed. If you have changed the contents of these variables prior to printing out the record, you will see the cards for which allread is true rather than those which were originally read.
The example above was very simple; more often than not a program contains several write statements and you want to identify which records were printed by which statement and why. If the write is dependent upon some other statement (for example, it is part of an if statement) the whole statement is printed underneath each record, thus:
67 in file
----+----1----+----2-- ... --9----+----0
columns 1 - 100 are |0015263-16*735 *837361 ... 79&
if (c14n'1/4') write
This example checks whether column 14 contains a 1/4. This record has been printed out because it contains a ‘5’ instead.
Sometimes, it is more helpful to have explanatory text printed instead of the statement itself. To do this, follow the word write with the text to be printed enclosed in dollar signs:
if (c308n'1/5') write $c308 incorrect$
if (numb(c117,c118,c119).gt.3) write $too many choices$
might give:
Quantum edit report

Record 17 51 in file
----+----1----+----2-- ... --9----+----0
columns 101 - 200 are |00170116548986131*46*1 ...
columns 201 - 300 are |0017026464515 875 ** ...
columns 301 - 400 are |0017031929-5897231 ...
c308 incorrect
too many choices

Record 32 94 in file
----+----1----+----2-- ... --9----+----0
columns 101 - 200 are |003201837021 **53798 ...
columns 201 - 300 are |0032021353452 763736 ...
columns 301 - 400 are |003203212 & ...
too many choices
The first statement writes out all records in which column 308 does not contain any of the codes 1/5, and the second picks up all records having more than 3 codes in columns 117 to 119.
Normally, all output from write goes to the default print file, and whenever the current record is written to this file, the variable printed_ becomes true. You can change the output file by following the word write with the name of the file to write to. For example:
write pfile $First Print$
writes to the file ‘pfile’.
write errors $Second Print$
writes to a file called ‘errors’.
All files named on write statements must be defined on a filedef statement before they are used: see Defining the file type.
If two or more write statements apply to a single record, the record is printed out once in the state it was when the first applicable write was read, with all relevant write statements or texts listed below it. If a record satisfies two or more write statements which write to different files, Quantum writes the record out once for each statement, in the state it is when each write is executed.
Note If you want to write out more than one field at a time, or to print more than one text, you can define those fields and/or texts on an ident statement. All write statements from that point on will then print those fields and texts.
More information
For more information about ident, read Default print parameters for write statements.
See also
Print files