READ, READTAB, READLK (FILE)


ANSI

 

The READ instruction retrieves information from disk and transfers that information into data variables. The statement format is as follows:

 

(1)

[label]

READ

{file},{record};[{list}][;]

(2)

[label]

READ

{file},{record};[columnname={variable}][,...][;]

(3)

[label]

READTAB

{file},{record};[{list}][;]

(4)

[label]

READTAB

{file},{record};[columnname={variable}][,...][;]

(5)

[label]

READLK

{file},{record};[{list}][;]

(6)

[label]

READLK

{file},{record};[columnname={variable}][,...][;]

 

Where:

label

Optional. A Program Execution Label.

file

Required. A previously defined and opened FILE variable from which data is read.

record

Required. A previously defined Numeric Variable or Expression that selects the record to read.

list

Optional. Any combination of previously defined Character String Variables, Numeric Variable, string or numeric ARRAYs, or individual array elements, VARLISTs of string or numeric variables, or valid Disk I/O List Controls.

;

Optional unless list not specified. A semicolon indicating Partial I/O.

columnname

Required. The column name as specified in the VIEW that was assigned to the file variable by the OPEN or PREPARE instruction. The column named is not case sensitive.

variable

Required. The variable that has been previously declared and is loaded with data read.

Flags Affected: LESS, OVER, ZERO

Note the following:

  1. READ and READTAB are synonyms.

  2. If the manual record locking mode is in effect, the READLK form locks the record as it is read.

  3. If manual record locking is in effect, a READ performs a traditional read operation with an implied FILEPI and temporarily locks the data record only for the duration of the READ statement. The READ clears the temporary record lock when the operation is completed. The READ in this case honors the WAIT mode as expected for the record locking operations.

  4. If the automatic record locking mode is in effect, all forms of this instruction lock the record as it is read.

  5. If {record} is equal to or greater than zero, it designates a sector in the file for random or direct access (see Random Access Method). The first sector in the file is zero (0) and each subsequent sector increments the reference appropriately. The relative sector size defaults to 256 bytes but may be adjusted using the BUFFER/FIX/FIXED FILE declaration parameter.

  6. If {record} is a negative number equal to -1, -2, -3 or -4, it indicates sequential file processing (see Sequential Access Method). The differences are as follows:

  7.  

    Value

    Action

    -1

    Sequential forward processing

    -2

    Sequential forward processing

    -3

    Position to End Of File (EOF) prior to processing

    -4

    Sequential backward processing

 

  1. {list} may be any combination of character string and/or numeric variables (including arrayed items), character string and/or numeric literals and/or supported list controls separated by commas. If an ARRAY variable is given without a specific array element designated, all elements of the array are processed.

  2. When reading a data field into a FORM variable, any non-leading white space characters read are converted to zero characters. This read IO behavior exists because this was the legacy behavior that existed for the original Databus IO read instructions. As an example, if the data being read is 's1s2s3', where the 's' character is a white space, the resulting FORM variable value would be 's10203' where 's' character is a white space. This read IO behavior is the default for Sunbelt runtimes. For runtime versions 9.4D or later, this behavior can be changed using the PLB_ANSIIO runtime keyword or the SETMODE *PLBANSIIO keyword to force a FORMAT error when non-leading white space characters are encountered.

  3. {list} may be optionally excluded if two semi-colons (;;) are specified after {record}. This technique only positions the file pointer to the beginning of the record/sector without actually reading any data.

  4. The supported list controls are as follows:

  5.  

    Control

    Function

    *ABSON

    Enable absolute transfer of file data

    *ABSOFF

    Disable *ABSON

    *CDFOFF

    Disable *CDFON

    *CDFON

    Enable comma-delimited Field support

    *EDIOFF

    Disable *EDION

    *EDION

    Enable Electronic Data Information support

    *LC

    Disable *UC (default)

    *LL

    Set the Length Pointer to last non-blank character

    *{n}

    Tab to the {n}'th character offset in the given record

    *PL

    Disable *LL (default)

    *TAB={n}

    Tab to the {n}'th character offset in the given record

    *UC

    Convert lower case data to upper case

 

  1. When using tabbing (*n) in a text file, the tab position is relative to the first position in the sector being processed.

  2. If an attempt is made to read past the End Of File (EOF) indicator (using -1 or -2) or if an attempt is made to read before the beginning of the file (using -4), the OVER Condition Flag is set and the LESS Condition Flag is cleared, all numeric variables in the list are set to zero (0) and all character string variables in the list are blank-filled and CLEARed.

  3. If a semi-colon (;) terminates the list, the rules relevant to partial reads apply (see Partial I/O).

  4. It is assumed the data file may have space compression and FORM fields may be in minus overpunch format during the input mode. If space compression is present in the file and record locking is not in effect, the LESS Condition Flag is set. If record locking is in effect, the LESS Condition Flag indicates a lock failure.

  5. If deleted characters are found (Hex/Octal 00), the ZERO Condition Flag is set.

  6. An I44 error can occur with a random read if the data has been deleted.

  7. If a FORMAT error occurs, the record pointer is returned to its original position prior to the read.

  8. If a locking conflict occurs, the read fails and the following actions take place:

  1. Record Locking was added in version 8.2 and is not available when using the PLBCE runtime.

  2. When a view schema is assigned to a FILE variable (9.4), the READ instruction can optionally use the column name syntax (format 2, 4, and 6 above). When the column name syntax is being used, all variables used in the instruction variable list must have column names specified. When the column name syntax is not being used, no variables in the instruction variable list can have column names.

  3.  

    If the column name syntax specified with the 'columnname' parameter is being used, the 'columnname' parameter can be one of the following:

     

    Column name as specified by the VIEW column definitions.

     

    @{svar} where {svar} is a variable that contains the column name as specified by the VIEW column definitions.

    Example:

    FILE FILE

    SEQ FORM "-1"

    myProdid DIM 10

    myParam DIM 50

    ...

    . Both of these READ syntax formats give the same results when

    . using a VIEW definition column name of 'PRODID' and the FILE

    . is opened with VIEW definition being used.

    .

               READ FILE, SEQ; PRODID=myProdid

    .

               MOVE "PRODID", myParam

               READ FILE, SEQ; @myParam=myProdid

    .

     

     

  4. If the column name syntax format is being used, partial IO using the ';' character is allowed.

  5. If the column name syntax format is being used, the data is retrieved from the data record using the VIEW data type, location, and field size that has been defined for a column. After the column data field is retrieved, the data is moved into the final destination variable specified by {variable}.

 

 

See Also: Example Code, WRITE (FILE), Disk I/O Instructions

 



PL/B Language Reference READ, READTAB, READLK (AFILE) READ, READTAB, READLK (IFILE)