Reads the next record of a file into the specified variables.
Number assigned in OPEN to the file to be read.
any_var:length_int_lit|_var|_col
One or more variables into which data from the record read are to be put. length_int_lit|_var|_col specifies the length of each field of data.
Optional variable into which a read status is returned.
Text and binary data is parsed according to the following:
Text data is any string of characters. The length of the variable name indicates how many characters to place into the variable. After being transferred, trailing blanks in the variable are omitted.
If the field was written as a date variable, then it may be read into a date variable or text variable. When reading a date into a date variable, it must be in the format specified by SQR_DB_DATE_FORMAT, one of the database-dependent formats in Table 61, Default Formats by Database or the database-independent format 'SYYYYMMDD[HH24[MI[SS[NNNNNN]'.
Binary numbers, may be 1, 2, or 4 bytes in length. They must be read into numeric variables. Note that the bytes making up the binary number must be in the standard sequence expected by your operating system.
When reading binary data the file must be opened with the FIXED or FIXED‑NOLF qualifier.
Only the integer portion of the number is represented with binary numbers. To maintain the decimal portion of the number convert the number to a string variable.
If you use binary numbers, the file is not portable across platforms. This is because different hardware represents binary numbers differently.
The total length indicated for the variables must be less than or equal to the length of the record being read.
If there are no more records to read, the #end-file reserved variable is set to 1; otherwise, it is set to 0 (zero). Your program should check this variable after each READ command.
If STATUS is specified, Production Reporting returns 0 if the read is successful; otherwise, it returns the value of errno, which is system-dependent.
The following example shows several READ commands:
read 1 into $name:30 $addr:30 $city:20 $state:2 $zip:5 read 3 into $type:2 #amount:2 #rate:1 $code:5 $date:11 read #j into #sequence:2 $name:20 $title:15
The following example shows a READ command that reads two dates. One is loaded into a date variable; the other is loaded into a string variable, which is then converted to a date using the strtodate function.
. . . declare-variable date $date1 $date2 text $text end-declare . . . read 4 into $date1:18 $text1:18 let $date2 = strtodate($text1,'SYYYYMMDDHHMISSNNN') or let $date2 = strtodate($text1)
The following example shows a READ command with an INSERT loop:
while 1 ! Infinite loop, exited by BREAK, below. read 10 into $company:40 $parent:30 $location:50 if #end-file break ! End of file reached. end-if begin-sql insert into comps (name, parent, location) values ($company, $parent, $location) end-sql add 1 to #inserts if #inserts >= 100 begin-sql end transaction; begin transaction end-sql move 0 to #inserts end-if end-while