/

 

The manual

Self-training

Experimentation

Contact

 

Language

Management of sub tables

Browse a sub table

Suppose you have constructed a form, with an 'article' sub-table containing the 'quantity' and 'price' fields, as well as a simple 'total' field.
You can then write something like:

var Float t := 0
each quantity
  t := t + quantity * price
total := t

It is important to note that 'each' takes as parameter not the name of the sub table, but the name of one of its fields.
It is therefore imperative not to use the same variable name (of column) in different sub tables of the same file.

Finally, the 'sum' function is used to total all the values \u200b\u200bof a field (a column in a sub table).
For example:

var Float q := sum quantity

is equivalent to

var Float q := 0
each quantity
  q := q + quantity

Creation, deletion of rows in a sub table

To add a line, use the 'create' instruction:

create quantity
  quantity := ...
  price := ...

or

create quantity "foo"
  quantity := ...
  price := ...

or

create quantity "foo"

As in the case of 'each', the table is not identified by its name, but by the name of one of its fields. Also, in this example, 'foo' is the code for the new line to be created.
The first form is the simplest: Storga chooses the code for the new line.
In the second form, you choose the code for the new line. The lines will be ordered according to the lexicographical order of the codes chosen.
The third form exists for historical reasons, and requires to then use a 'group' statement (see below) to fill in the fields of the new row.

To delete it:

delete quantity "foo"

You can also delete all the lines at once:

delete_all quantity

Warning: as a sub table must not be empty, otherwise the list of associated fields would be lost, if you destroy all the rows of a sub table, an empty row will be added automatically.

Go specifically to a line

Finally, you can access one of the lines:

group quantity "foo"
  price := 1

Which is equivalent to:

each quantity
  if group_id="foo"
    price := 1