Database

Queries

The LN development team has the responsibility to keep the data model compatible. Sometimes it is required to change indexes. We recommend that you do not refer to indexes, but to the fields directly. See these code examples:

  • This syntax is incorrect because it refers to an index:
function extern void tdsls401.read()
{
        select tdsls401.*
        from   tdsls401
        where  tdsls401._index1 = {:rep.orno, :rep.pono}
        selectdo
        endselect
}
  • Instead, use this syntax, which refers to the fields directly:
function extern void tdsls401.read()
{
        select tdsls401.*
        from   tdsls401
        where  tdsls401.orno = :rep.orno
        and    tdsls401.pono = :rep.pono
        selectdo
        endselect
}

If Public Interfaces are available to read data from the database, use those instead of querying the database directly. Public Interfaces are not created to read data which can be retrieved by a simple query. If the approach is more complex, Public Interfaces can be present or can be requested. See these code examples:

  • This syntax is incorrect because it queries the database directly and there is a Public Interface available:
function domain tcyesno read.apply.discount.parameter()
{
        domain tcyesno apply.discount         
        select tssoc003.aomt:apply.discount
        from   tssoc003
        where  tssoc003.soff = :rep.soff
        and    tssoc003.site = :rep.site
        selectdo
        selectempty
               apply.discount = empty
        endselect
        return(apply.discount)

}
  • Instead, use this syntax, which uses the Public Interface:
function domain tcyesno read.apply.discount.parameter ()
{
        domain tcyesno apply.discount         
               long    ret 
               long    exceptionid 
              string  exception.message(1000) mb 
       if Service.GetServiceOrderSettings(
                                get.compnr(),
                                rep.soff,
                                rep.site,
                                false,
                                exception.message,
                                exception.id,
                                "aomt",
                                apply.discount) = 0 then
                apply.discount = empty
                Exception.Delete(exception.id)
        endif
        return(apply.discount)
}

Table definitions

If you create own tables in the Extensions (tx) package, use standard domains if you store copies of standard data in your tables. This ensures that your tables also are reconfigured if the standard tables are reconfigured after a domain change. For enumerated domains, new values can be added. Prepare your extension for possible new values.

Standard table updates

If you update standard tables, use the DAL. Always check the return values of the functions such as dal.save.object() and react accordingly.