table manipulate, table manipulate selected rows
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.
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
4
No. | Type | Description |
---|---|---|
1. input |
string | Name of existing target table |
Opt. 2. code |
expression :string |
Expression to select rows Applicable to table manipulate selected rows only: |
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.
The table context for partial table specifications referring to the target table is available for referencing just the columns easily. Example: [Year]>=2022. |
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.
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.
|
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 );
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 |