A simple BDL program

This simple example displays a text message to the screen, illustrating the structure of a BDL program.

Genero BDL source code is written as text in a source module (a file with an extension of .4gl). Because Genero BDL is a structured programming language as well as a 4th generation language, executable statements can appear only within logical sections of the source code called program blocks. This can be the MAIN statement, a FUNCTION statement, or a REPORT statement. (Reports are discussed in Chapter 9.)

Execution of any program begins with the special, required program block MAIN, delimited by the keywords MAIN and END MAIN. The source module that contains MAIN is called the main module.

The FUNCTION statement is a unit of executable code, delimited by FUNCTION and END FUNCTION, that can be called by name. In a small program, you can write all the functions used in the program in a single file. As programs grow larger, you will usually want to group related functions into separate files, or source modules. Functions are available on a global basis. In other words, you can reference any function in any source module of your program.

Although the language keywords in this example and throughout the tutorial are in all-capitals, this is just a convention used in these documents. You may write keywords in any combination of capitals and lowercase you prefer.

You can begin a comment that terminates at the end of the current line with a pair of minus signs (--) or #. Curly braces {} can be used to delimit comments that occupy multiple lines.

The following example is a small but complete Genero BDL program named simple.4gl.

01 -- simple.4gl
04     CALL sayIt()
07 FUNCTION sayIt()
08    DISPLAY "Hello, world!"
  • Line 01 simply lists the filename as a comment , which will be ignored by BDL.
  • Line 03 indicates the start of the MAIN program block.
  • Line 04 Within the MAIN program block, the CALL statement is used to invoke the function named sayIt. Although no arguments are passed to the function sayIt, the empty parentheses are required. Nothing is returned by the function.
  • Line 05 defines the end of the MAIN program block. When all the statements within the program block have been executed the program will terminate automatically.
  • Line 07 indicates the start of the function sayIt .
  • Line 08 uses the DISPLAY statement to display a text message, enclosed within double quotes, to the user. Because the program has not opened a window or form, the message is displayed on the command line.
  • Line 09 indicates the end of the function. After the message is displayed, control in the program is returned to the MAIN function, to line 05, the line immediately following the statement invoking the function. As there are no additional statements to be executed (END MAIN has been reached), the program terminates.