UPDATE statement
Displays fields or variables, requests input, and then puts the input data in both the screen buffer and in the specified fields or variables.
The UPDATE statement is a combination of the following statements:
- DISPLAY — Moves the values of fields or variables into the screen buffer and displays them (#1 in the figure)
- PROMPT-FOR — Prompts the user for data and puts that data into the screen buffer (#2 in the figure)
- ASSIGN — Moves data from the screen buffer to the record buffer (#3 in the figure)
Note: Does not apply to SpeedScript programming.Data movement
Syntax
UNLESS-HIDDENfield
Represents the name of the field or variable whose value you want to display, change, and store in the screen and record buffers.In array fields, array elements with constant subscripts are handled as any other field. Array fields with no subscripts are expanded as though you entered the implicit elements. See the DISPLAY statement reference entry for information on how array fields with expressions as subscripts are handled.You can supply values for array elements in the UPDATE statement as follows:
This statement assigns the letter x to the first element of array x. If you do not include an array subscript, the AVM assigns the value to all elements of the array.
This statement assigns the letter x to all elements of the array x.format-phrase
Specifies one or more frame attributes for a field, variable, or expression. For more information onformat-phrase
, see the Format phrase reference entry.WHENexpression
TEXT
Defines a group of character fields or variables (including array elements) to use automatic word wrap. The TEXT option works only with character fields that are ABL default FILL-IN widgets (not specified with the FILL-IN NATIVE option). When you insert data in the middle of a TEXT field, the AVM wraps data that follows into the next TEXT field, if necessary. If you delete data from the middle of a TEXT field, the AVM wraps data that follows to the empty area. If you enter more characters than the format for the field allows, the AVM discards the extra characters. The character fields formats must be in the x(n) format. A blank in the first column of a line marks the beginning of a paragraph. Lines within a paragraph are treated as a group and will not wrap into other paragraphs.Table 64 lists the keys you can use within a TEXT field and their actions.
In this procedure, the s-com field is a TEXT field. Run the procedure and enter text in the field to see how the TEXT option works:
field
=expression
constant
ATn
constant
TOn
^SPACE [ (n
) ]
Identifies the number (n
) of blank spaces to insert after the expression displays. Then
can be 0. If the number of spaces you specify is more than the spaces left on the current line of the frame, the AVM starts a new line and discards any extra spaces. If you do not use this option or do not usen
, the AVM inserts one space between items in the frame.SKIP [ (n
) ]
Identifies the number (n
) of blank lines to insert after the expression is displayed. Then
can be 0. If you do not use this option, the AVM does not skip a line between expressions unless they do not fit on one line. If you use the SKIP option, but do not specifyn
or ifn
is 0, the AVM starts a new line unless it is already at the beginning of a new line.GO-ON (keylabel
. . . )
Tells the AVM to take the GO action when the user presses any of the keys listed. You list keys in addition to keys that perform the GO action by default or because of ON statements. For example, if you want the AVM to execute the GO action when the user presses F1, use the statement GO-ON(F1). If you list more than one key, separate them with spaces, not commas.Note that the GO-ON option is valid if you specify a list of fields in the UPDATE statement, but is invalid if you specify a record.frame-phrase
Specifies the layout and processing properties of a frame. For more information onframe-phrase,
see the Frame phrase reference entry.editing-phrase
Supported only for backward compatibility.Identifies processing to take place as each keystroke is entered. This is the syntax forediting-phrase
:
For more information onediting-phrase
, see the EDITING phrase reference entry.NO-ERROR
Suppresses ABL errors or error messages that would otherwise occur and diverts them to the ERROR-STATUS system handle. If an error occurs, the action of the statement is not done and execution continues with the next statement. If the statement fails, any persistent side-effects of the statement are backed out. If the statement includes an expression that contains other executable elements, like methods, the work performed by these elements may or may not be done, depending on the order the AVM resolves the expression elements and the occurrence of the error.To check for errors after a statement that uses the NO-ERROR option:
- Check the ERROR-STATUS:ERROR attribute to see if the AVM raised the ERROR condition.
- Check if the ERROR-STATUS:NUM-MESSAGES attribute is greater than zero to see if the AVM generated error messages. ABL handle methods used in a block without a CATCH end block treat errors as warnings and do not raise ERROR, do not set the ERROR-STATUS:ERROR attribute, but do add messages to the ERROR-STATUS system handle. Therefore, this test is the better test for code using handle methods without CATCH end blocks. ABL handle methods used in a block with a CATCH end block raise ERROR and add messages to the error object generated by the AVM. In this case, the AVM does not update the ERROR-STATUS system handle.
- Use ERROR-STATUS:GET-MESSAGE(
message-num
) to retrieve a particular message, wheremessage-num
is 1 for the first message.If the statement does not include the NO-ERROR option, you can use a CATCH end block to handle errors raised by the statement.Some other important usage notes on the NO-ERROR option:
- NO-ERROR does not suppress errors that raise the STOP or QUIT condition.
- A CATCH statement, which introduces a CATCH end block, is analogous to a NO-ERROR option in that it also suppresses errors, but it does so for an entire block of code. It is different in that the error messages are contained in a class-based error object (generated by the AVM or explicitly thrown), as opposed to the ERROR-STATUS system handle. Also, if errors raised in the block are not handled by a compatible CATCH block, ON ERROR phrase, or UNDO statement, then the error is not suppressed, but handled with the default error processing for that block type.
- When a statement contains the NO-ERROR option and resides in a block with a CATCH end block, the NO-ERROR option takes precedence over the CATCH block. That is, an error raised on the statement with the NO-ERROR option will not be handled by a compatible CATCH end block. The error is redirected to the ERROR-STATUS system handle as normal.
- If an error object is thrown to a statement that includes the NO-ERROR option, then the information and messages in the error object will be used to set the ERROR-STATUS system handle. This interoperability feature is important for those integrating code that uses the traditional NO-ERROR technique with the newer, structured error handling that features error objects and CATCH end blocks.
record
Specifies the name of a record buffer. All of the fields in the record are processed as if you updated each of them individually.To update a record in a table defined for multiple databases, you must qualify the record’s table name with the database name. See the Record phrase reference entry for more information.EXCEPTfield
ExamplesThe following procedure lets you update the
Name
,Address
,City
,State
, andCountry
for each Customer record in the database:
The
r-updat2.p
procedure reads each Customer record and lets you update theName
andCreditLimit
fields. The VALIDATE option on the first UPDATE statement ensures that you enter aCreditLimit
value that is less than 500000. The HELP option displays a message to that effect.
The second FOR EACH block reads every Order belonging to the Customer, displays the
OrderNum
field, and lets you update thePromiseDate
andShipDate
fields. The VALIDATE option ensures that you enter a ship date value that is after today’s date.This procedure requests a Customer number and then lets you update information for that Customer record. The frame phrase WITH 1 COLUMN 1 DOWN tells the AVM to display the fields in a single column on the screen (rather than in a row across the screen) and to display only one Customer record on the screen at a time.
Notes
- If any
field
is a field in a database record, the UPDATE statement upgrades the record lock condition to EXCLUSIVE-LOCK before updating the record.- If any
field
is part of a record retrieved with a field list, the UPDATE statement rereads the complete record before updating it. If anyfield
is not part of the field list (or related fields) fetched with the record, or ifrecord
includes such unfetched fields, the AVM raises the ERROR condition before the UPDATE statement accepts input. This is because the UPDATE attempts to display the fields before it rereads the record.- If an error occurs during UPDATE statement input (for example, the user enters a duplicate index value for a unique index), the AVM retries the data entry part of the statement and does not do the error processing associated with the block that contains the statement.
- The UPDATE statement is not equivalent to a combination of the DISPLAY and SET statements.
The previous procedure is approximately equivalent to the following procedure:
If an error occurs during an UPDATE statement, the statement is retried until the error is corrected. If this happens during a SET statement, an entire block is retried.- If you receive input from a device other than the terminal, and the number of characters read by the UPDATE statement for a particular field or variable exceeds the display format for that field or variable, the AVM returns an error. However, if you are setting a logical field that has a y/n format and the data file contains a value of YES or NO, the AVM converts that value to “y” or “n”.
- If you use a single qualified identifier with the UPDATE statement, the compiler first interprets the reference as
dbname
.tablename
. If the compiler cannot resolve the reference asdbname.tablename
, it tries to resolve it astablename.fieldname
.- When updating fields, you must use table names that are different from field names to avoid ambiguous references. See the Record phrase reference entry for more information.
- The UPDATE statement causes ASSIGN and WRITE events to occur and all related database ASSIGN and WRITE triggers to execute. The ASSIGN triggers execute before the WRITE triggers and after the field is actually updated. The WRITE triggers only execute if the ASSIGN triggers do not return an error. If an ASSIGN trigger fails, the database update is undone. This means that all database changes are backed out. If the UPDATE statement occurs within a transaction, any changes to variables, worktable fields, and temp-table fields are also undone unless the variable or field is defined with the NO-UNDO option. Likewise, if a WRITE trigger fails, the UPDATE statement is undone.
- In Progress Version 7 and above, when you execute UPDATE with a specific or implied GO-ON(
keylabel
) from a called program, the AVM generates an error message (4123). This is due to an incompatibility in focus. The workaround is to add a VIEW FRAME statement after the call to the subprocedure such that the VIEW FRAME is the first statement executed on return from the called procedure.See alsoASSIGN statement, DISPLAY statement, EDITING phrase, Format phrase, Frame phrase, PROMPT-FOR statement
OpenEdge Release 10.2B
|