A new function, insert_cust, in the
custquery.4gl module, contains the logic to
add the new row to the customer table.
Function
insert_cust:
01 FUNCTION insert_cust()
02
03 WHENEVER ERROR CONTINUE
04 INSERT INTO customer (
05 store_num,
06 store_name,
07 addr,
08 addr2,
09 city,
10 state,
11 zip_code,
12 contact_name,
13 phone
14 )VALUES (mr_custrec.*)
15 WHENEVER ERROR STOP
16
17 IF (SQLCA.SQLCODE = 0) THEN
18 MESSAGE "Row added"
19 ELSE
20 ERROR SQLERRMESSAGE
21 END IF
22
23 END FUNCTION
Note:
- Lines 04 thru 14 contain an embedded SQL statement to
insert the values in the program record
mr_custrec into the
customer table. This syntax can
be used when the order in which the members of the
program record were defined matches the order of
the columns listed in the SELECT
statement. Otherwise, the individual members of
the program record must be listed separately.
Since there is no BEGIN WORK /
COMMIT WORK syntax used here,
this statement will be treated as a singleton
transaction and the database driver will
automatically send the appropriate
COMMIT statement. The
INSERT statement is surrounded by
WHENEVER ERROR statements.
- Lines 17 thru 21 test the
SQLCA.SQLCODE that was returned
from the INSERT statement. If the
INSERT was not successful, the
corresponding error message is displayed to the
user.