Read Data

From Br Wiki
Jump to: navigation, search

The Read (REA) data statement assigns values to variables from internal lists created by DATA statements.

Comments and Examples

READ statements automatically match themselves up to DATA statements. A program's first READ statement variable is set to its first DATA statement value; the second READ statement variable is set to the second DATA statement value; and so on. When a READ statement has more variables than a DATA statement has values, Business Rules searches for the program's next DATA statement. In the following example, the execution of line 55 assigns 2 to T, 4 to F, 8 to E, 16 to S, 32 to X and 64 to M:

00045 DATA 2, 4, 8
00055 READ T, F, E, S, X, M
00065 DATA 16, 32, 64, 128, 512

The following example shows how the CNT internal function can be used to determine how many variables have been read:

00010 DIM A (20)
00020 DATA 1,1,1,1,1
00030 READ MAT A EOF 40
00040 MAT A (CNT)

Syntax

READ {Mat <array name>|<variable name>}[,...] [<error condition> <line ref>][,...]

Readdata.png

Default

  1. Interrupt the program if an error occurs and ON error is not active.

Parameters

The "MAT array-name" and "var-name" parameters represent the list of variables to be assigned to DATA statement values. Multiple specifications must be separated with commas.

READ's optional "error cond line-ref" tells the system what to do when an error occurs. See Error Conditions for more information.

Technical Considerations

  1. Relevant error conditions are: CONV, EOF, ERROR, EXIT, and SOFLOW.
  2. When there are more variables in a program's READ statements than there are values in its DATA statements, Business Rules! returns error code 0054 (out of data for READ). This error can be trapped with the EOF error condition.
  3. When a program's DATA statements contain more values than its READ statements contain variables, no error will occur. The extra values are available for the next READ statement.
  4. Array references in a data-item list are assigned values by row/column. READ assigns values all the way across a row before it moves on to the next row.