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 FUNCTIONNote:
- Lines
04thru14contain an embedded SQL statement to insert the values in the program recordmr_custrecinto thecustomertable. 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 theSELECTstatement. Otherwise, the individual members of the program record must be listed separately. Since there is noBEGIN WORK/COMMIT WORKsyntax used here, this statement will be treated as a singleton transaction and the database driver will automatically send the appropriateCOMMITstatement. TheINSERTstatement is surrounded byWHENEVER ERRORstatements. - Lines
17thru21test theSQLCA.SQLCODEthat was returned from theINSERTstatement. If theINSERTwas not successful, the corresponding error message is displayed to the user.