Download Informix 4GL By Example, Version 4.1

Transcript
The update_cust2() Function
31 ➤ These WHENEVER statements use the ANY clause keyword to ensure that the
status variable is set (and execution does not stop) after each 4GL statement.
Without this keyword, status is only set after SQL and screen statements (in
i4gl) or after most statements (in r4gl).
32 ➤ The LET statement attempts to assign the input received from the PROMPT to
an integer variable. This assignment should execute without error because
4GL can convert the character representation of a number to an integer value
and the user should have entered an integer value. However, if the user
entered letters or symbols, this conversion fails because 4GL cannot convert
these characters to an integer. The WHENEVER ANY ERROR statement prevents the program from encountering a runtime error if such a conversion is
attempted.
33 ➤ If the data conversion in the LET statement fails, 4GL sets the status variable
to a negative value. The program tells the user the desired type of data and
reprompts for input.
34 ➤ If the user pressed Cancel at the prompt, the program interprets the key as
a signal to exit the “Try Update” menu option. It resets the int_flag, sets the
number of retries to zero (0) to indicate that the user does not want to
continue and exits the WHILE loop.
35 ➤ Since a negative value or zero is not valid, the program tells the user the
desired type of data and reprompts for input.
36 ➤ If execution reaches this point, the data entered is valid. The program sets the
invalid_resp flag to FALSE to exit the WHILE loop.
37 ➤ This function returns the specified number of lock retries. If the user has
cancelled the PROMPT, the function returns zero (See Note 34).
The update_cust2() Function
38 ➤ This function declares an update cursor to select the specified customer
row. This update cursor locks the selected row as it is fetched. If the fetch
is successful, the UPDATE (see Note 43) should succeed (a locking error
was not encountered).
534
Handling Locked Rows
November 11, 1997 10:55 am