table keep ... columns

Prev Next

Function Names

table keep columns, table keep existing columns

Description

This function keeps and rearranges the columns specified according to the order provided in the 2nd function parameter. All remaining columns will be deleted.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

2

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
  • Appliable to table keep existing columns: No exceptions are asserted if header names are missing or column numbers are out of range.
  • Repeating the same columns (e.g. with intention to duplicate them) is not allowed.

Exceptions

Table not found
Header name not found

Examples

  table initialize ( table, { { First Name, "Middle Init.",    Last Name, "Street",      "Town" },
                  { Jane,       "E.",              Archer,    "1. Main St.", "Miami", "Comments" } } );

  echo("Original table: ", table max width(table), " columns. __________________ ");
  table list( table );

  table copy table (table, t1 );
  table keep columns(t1, { 2, First Name, -1 }); // Last Name, First Name, Town
  echo("Names only: ", table max width(t1), " columns. __________________ ");
  table list( t1 );

  table copy table (table, t1 );
  table keep existing columns(t1, { Phone, 2, First Name, -1 }); // Same outcome: "Phone" is ignored.
  echo("Names only: ", table max width(t1), " columns. __________________ ");
  table list( t1 );

Output

Original table: 6 columns. __________________
    0 : First Name | Middle Init. | Last Name | Street      | Town  |         
    1 : Jane       | E.           | Archer    | 1. Main St. | Miami | Comments

Names only: 3 columns. __________________
    0 : Last Name | First Name | Town
    1 : Archer    | Jane       | Miami

Names only: 3 columns. __________________
    0 : Last Name | First Name | Town
    1 : Archer    | Jane       | Miami

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

See also

table rearrange columns