table copy columns ...

Prev Next

Function Names

table copy columns, table copy columns selected rows

Description

This function copies contents from selected columns to another set of selected columns. New columns will be created if the destination header names are not yet existing. Otherwise, the existing columns will be overwritten.
table copy columns selected rows
copies the contents only in rows meeting the conditional expression in the 2nd function parameter.

Call as: procedure or function

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

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

Applicable to function table copy columns selected rows only.
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), ....

2 / 3
input
table columns Existing columns

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

3 / 4
input
table columns New columns

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

  • Number of columns specified must be the same as in the previous parameter.
  • If header names are missing in the table, then additional columns will be created on the right hand side of the table.
  • Column numbers outside the existing range results in creating columns with blank header names.

Return value

TypeDescription
numeral Number of columns copied

Exceptions

Table not found
Header name not found

Examples

       table initialize ( table,
               { { First Name, Last Name, Given Name, Birth Year },
                 { Abel,       Adams,     A.,         1990 },
                 { Betty,      Beavers,   B.,         1995 },
                 { Charlie,    Collins,   C.,         2000 },
                 { Daniela,    Douglas,   D.,         2005 } } );

       table copy columns selected rows( table, [Birth Year]<1998, {First Name, Last Name}, { Given Name, Family Name } );
       // The specified columns in the first two rows will be copied

       table list( table );

Output

    0 : First Name | Last Name | Given Name | Birth Year | Family Name
    1 : Abel       | Adams     | Abel       | 1990       | Adams      
    2 : Betty      | Beavers   | Betty      | 1995       | Beavers    
    3 : Charlie    | Collins   | C.         | 2000       |            
    4 : Daniela    | Douglas   | D.         | 2005       |            

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

See also

table duplicate columns