table copy/split table selected rows

Prev Next

Function Names

table copy table selected rows, table split table selected rows

Description

This function makes a copy of the table with selected rows only. The function table split table selected rows removes the transferred rows from the original table. If the new table is already existing, then it will be initialized.

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

3-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

2.
input
string Name of new table

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

Applicable to table split table selected rows only: The selected rows will be moved into the new table. If the same row is also mentioned in the 4th parameter, then the row will be copied and not moved.
Specify the conditions or rules to select the rows. 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), ....

Opt. 3. / 4.
code
expression
:string
Expression to select rows to copy

The selected rows will be copied into the new table. Rows specified for both splitting and copying will be considered for copying.
Specify the conditions or rules to select the rows. 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), ....

Examples

  table initialize( t, {{ Name, Age }, { Ann, 45 }, { Dan, 35 }, { Eva, 40 }, { Nic, 10 } } );

  echo("Original table:");
  table list( t );

  table copy table selected rows ( t, u, [Age]>=40 );
  echo("Copied table:");
  table list ( u );

  table split table selected rows( t, v, [Age]>=40, [Name]=Eva );
  echo("Source table after splitting: ");
  table list (t );
  echo("Destnation table after splitting: ");
  table list (v );

Output

Original table:
    0 : Name | Age
    1 : Ann  | 45
    2 : Dan  | 35
    3 : Eva  | 40
    4 : Nic  | 10

Copied table:
    0 : Name | Age
    1 : Ann  | 45
    2 : Eva  | 40

Source table after splitting:
    0 : Name | Age
    1 : Dan  | 35
    2 : Eva  | 40
    3 : Nic  | 10

Destnation table after splitting:
    0 : Name | Age
    1 : Ann  | 45
    2 : Eva  | 40

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

See also

table copy table
table copy table columns
table split table columns