Kbase P137168: 4GL/ABL: How to get the values of a calculated field from a regular multiple select browse?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  12/11/2008 |
|
Status: Unverified
GOAL:
4GL/ABL: How to get the values of a calculated field from a regular multiple select browse?
GOAL:
How to get the calculated values in a cell of a regular multiple select browse?
FACT(s) (Environment):
All Supported Operating Systems
Progress 9.x
OpenEdge 10.x
FIX:
The following code demonstrates one way of getting the values of a calculated field from a regular multiple select browse. The code is partially based on the code in the Progress Knowledge Center Solution number P17641. This version uses a TEMP-TABLE to store the values of the calculated field and deselects the selected rows when the processing of the calculated fields of the current set of selected rows is done.
DEFINE VARIABLE cCalculatedField AS CHARACTER LABEL "State":U NO-UNDO.
DEFINE VARIABLE hCalculatedColumn AS HANDLE NO-UNDO.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE hWindow AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE cSelectedRowsList AS CHARACTER NO-UNDO.
DEFINE VARIABLE rCurrentRowid AS ROWID NO-UNDO.
FUNCTION getCalculatedColumnHandle RETURNS HANDLE() FORWARD.
DEFINE BUTTON btnCalcFldVal LABEL "Calculated Field Value" SIZE 40 BY 1.14.
DEFINE QUERY BROWSE-1 FOR Customer SCROLLING.
DEFINE BROWSE BROWSE-1
QUERY BROWSE-1 NO-LOCK
DISPLAY
Customer.Name FORMAT "x(30)":U
Customer.Contact FORMAT "x(30)":U
Customer.Phone FORMAT "x(20)":U
Customer.City FORMAT "x(25)":U
CAPS(customer.state) @ cCalculatedField WIDTH 49.6
WITH MULTIPLE NO-ROW-MARKERS SEPARATORS SIZE 133 BY 5.48 EXPANDABLE.
DEFINE FRAME DEFAULT-FRAME
BROWSE-1 AT ROW 1.71 COL 3
btnCalcFldVal AT ROW 7.67 COL 43
WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY SIDE-LABELS NO-UNDERLINE THREE-D AT COL 1 ROW 1 SIZE 136.6 BY 8.05.
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
CREATE WINDOW hWindow
ASSIGN
HIDDEN = YES
TITLE = "Calculated Field Window"
HEIGHT = 8
WIDTH = 136.4
MAX-HEIGHT = 16
MAX-WIDTH = 156.8
VIRTUAL-HEIGHT = 16
VIRTUAL-WIDTH = 156.8
RESIZE = yes
SCROLL-BARS = no
STATUS-AREA = no
BGCOLOR = ?
FGCOLOR = ?
KEEP-FRAME-Z-ORDER = yes
THREE-D = yes
MESSAGE-AREA = no
SENSITIVE = yes.
ELSE
ASSIGN
hWindow = CURRENT-WINDOW.
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(hWindow) THEN
hWindow:HIDDEN = NO.
ON END-ERROR OF hWindow OR ENDKEY OF hWindow ANYWHERE DO:
IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
END.
ON WINDOW-CLOSE OF hWindow DO:
APPLY "CLOSE":U TO THIS-PROCEDURE.
RETURN NO-APPLY.
END.
ON CHOOSE OF btnCalcFldVal IN FRAME DEFAULT-FRAME DO:
/* Construct a list of the rowids of all the selected rows */
ASSIGN
cSelectedRowsList = "".
DO iCounter = 1 TO BROWSE-1:NUM-SELECTED-ROWS:
&.nbsp; BROWSE BROWSE-1:FETCH-SELECTED-ROW(iCounter).
cSelectedRowsList = cSelectedRowsList + "," + STRING(ROWID(Customer)).
END.
ASSIGN
cSelectedRowsList = LEFT-TRIM(cSelectedRowsList, ",").
/* Message the calcualted field of each selected row */
DO iCounter = 1 TO NUM-ENTRIES(cSelectedRowsList):
rCurrentRowid = TO-ROWID(ENTRY (iCounter,cSelectedRowsList,",")).
REPOSITION BROWSE-1 TO ROWID rCurrentRowid.
BROWSE BROWSE-1:SELECT-FOCUSED-ROW() NO-ERROR.
MESSAGE NAME hCalculatedColumn:SCREEN-VALUE
VIEW-AS ALERT-BOX INFO BUTTONS OK.
END.
END.
/* *************************** Main Block *************************** */
ASSIGN CURRENT-WINDOW = hWindow
THIS-PROCEDURE:CURRENT-WINDOW = hWindow.
ON CLOSE OF THIS-PROCEDURE
RUN disable_UI.
PAUSE 0 BEFORE-HIDE.
MAIN-BLOCK:
DO ON ERROR UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK
ON END-KEY UNDO MAIN-BLOCK, LEAVE MAIN-BLOCK:
RUN enable_UI.
ASSIGN
hCalculatedColumn = getCalculatedColumnHandle().
IF NOT THIS-PROCEDURE:PERSISTENT THEN WAIT-FOR CLOSE OF THIS-PROCEDURE.
END.
/* *************************** End of Main Block ******************** */
FUNCTION getCalculatedColumnHandle RETURNS HANDLE():
DEFINE VARIABLE hColumn AS HANDLE NO-UNDO.
ASSIGN
hColumn = BROWSE BROWSE-1:FIRST-COLUMN.
DO WHILE VALID-HANDLE(hColumn):
IF hColumn:NAME = "cCalculatedField":U THEN LEAVE.
hColumn = hColumn:NEXT-COLUMN.
END.
RETURN hColumn.
END FUNCTION.
PROCEDURE disable_UI :
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(hWindow)
THEN DELETE WIDGET hWindow.
IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.
PROCEDURE enable_UI :
ENABLE BROWSE-1 btnCalcFldVal
WITH FRAME DEFAULT-FRAME IN WINDOW hWindow.
OPEN QUERY BROWSE-1 FOR EACH Customer NO-LOCK INDEXED-REPOSITION.
VIEW hWindow.
END PROCEDURE..