WRITE (FILE)


ANSI

 

The WRITE instruction transfers information from program variables into a disk file.

 

(1)

[label]

WRITE

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

(2)

[label]

WRITE

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

 

Where:

label

Optional. A Program Execution Label.

file

Required. A previously defined and opened FILE variable in which data is written.

record

Required. A previously defined Numeric Variable that selects the record written.

list

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

;

Optional. 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 loaded with data to be written.

Flags Affected: NONE

Note the following:

  1. 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 butmay be adjusted using the BUFFER/FIX/FIXED FILE declaration parameter.

  2. 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:

  3.  

    Control

    Function

    -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, Ctrl values 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. Ctrl values and literals are written to the disk exactly as specified in {list}.

  3. The supported list controls are as follows:

  4.  

    Control

    Function

    *+

    Enable space compression

    *-

    Disable space compression

    *CDFOFF

    Disable *CDFON

    *CDFON

    Enable comma-delimited Field support

    *EDIOFF

    Disable *EDION

    *EDION

    Enable Electronic Data Information support

    *LC

    Data is written in the case in which it was stored

    *LL

    Forces output of only the Logical String

    *MP

    Minus overpunch negative numeric variables

    *PL

    Disable *LL (default)

    *UC

    lower case characters are converted to upper case before being written

    *ZF

    Zero-fill numeric variables

    *ZS

    Blank-fill zero numeric variables

 

  1. Tabbing is not allowed with the WRITE instruction. If tabbing is desired, the WRITAB instruction should be used.

  2. If a semi-colon (;) terminates the list, the rules relevant to partial writes apply (see Partial I/O). Partial IO is not allowed for SQLIO.

  3. Space compression is disabled unless explicitly enabled through *+.

  4. Any short records written to the file are padded with blanks to the record length.

  5. When using the single unlocking mode, a WRITE to a record that is not locked unlocks the currently locked record before the WRITE begins.

  6. When using the single unlocking mode, a WRITE to a locked record unlocks the record when the operation completes.

  7. When a view schema is assigned to an FILE variable (9.4), the WRITE instruction can optionally use the column name syntax (format 2 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.

  8.  

    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 WRITE 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.

    .

               WRITE FILE, SEQ; PRODID=myProdid

    .

               MOVE "PRODID", myParam

               WRITE FILE, SEQ; @myParam=myProdid

    .

     

  9. If the column name syntax format is being used, partial IO using the semicolon character (;) is not allowed and a runtime error will result.

  10. If the column name syntax format is being used and all of the view column names are not included in the WRITE variable list, any unspecified fields are either blank filled or filled with a default value specified in the view schema. For a file opened or created with fixed length records, the WRITE instruction writes the full record with appropriate default data for unspecified fields. For a file opened or created with variable length records, the WRITE instruction writes all of the fields up to and including the last column that has been specified with unspecified fields being appropriately filled with default data.

 

 

See Also: Example Code, READ (FILE), WRITAB, WEOF, Disk I/O Instructions

 



PL/B Language Reference WRITE (AFILE) WRITE (FILELIST)