| Transactions from Variables to Tables

Prev Next

Introduction

This is the opposite direction where member contents of structures or arrays are transferred into tables. In contrast to transaction to tables without assignment operators, the data in the destination table row will not be deleted. Only the specifed data columns will be overwritten as long as matching data from the source variable is available. Additional columns may be added as long open-ended ranges have been specified.

Destination table rules: See section on Transactions from Variables to Tables.
The only exception is that destination table rows are not cleared, and the open-ended ranges rule does not apply for the | assignment operator. The ^ suffix, if used, does not affect the functionality with copy- and swap-transactions because the destination is a table and table names will not be changed during transactions.

Structures to tables:
The member names will be matched with the existing column header names, provided they are part of the table specification (where whole row, a set of columns, a range or just one column is defined). If a member name cannot be matched with any column header, then an additional header with that name will be added to the table and the data will be written into the designated field below as long open-ended ranges have been specified.

Arrays to tables:
The array members will be written into the table fields as defined in the table specification (whole row, set of columns, a range or just one column). Normally, the members are written to the table from left to right except if a set of columns is specified. In this case, the sequence inside the set will apply. If the array contains more elements than the number of columns (header names) provided, then the remaining elements will not be written into the table unless open-ended ranges have been specified..

Copy and Move Transaction Example
  table initialize( animals,
      { { Name,  Leg count, Special ability  },
        { Owl,   2,         Night vision     },
        { Dog,   4,         Sensitive nose   },
        { Ape,   2 or 4,    Relatively smart } } );

  structure( animal1[], { Name, Special ability, Skin surface, Strange habit },
                        { Bat, "On-flight acoustic radar", skin wings, hangs while sleeping } );

  array( animal2[], { Crab, 10, walks sideways, some are delicious  } );

  [ animals: .., 2 ] |<== animal1[];
  [ animals: .., 3 ] |<<=^ animal2[]; // If ^-symbol is not used, then animal2[] would be deleted.

  see( animal1[] );
  see( animal2[] );
  table list( animals ); // Contains bat and crab and ape with some info
animal1[]               [Void]                     (void,full access)
Name                    Bat                        (softquoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         On-flight acoustic radar    (quoted string,full access)
Strange habit           hangs while sleeping       (softquoted string,full access)

animal2[]               [Void]                     (void,full access)

    0 : Name | Leg count | Special ability          | Skin surface       | Strange habit       
    1 : Owl  | 2         | Night vision             |                    |                     
    2 : Bat  | 4         | On-flight acoustic radar | skin wings         | hangs while sleeping
    3 : Crab | 10        | walks sideways           | some are delicious |                     

Try it yourself: Open LAN_Features_OR_Transactions_from_variables_to_tables.b4p in B4P_Examples.zip. Decompress before use.
Swap Transaction Example
  table initialize( animals,
      { { Name,  Leg count, Special ability  },
        { Owl,   2,         Night vision     },
        { Dog,   4,         Sensitive nose   },
        { Ape,   2 or 4,    Relatively smart } } );

  structure( animal1[], { Name, Special ability, Skin surface, Strange habit },
                        { Bat, "On-flight acoustic radar", skin wings, hangs while sleeping } );

  array( animal2[], { Crab, 10, walks sideways, some are delicious  } );

  [ animals: .., 2 ] |<=> animal1[];  // Swap, with table name in base variable
  [ animals: .., 3 ] |<=>^ animal2[]; // Swap

  see( animal1[] ); // Dog, ...
  see( animal2[] ); // Ape, ...
  table list( animals ); // Contains owl, bat and crab and ape with some info
animal1[]               animals                    (quoted string,full access)
Leg count               4  "4"                     (numeral,full access)
Name                    Dog                        (quoted string,full access)
Skin surface            skin wings                 (softquoted string,full access)
Special ability         Sensitive nose             (quoted string,full access)
Strange habit           hangs while sleeping       (softquoted string,full access)

animal2[]               [Void]                     (void,full access)
Array [   0]            Ape                        (quoted string,full access)
Array [   1]            2 or 4                     (quoted string,full access)
Array [   2]            Relatively smart           (quoted string,full access)
Array [   3]            some are delicious         (softquoted string,full access)

    0 : Name | Leg count | Special ability          | Skin surface       | Strange habit       
    1 : Owl  | 2         | Night vision             |                    |                     
    2 : Bat  | 4         | On-flight acoustic radar | skin wings         | hangs while sleeping
    3 : Crab | 10        | walks sideways           | some are delicious |                     

Try it yourself: Open LAN_Features_OR_Transactions_from_variables_to_tables_01.b4p in B4P_Examples.zip. Decompress before use.