table move rows

Prev Next

Function Names

table move rows

Description

This function moves a specified number of rows 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

Parameter count

2 - 5

Parameters

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

2.
input
string Name of existing destination table

Opt. 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)
Opt. 4
input
numeral Source starting row number

Row movement begins at the specified row number. Negative indexing is supported here.

  • 0 includes the header row (row 0)
  • 1 begins with first data row
  • -1 moves the last row only
  • -2 moves the last two rows

Default value: 1 (1st data row without header)
Opt. 5
input
numeral Source ending row number

Row movement ends at specified row number, including that row. No rows will be transferred if it is smaller than the starting row number. Negative indexing is supported here where -1 refers to the last existing row.

Default value: -1 (till end of table, including last row)

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 rows ( t1, t2 );

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

  table move rows( t2, t1, -1, 9 );

  echo(  new line, "Move the same names back to t1");
  echo(  "t1: ", [t1:Name,..] );
  echo(  "t2: ", [t2:Names,..] );

  table move rows( t2, t1, 4, 3, 5 );

  echo(  new line, "Move 3 names (Tim, Udo, Victor) in t2 to t1 before Daniela");
  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: {}
t2: {'Richard','Sam','Tim','Udo','Victor','Xavier','Yoel','Zoe','Amy','Bea','Colin','Daniela','Emily','Fabian'}

Move the same names back to t1
t1: {'Amy','Bea','Colin','Daniela','Emily','Fabian'}
t2: {'Richard','Sam','Tim','Udo','Victor','Xavier','Yoel','Zoe'}

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

See also

table move selected rows
table merge