Help Needed to Export the browser data to Excel

Posted by philippoommen on 20-May-2010 04:42

Hi,

Problem is ONLY with Calculated fields Data in a Multi Select Browser .

We are using a seprate procedure to handle the multiselct browser export because if the user selects any rows , only that rows should export. Following is the code

Below high lighted two lines of code giving me problem, in case of a calaculated field

hField = hBuffer:BUFFER-FIELD(vhBrowseCurCol:NAME) NO-ERROR.
vWorkSheet:Cells(i ,j):VALUE = (IF VALID-HANDLE(hField) THEN hField:BUFFER-VALUE ELSE hField:SCREEN-VALUE).

What is happening is , if it is a calculated field hField is not a valid-handle. So screen-value gets assigned, but  screen-value is holding the last selected row's field value and that get gets repeated to all Excel rows.

Any ways to solve this issue please help me.

DEF VAR hBuffer AS HANDLE NO-UNDO.
DEF VAR hQuery AS HANDLE NO-UNDO.

DEF VAR hField AS HANDLE NO-UNDO.
hQuery = vBrwHandle:QUERY.
hBuffer = hQuery:GET-BUFFER-HANDLE(1).
ASSIGN
i = 1
vCellColumn = 1
vhBrowseCurCol = vBrwHandle:FIRST-COLUMN .
DO j = 1 TO vBrwHandle:NUM-COLUMNS:
IF vhBrowseCurCol:VISIBLE = TRUE THEN
ASSIGN
vWorkSheet:Cells(1,vCellColumn):VALUE = vhBrowseCurCol:LABEL
vCellColumn = vCellColumn + 1.
ASSIGN
vhBrowseCurCol = vhBrowseCurCol:NEXT-COLUMN.
.
END.
DO browserNumber = 1 TO vBrwHandle:NUM-SELECTED-ROWS:
IF vBrwHandle:FETCH-SELECTED-ROW(browserNumber) THEN.

i = i + 1.
ASSIGN
j = 1
vhBrowseCurCol = vBrwHandle:FIRST-COLUMN.
DO-BLK:
DO WHILE VALID-HANDLE(vhBrowseCurCol):
READKEY PAUSE 0.
IF KEYFUNCTION(lastkey) = "END-ERROR" THEN
DO:
vEndError = YES.
LEAVE DO-BLK.
END.
IF vhBrowseCurCol:VISIBLE = TRUE THEN
DO:
hField = hBuffer:BUFFER-FIELD(vhBrowseCurCol:NAME) NO-ERROR.
vWorkSheet:Cells(i ,j):VALUE = (IF VALID-HANDLE(hField) THEN hField:BUFFER-VALUE ELSE hField:SCREEN-VALUE).
j = j + 1.
END.


vhBrowseCurCol = vhBrowseCurCol:NEXT-COLUMN.
END.

END.

TIA

Philip

All Replies

Posted by olivier.dunemann on 21-May-2010 08:48

I guess you can't retrieve each calculated field value by simply referencing its SCREEN-VALUE.

As far as I know, you have to re-apply the code that sets calculated fields' SCREEN-VALUE (in a browse, it's the code that stands in the  ROW-DISPLAY event) for each row returned by your query.

Alternatively, you can put db-fields and calculated fields in a temp-table, and export the content of this temp-table.

Posted by Peter Judge on 21-May-2010 08:58

If you're using ADM2, take a look at the tableOut procedure in adm2/dataquery.p. It calls the columnStringValue() function on a column to get the value, regardless of whether it's a calcfield or not.

-- peter

This thread is closed