table multiply ...

Prev Next

Function Names

table multiply, table multiply selected rows

Description

A cartesian multiplication will be applied on the destination table using the data from the source table. All (selected) rows in the destination table will be repeated by the number of rows in the source table and the additional columns be repeatedly appended.
table multiply selected rowstakes an extra parameter to specify abBoolean expression to select rows to multiply and leave the remaining rows unchanged.
Attention: Multiplication by zero rows: If the source table contains zero rows below the headers, then a multiplication by zero will happen, which means that the rows in the destination will be removed.
Function 'table multiply'

Call as: procedure

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters

Parameter count

2-4

Parameters

No.TypeDescription
1.
input
string Name of existing source table

2.
input
string Name of destionation table

Opt. 3.
code
expression
:string
Expression to select rows

Applicable to function table multiply selected rows only, addressing the rows in the destination table.
Specify the conditions or rules to select the row. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

Default value: true (all rows selected)
Opt 3./4.
input
table column Destination columns

Specify a header name or column number where to insert the new columns added. The specified column and further ones to the right will shift to the right accordingly.
Negative number are supported for indexing from right to left, however -1 refers to the end of the table, -2 to left of last column, etc.

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Only 1 header name or column number may be specified.

Default value: -1 (behind last column)

Examples

  table initialize( colors,
      { { Color,  Delight, Another Delight },
        { red,    tomatoes,  strawberries },
        { yellow, bananas,   lemons },
        { green,  lettuce,   cucumbers },
        { blue,   plums,     blueberries } } );

  table initialize( shades,
      { { Shade,   Example 2 }, { Dark, moonshine }, { Light, sunshine } } );

  table multiply selected rows( shades, colors, ([Color]<>green), Another Delight );

  // Why parentheses used in the 3rd parameter?
  // Comparison would otherwise hijack the 4th parameter.
  // Alternatively, use '!=' which expects only 1 comparison operand.

  table list ( colors );

Output

    0 : Color  | Delight  | Shade | Example 2 | Another Delight
    1 : red    | tomatoes | Dark  | moonshine | strawberries   
    2 : red    | tomatoes | Light | sunshine  | strawberries   
    3 : yellow | bananas  | Dark  | moonshine | lemons         
    4 : yellow | bananas  | Light | sunshine  | lemons         
    5 : green  | lettuce  |       |           | cucumbers      
    6 : blue   | plums    | Dark  | moonshine | blueberries    
    7 : blue   | plums    | Light | sunshine  | blueberries    

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

See also

table divide