I thought I would share with you a method I found for comparing
field differences.  

Problem: decide if I need to insert a record into a previous
address history file via action in a stored procedure.  I was
working an this complex IF statement to determine it the SYS_NEW
record was different that SYS_OLD record.  Say for a field such
as HMainAddressLn.  If you have SELECT HMainAddressLn INTO
NHMainAddressLn INDICATOR NIvMainAddress FROM ... WHERE CURRENT
OF SYS_NEW; SELECT HMainAddressLn INTO PHMainAddressLn INDICATOR
PIvMainAddress FROM ... WHERE CURRENT OF SYS_OLD. I was writing
the following:
 IF ((NHMainAddressLn <> .PHMainAddressLn) OR +
(NHMainAddressLn IS NOT NULL AND PHMainAddressLn IS NULL) OR +
(NHMainAddressLn IS NULL AND PHMainAddressLn IS NOT NULL)) OR +
... SAME TEST REPEATED FOR ADDITIONAL FIELDS ... THEN
  SET VAR VFieldsAreDif = 'YES'
ENDIF

Think of repeating that for up to 8 fields.  Upon review of
documentation, it dawned on me that I could use the indicator
variables in place of the NULL/NOT NULL tests.  The indicator
variables will ALWAYS be set to 0 if NOT NULL and -1 if NULL.

Thus a test works in place of the above null tests:
n=0 <> p=0 both have value = OK
n=-1 <> p=-1 both null = OK
n=0 <> p=-1 field is Different
n=-1 <> p=0 field is Different

IF NHMainAddressLn <> .PHMainAddressLn OR +
 NIvMainAddress <> .PIvMainAddress OR +
... SAME TEST REPEATED FOR ADDITIONAL FIELDS ... THEN
  SET VAR VFieldsAreDif = 'YES'
ENDIF

I hope this offers some help in simplifying your coding.

Jim Bentley


Jim Bentley
American Celiac Society
[EMAIL PROTECTED]
tel: 1-504-737-3293

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


Reply via email to