table manipulate (selected rows)

Prev Next

Function Names

table manipulate, table manipulate selected rows

Description

Referring to table process selected rows(), the condition expressions and following statements to be executed on applicable rows need to be coded directly in the B4P program. Alternatively, one or more sets of expressions and statements can be provided in a table, and that table will be applied to process a different table.

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 and table contents

Parameter count

4

Parameters

No.TypeDescription
1.
input
string Name of existing target table

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

Applicable to table manipulate selected rows only:
This expression is applied to the table before any of the conditions or statements specified in the lookup table are executed.

Specify the conditions or rules to select the rows. See expressions to select rows. It will be calculated only once per row (and not for every cell).
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
string Name of existing lookup table

This table must contain two columns: One for the expressions and one for the statements.

3. / 4.
input
table column Column in lookup table containing conditional expressions

The table column specified here must contain B4P expressions which return either Boolean true or false.
See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • Only 1 header name or column number may be specified.

The table context for partial table specifications referring to the target table is available for referencing just the columns easily. Example: [Year]>=2022.
All these expressions are calculated for every (selected) row in the target table. If the expressions return true, then the corresponding statement(s) specified in the lookup table column named in the next function parameter will be executed.

4. / 5.
input
table column Column in lookup table containing statements to execute

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

  • Only 1 header name or column number may be specified.

The table context for partial table specifications referring to the target table is available for referencing just the columns easily. Example: [Full Name]=[First Name]+' '+[Last Name];.

Opt. 5. / 6.
input
table column Column in lookup table containing conditional stopping expressions

This optional table column may contain expressions returning boolean values. These expressions are calculated only if the corresponding statements in the same row have been executed, also meaning that the corresponding condition specified in the 3. / 4. parameter was true. If the calculated condition is true, or simply true has been specified, then the further rows in the lookup table will no longer be checked and executed for the current row in the target table.

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

  • Only 1 header name or column number may be specified.

Default value: false (execution will continue till end of lookup table reached)

Examples



       table initialize( animals,
           { { Animal, Leg Count, Comment },
           { ant, 6 }, { rat, 4 }, { octopus, 8 }, { centipede, 100 }, { parakeet, 2 },
           { tick, 8 }, { orang utan, 2 or 4 }, { human, 2 }, { lobster, 8 }, { snake, 0 }, { dog, 4 },
           { cat, 4 }, { kangaroo, 2 or 4 }, { fly, 6 }, { alien, 3 }, { worm, 0 }, { emu, 2 } }  );

       table copy table (animals, a2 );


       table initialize( lookup, {
           { Condition,                  Todo,                                             Stop  },
           { "[Leg Count] = '*or*'",     "[Comment] = 'Leg count probably unclear'",       false },
           { "[Leg Count] > 6",          "[Comment] = 'Many legs'",                        true  },
           { "[Leg Count] > 6",          "[Comment] = 'Lots of legs'",                     false },
           { "[Animal] = rat",           "[Animal] = 'mouse'; [Comment] += 'not a rat'",   false },
           { "true",                     "[Animal] = ![Animal]",                           false } } ); // Upper case of ALL


       echo("Demonstrate 'table manipulate selected rows' on animals with 6 or more legs (stop there if condition met):");
       table copy table( animals, a1 );
       table manipulate selected rows( a1, [Leg Count]>=6, lookup, Condition, Todo, Stop );
       table list ( a1 );

       echo("Demonstrate 'table manipulate' on all rows:");
       table copy table( animals, a1 );
       table manipulate( a1, lookup, Condition, Todo );
       table list( a1 );

       echo("Equivalent alternative appraoch intead of using 'table manipulate',but a bit more cryptic:" );

       table process( lookup, table process selected rows( a2, :[Condition], :[Todo] ) );
       table list( a2 );

Output

Demonstrate 'table manipulate selected rows' on animals with 6 or more legs (stop there if condition met):
    0 : Animal     | Leg Count | Comment  
    1 : Ant        | 6         |          
    2 : rat        | 4         |          
    3 : octopus    | 8         | Many legs
    4 : centipede  | 100       | Many legs
    5 : parakeet   | 2         |          
    6 : tick       | 8         | Many legs
    7 : orang utan | 2 or 4    |          
    8 : human      | 2         |          
    9 : lobster    | 8         | Many legs
   10 : snake      | 0         |          
   11 : dog        | 4         |          
   12 : cat        | 4         |          
   13 : kangaroo   | 2 or 4    |          
   14 : Fly        | 6         |          
   15 : alien      | 3         |          
   16 : worm       | 0         |          
   17 : emu        | 2         |          

Demonstrate 'table manipulate' on all rows:
    0 : Animal     | Leg Count | Comment                   
    1 : Ant        | 6         |                           
    2 : Mouse      | 4         | not a rat                 
    3 : Octopus    | 8         | Lots of legs              
    4 : Centipede  | 100       | Lots of legs              
    5 : Parakeet   | 2         |                           
    6 : Tick       | 8         | Lots of legs              
    7 : Orang utan | 2 or 4    | Leg count probably unclear
    8 : Human      | 2         |                           
    9 : Lobster    | 8         | Lots of legs              
   10 : Snake      | 0         |                           
   11 : Dog        | 4         |                           
   12 : Cat        | 4         |                           
   13 : Kangaroo   | 2 or 4    | Leg count probably unclear
   14 : Fly        | 6         |                           
   15 : Alien      | 3         |                           
   16 : Worm       | 0         |                           
   17 : Emu        | 2         |                           

Equivalent alternative appraoch intead of using 'table manipulate',but a bit more cryptic:
    0 : Animal     | Leg Count | Comment                   
    1 : Ant        | 6         |                           
    2 : Mouse      | 4         | not a rat                 
    3 : Octopus    | 8         | Lots of legs              
    4 : Centipede  | 100       | Lots of legs              
    5 : Parakeet   | 2         |                           
    6 : Tick       | 8         | Lots of legs              
    7 : Orang utan | 2 or 4    | Leg count probably unclear
    8 : Human      | 2         |                           
    9 : Lobster    | 8         | Lots of legs              
   10 : Snake      | 0         |                           
   11 : Dog        | 4         |                           
   12 : Cat        | 4         |                           
   13 : Kangaroo   | 2 or 4    | Leg count probably unclear
   14 : Fly        | 6         |                           
   15 : Alien      | 3         |                           
   16 : Worm       | 0         |                           
   17 : Emu        | 2         |                           

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

See also

table process selected rows