Module custquery.4gl (function insert_cust)
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
thru14
contain an embedded SQL statement to insert the values in the program recordmr_custrec
into thecustomer
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 theSELECT
statement. Otherwise, the individual members of the program record must be listed separately. Since there is noBEGIN WORK
/COMMIT WORK
syntax used here, this statement will be treated as a singleton transaction and the database driver will automatically send the appropriateCOMMIT
statement. TheINSERT
statement is surrounded byWHENEVER ERROR
statements. - Lines
17
thru21
test theSQLCA.SQLCODE
that was returned from theINSERT
statement. If theINSERT
was not successful, the corresponding error message is displayed to the user.