5.4.5.11 Put Statement

 put-statement = "Put" file-number ","[record-number] "," data
  
 record-number = expression 
 data = expression

Static Semantics.

§ The declared type of a <data> expression MUST NOT be Object, a named class, or a UDT whose definition recursively includes such a type.

§ If no <record-number> is specified, the effect is as if <record-number> is the current file-pointer-position.

Runtime Semantics.

  • An error (number 52, "Bad file name or number") is raised if the file number value (section 5.4.5.1.1) of <file-number> is not a currently-open (section 5.4.5.1) file number (section 5.4.5).

  • The value of <record-number> is defined to be the value of <record-number> after it has been Let-coerced to a Long.

  • If the <mode> for <file-number> is Binary:

    • The file-pointer-position is updated to be exactly <record-number> number of bytes from the start of the file underlying <marked-file-number>.

    • The value of <data> is written to the file at the current file-pointer-position (according to the rules defined in the Variant Data File Type Descriptors and Binary File Data Formats tables). 

    • If <data> is a UDT, then the value of each member of the UDT is written to the file at the current file-pointer-position (according to the rules defined in the Variant Data File Type Descriptors and Binary File Data Formats tables), in the order in which the members are declared in the UDT.

  • If the <mode> for <file-number> is Random:

    • The file-pointer-position is updated to be exactly (<record-number> * <rec-length>) number of bytes from the start of the file underlying <marked-file-number>. o The value of <data> is written to the file at the current file-pointer-position (according to the rules defined in the Variant Data File Type Descriptors and Binary File Data Formats tables).

    • If <data> is a UDT, then the value of each member of the UDT is written to the file at the current file-pointer-position (according to the rules defined in the Variant Data File Type Descriptors and Binary File Data Formats tables), in the order in which the members are declared in the UDT.

    • If the number of bytes written is less than the specified <rec-length> (see section 5.4.5.1) then the remaining bytes are written to the file are undefined. If the number of bytes written is more than the specified <rec-length>, an error is generated (#59, "Bad record length").

    When outputting a variable whose declared type is Variant, a two byte type descriptor is output before the actual value of the variable.

    Variant Kind

    Type Descriptor Byte 1

    Type Descriptor Byte 2

    Unknown

    ERROR

    -

    User Defined Type

    ERROR

    -

    Object

    ERROR

    -

    Data value Empty

    00

    00

    Data value Null

    01

    00

    Integer

    02

    00

    Long

    03

    00

    Single

    04

    00

    Double

    05

    00

    Currency

    06

    00

    Date

    07

    00

    String

    08

    00

    Error

    10

    00

    Boolean

    11

    00

    Decimal

    14

    00

    LongLong

    20

    00

 

Once the type descriptor has been written to the file (if necessary), the literal value of the variable is output according to the rules described in the following table:

Data Type

Bytes to write to file

Integer

A two byte signed integer output in little-endian form. See _int16 in [MS-DTYP].

Long

A four byte signed integer. See _int32 in [MS-DTYP].

Single

A four byte IEEE floating point value. See float in [MS-DTYP].

Double

An eight byte IEEE double value. See double in [MS-DTYP].

Currency

An eight byte Currency value. See [MS-OAUT] section 2.2.24.

Date

An eight byte Date value. See [MS-OAUT] section 2.2.25.

String

In random mode, the first two bytes are the length of the String. If the value is more than 64 kilobytes, then the value of the first two bytes is FF FF. In binary mode there is no two-byte prefix, and the String is stored in ANSI form, without NULL termination

Fixed-length String

There is no two-byte prefix, and the String is stored in ANSI form, without NULL termination

Error

The value of the error code. See HRESULT in [MS-DTYP].

Boolean

If the data value of the Boolean is True, then the two bytes are FF FF. Otherwise, the two bytes are 00 00.

Decimal

A 16 bytes Decimal value. See [MS-OAUT] section 2.2.26.