The development tools supplied by the BaanERP Tools package enable developers to program additional functionality for existing BaanERP applications or to build entirely new applications. The features provided by the development tools include:
- The BaanERP 3GL programming language.
- 4GL language features that enable you to add to or modify the default behaviour of sessions, reports, and the Data Access Layer.
- Baan SQL, which enables you to retrieve database data.
- Support for Dynamic Link Libraries (DLLs).
3GL scripts are program scripts that are either linked to sessions without forms or not linked to sessions at all. They do not have any relationship with the 4GL Engine (previously known as the Standard Program). When creating such scripts, you must specify the entire program flow, including the main function. You cannot use 4GL event sections or functions.
In BaanERP applications, the 4GL engine provides much of the default functionality for a session. You can add to or modify the default functionality of a session by creating a 4GL script that is linked to the session. 4GL scripts are event-oriented. They consist of one or more event sections in which you program actions to be performed at particular states of execution of the 4GL engine. In previous versions of the software, changes or additions to the default functionality of a session were programmed in a single script that was associated with the session. In BaanERP, user interface actions and database actions have been separated. The _Data Access Layer_ (DAL) now handles database interaction. Programmers create a user interface (UI) script to change the default behavior of a session. They create a DAL script to program all the logical integrity rules for a particular table. The statements programmed in event sections can be a combination of 3GL/4GL functions and 3GL language statements.
Report scripts are 4GL scripts that are linked to a report in order to add to or modify its output. In a report script, you can program actions that you want to be performed at particular stages of the report execution.
You can use Baan SQL (Structured Query Language) in 4GL scripts to retrieve data from database tables. There are two ways to use Baan SQL in a 4GL program. You can embed it in the language (embedded SQL), or you can use BaanERP 4GL functions (dynamic SQL).
The bshell (the BaanERP application server) provides a multitasking execution environment for BaanERP applications. Each bshell can execute and schedule multiple parallel processes.
3GL programming language features
There are five types of variables: long, double, string, table, and domain variables.
- variables can contain any whole number from -2147483648 to 2147483647. For numbers beyond this range, use double variables instead. Physically, four bytes are reserved for each long variable.
- variables are used for any number containing a decimal point, with a maximum of 15 significant digits (8 bytes).
- variables are used for symbolic names, descriptions, and short text. The maximum length of a string is 1024 characters. A string variable can be declared as a multibyte string, in order to handle multibyte or bidirectional characters. In a single-byte string, each byte contains a single character. But in a multibyte string, characters can occupy from one to four bytes.
- declarations are used for accessing database tables in a program. The table must be defined in the data dictionary.
- variables assume the characteristics of a database domain defined in the data dictionary. A domain may be based on any of the following data types: long, byte, integer, date, enumerate, set, float, double, string, text. Each domain defined in the data dictionary can be used in a declaration of your program.
Baan 3GL comprises the usual imperative programming statements:
- Variable assignment
- IF ...THEN ...ELSE ...ENDIF ON CASE statement
- WHILE-, REPEAT- and FOR- Loops with BREAK and CONTINUE options
- Procedure calls (procedures are called 'functions')
In addition to the standard loop constructs there is an embedded SQL loop statement consisting of a SQL query expression (by means of the standard SELECT ...FROM...WHERE ... statement) followed by SELECTDO ...SELECTEMPTY ...ENDSELECT. The statements in the SELECTDO block are executed iteratively for each row of the query result set, whereas the statements in the SELECTEMPTY block are executed only if the result set is empty.
FUNCTION LONG compnr_check( LONG new_compnr )
SELECT pctst999.* FROM pctst999
WHERE pctst999.compnr = :new_compnr
ORDER BY pctst999.compnr
compnr = pctst999.compnr
4GL programming language features
When you create a session, the session generator generates a standard source. This standard source provides default session functionality. If the required functionality of the session is not fully implemented by the standard source, you can program the additional functionality in a 4GL program script.
In Baan IV, changes or additions to the default functionality for a session were programmed in a single script that was associated with the session. Both user interface actions and database actions were programmed in this script. In BaanERP, user interface actions and database actions have been separated. The Data Access Layer (DAL) now handles database interaction. Programmers create a user interface (UI) script to change the default behavior of a session. They create a DAL script to program all the logical integrity rules for a particular table.
4GL script types
There are four types of 4GL program scripts:
- Type 1 single-occurrence (details) session, operating on a main table.
- Type 2 multi-occurrence (overview) session with group fields, and operating on a main table.
- Type 3 multi-occurrence (overview) session, without group fields, operating on a main table.
- Type 4 print/processing sessions, without main table.
4GL scripts are event oriented. They consist of one or more event sections in which you program actions to be performed at particular states of execution of the standard program - for example, when a session is started, before a form is activated, before input to a field, after input to a field, and so on. It is not necessary to program all sections, only those for which the standard program does not provide the required functionality. The statements programmed in a section can be a combination of 3GL/4GL functions and 3GL statements.
SELECT pctst001.* FROM pctst001
WHERE pctst001.item = :pctst099.item
AS SET WITH 1 ROWS
pctst001.dsca = "*****"
if ..... then
attr.input = false
SELECT pctst001.* FROM pctst001
WHERE pctst001.item = :pctst099.item
AS SET WITH 1 ROWS
pctst001.dsca = "*****"
attr.oformat$ = "%D002,2"
BaanERP reports are used to output data from the database to a variety of devices (for example, printers, displays, and files). The contents and layouts of reports are defined in the data dictionary. In addition, you can link a report script to a report. In a report script, you can program actions that you want to be performed at particular stages of the report execution. For example, you can create a script to perform calculations on the report data or to read records from related tables that are not automatically available to the report. You program report scripts in the same way as you program 4GL program scripts, except that report scripts use different event sections and some special functions.
A report script consists of one or more event sections in which you program actions to be performed at particular states of execution of the report to which the report script is linked. The statements programmed in a report script section consist of a combination of 3GL language statements and report script functions. Report scripts support the following event sections: program sections, report sections, and text field sections.
Data Access Layer (DAL) Functions
In BAAN applications, the standard program provides much of the default functionality for a session. In previous versions of the software, changes or additions to the default functionality for a session were programmed in a single script that was associated with the session. Both user interface actions and database actions were programmed in this script. In BaanERP, user interface actions and database actions have been separated. The Data Access Layer (DAL) now handles database interaction. Programmers create a user interface (UI) script to change the default behavior of a session. They create a DAL script to program all the logical integrity rules for a particular table. So the DAL ensures the logical integrity of the database. As in previous versions of the software, the database server ensures the referential integrity of the database.
The DAL script for a particular table has the same name as that table. It is implemented as a DLL that can be accessed by user interface scripts (via the standard program), by other DALs, and by external programs (via the Common Data Access Server (CDAS). The following diagram illustrates the overall relationship of these components.
Database integrity checks
The following are examples of some logical integrity rules that could be programmed in a DAL script:
- When customers have reached their credit limit, they cannot order further items.
- If the invoice for an order has been printed, the order cannot be changed.
- If the current PVRC of a user is not equal to the PVRC of the program script, the script cannot be compiled.
Programming database integrity checks in a separate DAL script has two main advantages:
- Code reuse: The integrity rules do not have to be replicated in each session that uses a particular table.
- External access: External applications can access the database via the CDAS and the DAL.
For an overview of the interaction between the user interface, the standard program, and the DAL, see DAL, UI, and standard program interaction.
In addition to performing data integrity checks, the DAL provides business methods for handling non-interactive database modifications such as printing sales orders or posting all orders to history. A business method is a function that performs a task that involves manipulating and/or checking one or more tables in the database. The function is programmed in a DAL script and can be called directly from a UI script. It must be programmed in the DAL script of the most relevant table.
Users can activate a business method with a single command. There is then no further user interaction. The UI script calls the relevant function in the DAL script. The function performs all operations to complete the required task. The user must wait until the business method finishes before continuing with other tasks. However, if a progress window is provided, the user can cancel the business method by clicking on the Cancel button. The UI script starts a business method by calling the dal.start.business.method() function.
Interaction between UI, DAL, and standard program
A DAL script contains all the logic integrity rules for a particular object set. These rules are referred to as hooks and they can be programmed for every possible manipulation of an object in the object set. For each session with a main table, the standard program ensures that the integrity rules for the table are checked each time an update, delete, insert, or read operation is performed on an object of the table. If there is no DAL script for the particular object set being accessed, no logic integrity checks are performed (unless they are programmed in the UI script itself).
A DAL script can contain hooks that prevent access to the database and hooks that prevent data being passed back to the user interface. The former are executed before the database action. The latter are performed after the database action.
If a user changes the address of a customer on a form, the standard program changes the address for that customer in the database via the DAL. If you want certain restrictions to apply to the update action, you can program a property hook in the DAL of the sessions main table to impose these restrictions.
UI function calls
The UI script can use either the database write functions or the DAL Data Access Methods (DAM) to manipulate the database. The database write functions are direct database calls. They do not use the DAL. In this case, any logic integrity checks required must be programmed in the UI script itself. This means that they cannot be reused by other sessions. In preference, use the DAL Data Access Methods. These access the database via the DAL, so all necessary checks are automatically performed.
When the DAL is used to manipulate the database, the main steps involved are as follows:
- The user issues a command through the user interface to access a record in the database.
- The standard program loads the appropriate DAL and calls the hooks in the DAL to check the integrity rules for the object.
- If the particular database action is permitted, the standard program issues the appropriate database call.
- After the database has been updated, the DAL can perform further checks to determine whether or not data is passed back to the user interface.
- The standard program passes data back to the user interface (provided that the integrity rules permit this).
A hook is a function, with a predefined name, that the DAL programmer programs in a DAL script. The function is used to program logic integrity rules for database access. The DAL script is compiled into a DLL.
When a user issues a command to access the database, the standard program loads the DAL DLL for the object being accessed and calls the hooks to perform the integrity checks. Provided that a DAL script exists for an object set being accessed, the standard program always ensures that the hooks in the DAL are called at the appropriate times. A DAL script can contain two types of hooks: property hooks and object hooks.