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
01
The 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, theCALL
to this function in theMENU
statement in main.4gl will pass a value "A" for add, and "U" for update. - Line
06
The variablecont_ok
is a flag to indicate whether the update operation should continue; set initially toTRUE
. - Lines
08
thru12
test the value of the parameterau_flag
. If the value ofau_flag
is "A" the operation is an Add of a new record, and aMESSAGE
is displayed. Since this is an Add, the modular program record values are initialized toNULL
prior to calling theINPUT
statement, so the user will have empty form fields in which to enter data. - Line
14
sets theINT_FLAG
global variable toFALSE
prior to theINPUT
statement, so the program can determine if the user cancels the dialog. - Line
17
TheUNBUFFERED
andWITHOUT DEFAULTS
clauses of theINPUT
statement are used. TheUNBUFFERED
attribute insures that the program array the screen array of the form are automatically synchronized for input and output. TheWITHOUT DEFAULTS
clause 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
19
thru38
Each time the value instore_num
changes, thecustomer
table is searched to see if thatstore_num
already exists. If so, the values in themr_custrec
record are displayed in the form, the variablecont_ok
is set toFALSE
, and theINPUT
statement is immediately terminated. - Lines
40
thru44
TheAFTER FIELD
control block verifies thatstore_name
was not left blank. If so, theNEXT FIELD
statement returns the focus to thestore_name
field so the user may enter a value. - Line
46
END INPUT
is required when any of the optional control blocks of theINPUT
statement are used. - Lines
48
thru53
TheINT_FLAG
is checked to see if the user has canceled the input. If so, the variablecont_ok
is set toFALSE
, and the program recordmr_custrec
is set toNULL
. TheUNBUFFERED
attribute of theINPUT
statement assures that theNULL
values in the program record are automatically displayed on the form. - Line
55
returns the value ofcont_ok
, indicating whether the input was successful.