Problem with next statement

make

Member
Hi there,

i want to look if a tt.aarnr is in lfschein.aarnr. If this is true the next lfschein.aarnr should be tested. But in my solution the next tt.aarnr will be tested.
When a tt.aarnr is found my programm should go on with the next lfschein.


FOR EACH lfschein use-index lfsdatum WHERE lfschein.lfsdatum >= ChVon
AND lfschein.lfsdatum <= ChBis
NO-LOCK:
Find tt
where tt.aarnr = lfschein.aarnr no-lock no-error.
if available tt then do:
next.
end.

Thanx Make
 

Crittar

Member
Make,

Code:
FOR EACH lfschein NO-LOCK
  USE-INDEX lfsdatum 
  WHERE lfschein.lfsdatum >= ChVon
    AND lfschein.lfsdatum <= ChBis: 

  FIND tt 
    WHERE tt.aarnr = lfschein.aarnr NO-LOCK NO-ERROR.

  IF AVAILABLE tt THEN
    NEXT.

END.

Should do exactly what you want:

if a matching record for lfschein is found on the tt then the next lfschein record will be read.

If you don't actually need to do any processing with the temp-table then it would probably be quicker to use the can-find function. In either case it will be faster if the temp-table has an index defined on it.

Hope this helps.

:)
 

jongpau

Member
Hi Make,

Since it looks like you only want to test for the existence of a record, it is better to use a CAN-FIND statment instead of a FIND, eg:
Code:
testlfschein:
FOR EACH lfschein NO-LOCK
  USE-INDEX lfsdatum 
  WHERE lfschein.lfsdatum >= ChVon
    AND lfschein.lfsdatum <= ChBis: 

  IF CAN-FIND (tt 
    WHERE tt.aarnr = lfschein.aarnr)
  THEN NEXT testlfschein.
  ..
  ..  
END.
A CAN-FIND does exactly what it says, testing if it can find a record, but it does NOT place the record in the record buffer. This saves (sometimes valuable) time.

HTH
 
The following will only go through those ifschein records where no tt.aarnr exists (is that what you want to do?).

Code:
FOR EACH lfschein NO-LOCK
  USE-INDEX lfsdatum 
  WHERE lfschein.lfsdatum >= ChVon
    AND lfschein.lfsdatum <= ChBis
    AND NOT CAN-FIND (tt 
    WHERE tt.aarnr = lfschein.aarnr):
  ..
  ..  
END.
 
Top