/

 

The manual

Self-training

Experimentation

Contact

 

Language

Use states

Use a state to convert

Suppose we have a state whose identifier is 'x / y / z' which contains a column 'name' and a column 'tel' (telephone number).

In the following piece of code, the 'lookup' function will look in the 'x / y / z' state for the row that contains 'Dupont' in the 'name' column and will return the 'tel' column of this same row :

var Str n := "Dupont"
var Str t := lookup "x/y/z" nom tel n

If the report contains several lines whose key (here the 'name' field) corresponds to the value provided, and these lines do not all have the same value in the requested field (here the 'tel' field), then an error is generated.
To avoid this, we can add the following keyword at the end of the 'lookup' instruction:

undefined

If all lines do not have the same value in the requested field, we return the value 'undefined'.
For a character string, 'undefined' is understood as the empty string.

any

If several lines match the key, we return the value corresponding to any of them.

sum

If several lines correspond to the key, then we return the sum of the corresponding values.
This is only applicable for integer or floating point values.
For a character string, we return the concatenation of the values, with a new line between each.

Example:

var Str n := "Dupont"
var Str t := lookup "x/y/z" nom tel n sum

will return all of Dupont's phone numbers, separated by line breaks.

To copy the identifier of a state, switch to edit mode, select the state by clicking in it, then the 'Properties' button in the context menu on the left.
Then, press the Control key, then select the identifier in the sub-title 'Reference to report ...' in the window above.

You can also find the ID of a file:

var Str n := "Dupont"
var Str id := lookup_form_id "x/y/z" nom n

Validation of the entry of a customer code (or any other code field)
     An example of using the 'lookup' instruction

Browse a state

A more general version is the 'report' statement.
It is used to browse all the lines of a report whose specified field contains the specified value.
In the previous scenario, to get all the numbers corresponding to the name 'n', we could write:

var Str n
...
var Str all := ""
report "x/y/z" nom n
  field Str tel
  all += tel+" "

The 'report' function is especially powerful: when a form uses it, the form will be automatically recalculated each time the lines of the report searched change.
It is this specificity that provides Storga with a functional power comparable to that of the relational model.
We can deactivate this automatic recalculation via the 'manual' option:

report "x/y/z" nom n manual
  ...

The version without parameters is equivalent to:

report "x/y/z" nom n auto
  ...

We can also order the browsing of the lines of the report according to the value of one of the fields (in this example, it is the 'tel' field):

report "x/y/z" nom n sort tel
   ...

Finally, if only one parameter is supplied to the 'report' instruction instead of three, all the lines of the report will be scanned:

report "x/y/z"
  ...

Summary sheet
     An example of using the 'report' statement