table copy table columns ...

Prev Next

Function Names

table copy table columns, table copy table columns selected rows

Description

This function makes a copy of the table with all selected columns.
The function table copy table columns selected rows copies only the selected rows instead of all rows. 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.
input
table columns Header names and/or column numbers

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

  • Any number of header names and column numbers may be specified

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

Applicable for table copy table columns selected rows only: The selected rows will be copied into the new table.
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, Hobby },
      { Ann, 45, Skiing }, { Dan, 35, Skating }, { Eva, 40, Bee keeping }, { Nic, 10, Reading } } );

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

  echo("Copy Hobby and Name:");
  table copy table columns ( t, u, {Hobby, Name} );
  table list( u );

  echo("Copy Name and Age of young people:");
  table copy table columns selected rows ( t, v, {Name, Age}, [Age]<40 );
  table list( v );

Output

Original table:
    0 : Name | Age | Hobby      
    1 : Ann  | 45  | Skiing     
    2 : Dan  | 35  | Skating    
    3 : Eva  | 40  | Bee keeping
    4 : Nic  | 10  | Reading    

Copy Hobby and Name:
    0 : Hobby       | Name
    1 : Skiing      | Ann
    2 : Skating     | Dan
    3 : Bee keeping | Eva
    4 : Reading     | Nic

Copy Name and Age of young people:
    0 : Name | Age
    1 : Dan  | 35
    2 : Nic  | 10

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

See also

table copy table selected rows
table copy table