Kbase 20045: How to Update records in a dynamic browse
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/15/2008 |
|
Status: Verified
SYMPTOM(s):
Problems updating record in a dynamic browse.
** Unable to update filename> Field. (142)
Unable to set attribute attribute name> in widget <widget name> of type <widget-type>. (3131)
** <filename> record has NO-LOCK status, update to field not allowed. (396)
QUERY GET methods with exclusive lock requires a transaction. (7359)
Update of buffer field object requires a transaction. (7369)
CAUSE:
Updating a record in dynamic browse is different than in a static
browse. In a dynamic browse you need a handle to reference a field.
In a static browse you have the ability to reference a fields SCREEN-VALUE property:
customer.name:SCREEN-VALUE IN BROWSE {&BROWSE-NAME}.
In a dynamic browse the COLUMN-HANDLE handle is necessary
in order to get the SCREEN-VALUE.
FIX:
One way to get the COLUMN-HANDLE from the browse is by using the method GET-BROWSE-COLUMN():
brws-col-hdl = browse-hndl:GET-BROWSE-COLUMN(iFields).
With this function you have the handle of the column in the variable
brws-col-hdl. To get the SCREEN-VALUE of the COLUMN-HANDLE you can simply refer to it's SCREEN-VALUE property:
brws-col-hdl:SCREEN-VALUE.
To assign the SCREEN-VALUE of the COLUMN-HANDLE to a field in the database is necessary first to get the corresponding BUFFER-FIELD handle using the BUFFER-FIELD property:
buff-field-hdl = brws-col-hdl:BUFFER-FIELD.
The property BUFFER-VALUE of the BUFFER-FIELD allows to set or get the value of the field in the database.
buff-field-hdl:BUFFER-VALUE = brws-col-hdl:SCREEN-VALUE.
Another important point for making a dynamic browse updateable is to verify the READ-ONLY property. In a static browse the default value of this property is FALSE, but in a dynamic browse the default is TRUE.
Therefore, when working with a dynamic browse the READ-ONLY property 'MUST' be set to FALSE, otherwise, setting the property READ-ONLY to FALSE for a specific field will be ineffective.
The following example shows how to make a dynamic browse updateable:
CURRENT-WINDOW:HEIGHT-CHARS = 18.
CURRENT-WINDOW:WIDTH-CHARS = 132.
DEFINE BUTTON bQuit LABEL "&Quit" AUTO-ENDKEY.
DEFINE BUTTON bCreate LABEL "&Create Browse".
DEFINE VARIABLE Browse-Hndl AS WIDGET-HANDLE.
DEFINE VARIABLE bufFieldHandle AS WIDGET-HANDLE.
DEFINE VARIABLE qh AS WIDGET-HANDLE.
DEFINE VARIABLE bh AS WIDGET-HANDLE.
/*Names of the fields to be added and enabled*/
DEFINE VARIABLE cFields AS CHARACTER INITIAL "city,state,country,
postalcode" NO-UNDO.
CREATE BUFFER bh FOR TABLE "Customer".
CREATE QUERY qh.
qh:SET-BUFFERS(bh).
DEFINE FRAME F1
skip(13)
bcreate
bQuit
WITH SIZE 132 BY 18 THREE-D NO-LABELS.
ON CHOOSE OF bCreate
DO:
DEFINE VARIABLE iFields AS INTEGER NO-UNDO.
DEFINE VARIABLE Field-hdl AS WIDGET-HANDLE NO-UNDO.
CREATE BROWSE Browse-Hndl
ASSIGN
FRAME = FRAME F1:HANDLE
QUERY = qh
TITLE = " "
X = 2
Y = 2
WIDTH = 130
DOWN = 12
VISIBLE = TRUE
SENSITIVE = TRUE
READ-ONLY = NO /*the property READ ONLY 'MUST' be set to false in an updateable dynamic browse*/
COLUMN-SCROLLING = TRUE
SEPARATORS = YES
TRIGGERS:
ON 'ROW-LEAVE':U PERSISTENT RUN brRowLeave.
END TRIGGERS.
qh:QUERY-PREPARE("for each customer NO-LOCK":U).
qh:QUERY-OPEN.
/*Adding the fields custnum and Name, these fields will be not
enabled*/
Browse-Hndl:ADD-LIKE-COLUMN(bh:BUFFER-FIELD(1),1).
Browse-Hndl:ADD-LIKE-COLUMN(bh:BUFFER-FIELD(3),2).
/*Fields that will be enabled*/
DO iFields = 1 TO NUM-ENTRIES(cFields):
Field-hdl = Browse-Hndl:ADD-LIKE-COLUMN(bh:BUFFER-FIELD(ENTRY(iFields, cFields))).
field-hdl:READ-ONLY = FALSE. /*Field updateable */
END.
END.
/*Trigger ROW-LEAVE of dynamic browse*/
PROCEDURE brRowLeave.
DEFINE VARIABLE iNumColumns AS INTEGER NO-UNDO.
DEFINE VARIABLE brws-col-hdl AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE buff-field-hdl AS WIDGET-HANDLE NO-UNDO.
IF browse-hndl:CURRENT-ROW-MODIFIED
THEN DO:
REPEAT iNumColumns = 3 TO browse-hndl:NUM-COLUMNS:
brws-col-hdl = browse-hndl:GET-BROWSE-COLUMN(iNumColumns).
/*Get column handle according to column number*/
IF brws-col-hdl:MODIFIED
THEN DO:
buff-field-hdl = brws-col-hdl:BUFFER-FIEL.D.
DO TRANSACTION:
qh:GET-CURRENT(EXCLUSIVE-LOCK).
IF buff-field-hdl NE ? THEN
buff-field-hdl:BUFFER-VALUE =
brws-col-hdl:SCREEN-VALUE.
bh:BUFFER-RELEASE().
END.
END.
END.
END.
END PROCEDURE.
ON CHOOSE OF bQuit
DO:
APPLY "window-close" TO CURRENT-WINDOW.
END.
ENABLE ALL WITH FRAME F1.
WAIT-FOR CLOSE OF CURRENT-WINDOW..