+ Transactions from Variables to Tables

Prev Next

Introduction

This is the opposite direction where member contents of structures or arrays are transferred and added to the tables. First the existing table contents beginning at the specified row are moved down by 1 line in order to provide a new blank row without deleting any other data. Then the transaction into the new row takes place by transferring the data into the table. 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.

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: .., 3 ] +<== animal1[];  // Bat is added in row 3
  [ animals: .., 2 ] +<<=^ animal2[]; // Crab is added to row 2 (bat moves from row 3 to row 4)

  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 : Crab | 10        | walks sideways           | some are delicious |                     
    3 : Dog  | 4         | Sensitive nose           |                    |                     
    4 : Bat  |           | On-flight acoustic radar | skin wings         | hangs while sleeping
    5 : Ape  | 2 or 4    | Relatively smart         |                    |                     

Try it yourself: Open LAN_Features_ADD_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 and 1 tail,         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[];  // Bat is written to row 2 (other rows move down), other data not overwritten
  [ animals: .., 1 ] +<=>^ animal2[]; // Owl data added to array

  see( animal1[] ); // Gets leg count from the 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 and 1 tail               (quoted string,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)
Array [   0]            Crab                       (softquoted string,full access)
Array [   1]            10  "10"                   (numeral,full access)
Array [   2]            walks sideways             (softquoted string,full access)
Array [   3]            some are delicious         (softquoted string,full access)
Array [   4]            Owl                        (quoted string,full access)
Array [   5]            2  "2"                     (numeral,full access)
Array [   6]            Night vision               (quoted string,full access)

    0 : Name | Leg count    | Special ability          | Skin surface       | Strange habit       
    1 : Crab | 10           | walks sideways           | some are delicious |                     
    2 : Owl  | 2            | Night vision             |                    |                     
    3 : Bat  |              | On-flight acoustic radar | skin wings         | hangs while sleeping
    4 : Dog  | 4 and 1 tail | Sensitive nose           |                    |                     
    5 : Ape  | 2 or 4       | Relatively smart         |                    |                     

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