table process (all) (selected rows)

Prev Next

Function Names

table process, table process rows, table process all rows, table process selected rows, table process all selected rows

Description

These are one of the most powerful functions in the B4P language: The ability to process the contents in tables row-by-row without formulating loops or complex algorithms. The statements for processing the data in every row are provided as function parameters and will be executed for every single row selected. Combined with already available table context for partial table specifications, you can do powerful algorithms with minimum amount of simple code text. See code examples further below.

The all in the function name indicates that row 0 (header row) is to be included for processing.

For consistency with related function names, table process rows has been added and is identical to table process

The closest relative of this function is for all table rows() which describes a loop using loop index

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

2-4

Parameters

No.TypeDescription
1.
input
string Name of existing table

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

Applicable to table process 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.
code
statements
:string
Statements (applicable where rows are selected)

table process / table process rows: The statements provided will be executed for every row.
table process selected rows: The statements provided will be executed for every row where the condition calculated before returned true.

The table context for partial table specifications is available for referencing just the columns easily. Example: [Full Name]=[First Name]+' '+[Last Name];.
Hint: If you encounter an error message at the very end of the program after you worked on a statement, you may proabably have forgotton to add the closing parentheses to close the function call.

4.
code
statements
:string
Statements (otherwise)

table process / table process rows: Not applicable. This function accepts 3 parameters only. table process selected rows: The statements provided will be executed for every row where the condition calculated before returned false.

The table context for partial table specifications is available for referencing just the columns easily. Example: [Full Name]=[First Name]+' '+[Last Name];.
Hint: If you encounter an error message at the very end of the program after you worked on a statement, you may proabably have forgotton to add the closing parentheses to close the function call.

Return value

TypeDescription
numeral Number of rows processed

With table process selected rows, the number of selected rows (and processed with statements from 3rd function parameter) are counted. With the function table process selected rows, only the processing for 'true' matches are counted.

Examples

  table initialize ( animals, { {Animal, Group, Characteristics},
       { parakeet, bird },  { moose, mammal },  { ape, mammal },  { sparrow, bird } , { trout, fish }, { bass, fish },
       { canary, bird }, { penguin, bird }, { beluga, mammal} } );

  table process           ( animals, [Animal] = ![Animal] ); // Capitalize
  table process selected rows ( animals, ([Group] = bird), [Characteristics] = "Can fly", [Characteristics] = "Can't fly" );
  table process selected rows ( animals, ([Group] = fish) | ([Animal]=Penguin,Beluga), [Characteristics] = "Can swim" );

  table list ( animals );

Output

    0 : Animal   | Group  | Characteristics
    1 : Parakeet | bird   | Can fly        
    2 : Moose    | mammal | Can't fly      
    3 : Ape      | mammal | Can't fly      
    4 : Sparrow  | bird   | Can fly        
    5 : Trout    | fish   | Can swim       
    6 : Bass     | fish   | Can swim       
    7 : Canary   | bird   | Can fly        
    8 : Penguin  | bird   | Can swim       
    9 : Beluga   | mammal | Can swim       

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

See also

table process selected rows fast
table process cells
table process cells selected rows
table process columns
table process columns selected rows
table manipulate