table duplicate columns

Prev Next

Function Names

table duplicate columns

Description

This function duplicates specified columns to a destination column and assigns new header names accordingly. No existing columns will be overwritten. If the destination column is not at the end of the table, then the existing columns on the right will shift to the right in order provide space for the destination columns. In contrast to table copy columns, if a destination header name is already existing, existing columns remain untouched.

Call as: procedure or function

Restrictions

Indirect parameter passing is disabled

Parameter count

3, 4

Parameters

No.TypeDescription
1.
input
string Name of existing table

2
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
input
table columns New header names

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.
  • Only header names are allowed. Column numbers are not allowed.
  • Even if the header names are already existing, new columns (with same names) will be created anyhow.

3
input
table column Destination column

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

  • Only one header name or column number may be specified.
  • Existing columns further to the right will shift accordingly to clear space for new columns.

Return value

TypeDescription
numeral Number of columns duplicated

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 duplicate columns( table, { Birth Year, Given Name }, { BY, GN }, First Name );

  table list( table );

Output

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

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

See also

table duplicate columns