table move selected rows

Prev Next

Function Names

table move selected rows

Description

This function moves selected rows (using an expression) from one table to another table. With high performance in focus, this function moves the rows as they are, i.e. the individual data stay in their column locations where they are and they will not be realigned in order to match with the header names.

Please consider useing table merge() or transactions if you want to move data with alignments to their headers.

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

Parameter count

4

Parameters

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

2.
input
string Name of existing destination table

3
input
numeral Destination row number

The contents from the source table will be moved to the destination table, beginning with this specified row number in the destination table. All other rows in the destination table will move down. Negative indexing is supported here, whereas -1 is exceptionally referencing to the next row below the last row.

  • 0 = Insert contents above the header row
  • 1 = Insert contents below the header row / above the 1st data row
  • -1 (or table length value) = Insert contents below the last row. -2, -3, etc. count upwards.

If the 3rd parameter is not specified, then the rows will be added to the end of the table. Since the remaining parameters are not specified too, B4P assumes to move the entire table (except header row) to the end of the destination table.

Default value: -1 (below the last table row)
4.
code
expression
:string
Expression to select rows

Specify the conditions or rules to select the rows in the source table. 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), ....

Return value

TypeDescription
numeral Number of rows moved

Number of rows moved. -1 is returned if table is empty.

Exceptions

Table not found

Examples

       table initialize( t1,  { Name, Amy, Bea, Colin, Daniela, Emily, Fabian } );
       table initialize( t2,  { Names, Richard, Sam, Tim, Udo, Victor, Xavier, Yoel, Zoe } );

       echo(  new line, "Original tables");
       echo(  "t1: ", [t1:Name,..] );
       echo(  "t2: ", [t2:Names,..] );

       table move selected rows ( t1, t2, -1, [Name]{}=5 ); // Move Colin and Emily (5 letters)

       echo(  new line, "Move all names from t1 to end of t2");
       echo(  "t1: ", [t1:Name,..] );
       echo(  "t2: ", [t2:Names,..] );

Output

Original tables
t1: {'Amy','Bea','Colin','Daniela','Emily','Fabian'}
t2: {'Richard','Sam','Tim','Udo','Victor','Xavier','Yoel','Zoe'}

Move all names from t1 to end of t2
t1: {'Amy','Bea','Daniela','Fabian'}
t2: {'Richard','Sam','Tim','Udo','Victor','Xavier','Yoel','Zoe','Colin','Emily'}
Try it yourself: Open LIB_Function_table_move_selected_rows.b4p in B4P_Examples.zip. Decompress before use.

See also

table move rows
table merge