Introduction to DataBasic

DataBasic is a significantly extended version of the original Dartmouth BASIC programming language and is the standard programming feature provided by Reality. It is an interactive, on-line, web-enabled, terminal-based language that includes all the main features of BASIC plus a range of additional features for the Reality environment. Web features include the RealWeb API, that generates web pages from data held in a Reality database; Remote Basic, that allows DataBasic routines to be called from Visual Basic and java, and as web services; and XML support, that allows DataBasic programmers to extract data from and export data to XML documents.

Compilation

DataBasic programs are held as items in Reality files and are created by typing the program text (source code) into the item using any of the editors supplied with Reality (line Editor, Screen Editor or RealEdit). The source code is then compiled using the BASIC command, which creates either a deliverable or an executable item (or both) depending on the options selected. The deliverable item contains platform-independent code that can be copied to Reality databases on other types of host system without recompilation, while the executable item is platform-specific and can only be run on Reality databases on the same type of host system.

To execute the compiled program use the RUN command, specifying the name of the file containing the code and the name of the program; for example:

RUN PROGRAMS PROG

executes the program PROG that is in the file PROGRAMS.

Conditional Compilation

You can use conditional compilation to select particular sections of code to compile, while excluding other sections. For example, you may want to write PRINT statements to help with debugging, or to customise an application for a particular customer. Conditional compilation statements are designed to be used when a program is compiled, not at run time.

You declare a conditional compiler constant in code with the $DEFINE or EQUATE statement, and you mark blocks of code to be conditionally compiled with the $IFDEF...$ELSE...$ENDIF or $IFNDEF...$ELSE...$ENDIF construct. For example, if you need to create French- and German-language versions of the same application from the same source code, you can embed platform-specific code segments in $IFDEF statements using predefined constants FRENCH_VERSION and GERMAN_VERSION. For example:

$IFDEF FRENCH_VERSION THEN
* <code specific to the French language version>.
$ELSE
$IFDEF GERMAN_VERSION THEN
* <code specific to the German language version>.
$ELSE
* <code specific to other versions>.
$ENDIF
$ENDIF

If you define the FRENCH_VERSION constant at compile time, the conditional code for the French version is compiled, while defining GERMAN_VERSION instead will include the German version of the code. If neither is defined, the code in the last $ELSE block is included.

Note

When you select a MultiValue compatibility mode with the $OPTIONS statement, an appropriate conditional compilation symbol is defined. For details, refer to $OPTIONS statement (MultiValue compatibility).

Case Sensitivity

Programs with mixed case identifiers (keywords, variables and labels) can be compiled with the COMPILE command. This is functionally identical to the BASIC command, except that the case of identifiers is ignored; for example, the variables FRED, fred and FrEd are treated as a single variable. You should use COMPILE to compile programs imported from MultiValue systems that permit case-insensitive identifiers.

Cataloging

If you prefer, you can use the CATALOG command to create a copy of a program which can be run from any account without using the RUN command. CATALOG creates a command definition item in the MDClosed Master Dictionary - the dictionary file that defines an account. It contains items that point to the code executed by all the TCL commands, to SYSTEM accounts, and to other accounts by means of Q-pointers. The MD also includes all File Definition Items for the account and other items. of the account that points to the executable item - if no executable item exists one is created. The program can then be executed from that account by simply entering the program name at TCL; in the example above, for instance, you would enter just PROG  instead of RUN PROGRAMS PROG. You can copy the command definition item into the MD of any account, making the program available wherever it is needed.

Note

Depending on the options used when you compiled your program, it may be necessary to also create a Q-pointerClosed An Account or File Synonym Definition Item. Q-pointers allow users to address information in accounts other than the one they are currently logged onto or in files for which they otherwise are not allowed access.  to the file containing the executable item.

In addition, cataloging reduces the time needed to execute a program (because if only a deliverable version is available, RUN must first convert it to an executable), saves memory space by reducing the number of copies of the executable code that are required, and simplifies creating synonyms for programs. External subroutines must be cataloged.