Example: connectdb.4gl

This program connects to the custdemo database, selects the store name from the customer table and displays it to the user.

Note: The line numbers shown in the examples in this tutorial are not part of the BDL code; they are used here so specific lines can be easily referenced. The BDL keywords are shown in uppercase, as a convention only.
Program connectdb.4gl:
01 -- connectdb.4gl 
02 SCHEMA custdemo 
03
04 MAIN
05   DEFINE 
06    m_store_name LIKE customer.store_name 
07
08   CONNECT TO "custdemo"
09
10   CALL select_name(101) 
11       RETURNING m_store_name
12   DISPLAY m_store_name 
13  
14   DISCONNECT CURRENT
15
16 END MAIN
17
18 FUNCTION select_name(f_store_num)
19   DEFINE 
20    f_store_num  LIKE customer.store_num,
21    f_store_name LIKE customer.store_name 
22
23   SELECT store_name INTO f_store_name 
24      FROM customer 
25      WHERE store_num = f_store_num 
26
27   RETURN f_store_name 
28
29 END FUNCTION  -- select_name
Note:

The database schema file

This program requires a database schema file because of the use of the LIKE keyword when defining the variable m_store_name. The database schema contains the definition of the database tables and columns and is used to centralize column data types to define program variables. The schema file for the BDLTutorial has already been extracted from the custdemo database and is used at compile time.

To learn more about database schema files see Database schema in the Genero Business Development Language User Guide.

Compiling and executing the program

You can compile and execute the connectdb application using the Execute option in the Project view of Genero Studio or use the command line options.

  1. Compile the single module program:
    fglcomp connectdb.4gl
  2. Execute the program:
    fglrun connectdb.42m