If I just need to know if there is data, I add Limit=1 to the WHERE clause when populating the vRows variable. With 64 bit system, not noticeable to the user but as soon as the system finds matching data it exits with the value of 1 and if it finds none 0.

SET VAR vRows INTEGER
SELECT COUNT(*) INTO vRows FROM SourceTable +
WHERE datecomp IS NULL +
AND ((crew1 = .zcrew) + OR (crew2 = .zcrew) + OR (crew3 = .zcrew) + OR (crew4 = .zcrew)) +
AND LIMIT = 1

On 2015-12-18 9:22 AM, Javier Valencia wrote:
Dennis,

I use the same approach as R:azzak suggested and have for a while now.

FWIW, I  only use one IF statement as follows...

IF vRows > 0 THEN
    PRINT needfile ORDER BY site WHERE datecomp IS NULL AND ((crew1 = .zcrew)
+
    OR (crew2 = .zcrew) +
    OR (crew3 = .zcrew) +
    OR (crew4 = .zcrew)) +
    OPTION SCREEN|WINDOW_STATE MAXIMIZED +
    |ZOOM_TYPE percentage 98
ELSE
     PAUSE 2 USING 'No qualifying records to print this report' +
     CAPTION 'Print Report' ICON WARNING +
     BUTTON 'Press any key to continue ...' +
     OPTION BACK_COLOR WHITE +
     |MESSAGE_FONT_NAME Tahoma +
     |MESSAGE_FONT_COLOR RED +
     |MESSAGE_FONT_SIZE 11
     GOTO Done
ENDIF

I am not sure if there is much of a difference other than to me, the
IF...ELSE...ENDIF seems to be easier to understand because the entre logic
is contained in the IF-ELSE-ENDIF construct; of course that is just my
personal view based on the way my brain works and other might think the
other way is better. I seem to remember reading that GOTOs use more
resources but it might have been many versions ago and it might not matter
now; we all seem to stick with works for us based on what we consider good
programming practices...which sometimes turn out to be incorrect. :(

Maybe someone can chime in on the differences, performance-wise, of the two
approaches.

In any case, on you original question, capturing the error variable, it
seems like you had a typo on the last command:

set var holderr = .verrvar

If you look at it, it looks like the variable "holder" has an extra "r" at
the end and this is why it probably was not storing the variable where you
thought it was. Best way to check is to TRACE the code while displaying
variables on the panel on the right, and displaying both the variables
"verrvar" and "holder" and as the error happens you will see the error
variable change values and when you assigned it to "holder" it should take
the value of the error variable and the error variable should reset.

Javier,

Javier Valencia, PE
O: 913-829-0888
H: 913-397-9605
C: 913-915-3137
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Hodges,
Dennis
Sent: Friday, December 18, 2015 8:51 AM
To: [email protected]
Subject: [RBASE-L] - Re: Error trapping on Print command

Thanks Razzak, it worked perfectly, just what I needed.

Dennis Hodges
Maintenance Management Manager
FDOT Office of Maintenance MS #52
PH: (850) 410-5635
FAX: (850) 410-5511
[email protected]

"Life doesn't have a remote, get up and change yourself."

Please note: e-mail may be subject to public disclosure.

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of A. Razzak
Memon
Sent: Friday, December 18, 2015 9:06 AM
To: Hodges, Dennis
Subject: [RBASE-L] - Re: Error trapping on Print command

At 08:51 AM 12/18/2015, Hodges, Dennis wrote:

In the following print command if the where command returns no records,
the value of holder is 0, but I get a 2059 error message.  How can I
trap this error?

SET ERROR VARIABLE verrvar
   PRINT needfile ORDER BY site WHERE datecomp IS NULL AND ((crew1 =
.zcrew) +
   OR (crew2 = .zcrew) +
   OR (crew3 = .zcrew) +
   OR (crew4 = .zcrew)) +
   OPTION SCREEN|WINDOW_STATE MAXIMIZED +
   |ZOOM_TYPE percentage 98
   set var holderr = .verrvar

Dennis,

Here is the best approach to handle such circumstances ...

-- Start here ...
SET VAR vRows INTEGER = 0
SELECT COUNT(*) INTO vRows INDIC iv1 FROM reporttablename + WHERE datecomp
IS NULL AND ((crew1 = .zcrew) +
    OR (crew2 = .zcrew) +
    OR (crew3 = .zcrew) +
    OR (crew4 = .zcrew))
IF vRows = 0 THEN
     CLS
     PAUSE 2 USING 'No qualifying records to print this report' +
     CAPTION 'Print Report' ICON WARNING +
     BUTTON 'Press any key to continue ...' +
     OPTION BACK_COLOR WHITE +
     |MESSAGE_FONT_NAME Tahoma +
     |MESSAGE_FONT_COLOR RED +
     |MESSAGE_FONT_SIZE 11
     GOTO Done
ENDIF
    CLS
    PRINT needfile ORDER BY site WHERE datecomp IS NULL AND ((crew1 = .zcrew)
+
    OR (crew2 = .zcrew) +
    OR (crew3 = .zcrew) +
    OR (crew4 = .zcrew)) +
    OPTION SCREEN|WINDOW_STATE MAXIMIZED +
    |ZOOM_TYPE percentage 98
LABEL Done
    CLS
    CLEAR VARIABLES iv%,vRows
    RETURN
-- End here ...

Hope that helps!

Very Best R:egards,

Razzak





Reply via email to