Module custquery.4gl (function inpupd_cust)
A new function, inpupd_cust, is added to the
            custquery.4gl module, allowing the user to insert values for a new
        customer row into the form.
Function 
inpupd_cust
(custquery.4gl):01 FUNCTION inpupd_cust(au_flag)  
02   DEFINE au_flag CHAR(1),
03          cont_ok SMALLINT
04
05   LET cont_ok = TRUE 
06
07
08   IF (au_flag = "A") THEN
09     MESSAGE "Add a new customer"
10     INITIALIZE mr_custrec.* TO NULL
12   END IF
13
14   LET INT_FLAG = FALSE
15
16   INPUT BY NAME mr_custrec.*
17         WITHOUT DEFAULTS ATTRIBUTES(UNBUFFERED) 
18
19   ON CHANGE store_num 
20     IF (au_flag = "A") THEN
21       SELECT store_name, 
22              addr,
23              addr2, 
24              city, 
25              state, 
26              zip_code,
27              contact_name, 
28              phone 
29         INTO mr_custrec.*
30         FROM customer 
31         WHERE store_num = mr_custrec.store_num 
32       IF (SQLCA.SQLCODE = 0)THEN
33         ERROR "Store number already exists."
34         LET cont_ok = FALSE
35         CALL display_cust()
36         EXIT INPUT
37       END IF
38     END IF
39
40   AFTER FIELD store_name 
41     IF (mr_custrec.store_name IS NULL) THEN
42       ERROR "You must enter a company name."
43       NEXT FIELD store_name 
44     END IF
45
46   END INPUT
47
48   IF (INT_FLAG) THEN
49     LET INT_FLAG = FALSE
50     LET cont_ok = FALSE
51     MESSAGE "Operation cancelled by user"
52     INITIALIZE mr_custrec.* TO NULL
53   END IF
54  
55   RETURN cont_ok 
56
57 END FUNCTION- Line 
01The function accepts a parameter defined asCHAR(1). In order to use the same function for both the input of a new record and the update of an existing one, theCALLto this function in theMENUstatement in main.4gl will pass a value "A" for add, and "U" for update. - Line 
06The variablecont_okis a flag to indicate whether the update operation should continue; set initially toTRUE. - Lines 
08thru12test the value of the parameterau_flag. If the value ofau_flagis "A" the operation is an Add of a new record, and aMESSAGEis displayed. Since this is an Add, the modular program record values are initialized toNULLprior to calling theINPUTstatement, so the user will have empty form fields in which to enter data. - Line 
14sets theINT_FLAGglobal variable toFALSEprior to theINPUTstatement, so the program can determine if the user cancels the dialog. - Line 
17TheUNBUFFEREDandWITHOUT DEFAULTSclauses of theINPUTstatement are used. TheUNBUFFEREDattribute insures that the program array the screen array of the form are automatically synchronized for input and output. TheWITHOUT DEFAULTSclause is used since this statement will also implement record updates, to prevent the existing values displayed on the form from being erased or replaced with default values. - Lines 
19thru38Each time the value instore_numchanges, thecustomertable is searched to see if thatstore_numalready exists. If so, the values in themr_custrecrecord are displayed in the form, the variablecont_okis set toFALSE, and theINPUTstatement is immediately terminated. - Lines 
40thru44TheAFTER FIELDcontrol block verifies thatstore_namewas not left blank. If so, theNEXT FIELDstatement returns the focus to thestore_namefield so the user may enter a value. - Line 
46END INPUTis required when any of the optional control blocks of theINPUTstatement are used. - Lines 
48thru53TheINT_FLAGis checked to see if the user has canceled the input. If so, the variablecont_okis set toFALSE, and the program recordmr_custrecis set toNULL. TheUNBUFFEREDattribute of theINPUTstatement assures that theNULLvalues in the program record are automatically displayed on the form. - Line 
55returns the value ofcont_ok, indicating whether the input was successful.