can find in a query

longuard

New Member
hi
i want to do sometihing like that in a query
FOR EACH dsg_Mark
WHERE dsg_mark.entity-code = "X"
AND
NOT CAN-FIND(
dsg_mark_ml
WHERE dsg_mark_ml.entity-code = dsg_mark.entity-code
AND dsg_mark_ml.quote-no = dsg_mark.quote-no
AND dsg_mark_ml.ml-mark = dsg_mark.mark) :
DISPLAY dsg_mark.entity-code dsg_mark.quote-no dsg_mark.mark.
END.
 

TomBascom

Curmudgeon
hi
i want to do sometihing like that in a query

Code:
FOR EACH dsg_Mark 
      WHERE dsg_mark.entity-code = "X" 
       AND 
         NOT CAN-FIND( 
             dsg_mark_ml 
            WHERE dsg_mark_ml.entity-code = dsg_mark.entity-code
                AND dsg_mark_ml.quote-no    = dsg_mark.quote-no
                AND dsg_mark_ml.ml-mark      = dsg_mark.mark) :
DISPLAY dsg_mark.entity-code dsg_mark.quote-no dsg_mark.mark.
END.

What's your question?

Offhand I'll comment that you're missing a couple of NO-LOCK keywords and that NOT CAN-FIND() is probably going to turn this into a really slow query

If it were me I'd probably code this like so:

Code:
for each dsg_mark no-lock where dsg_mark.entity-code = "X":

  find dsg_mark_ml no-lock where 
            dsg_mark_ml.entity-code = dsg_mark.entity-code
      and dsg_mark_ml.quote-no    = dsg_mark.quote-no
      and dsg_mark_ml.ml-mark      = dsg_mark.mark no-error.

  if available( dsg_mark_ml ) then
    next.
   else
    display
      dsg_mark.entity-code
      dsg_mark.quote-no
      dsg_mark.mark
    .

end.

I think that it is a lot more readable and it is a lot easier to see what the code is actually doing.
 

longuard

New Member
i know this is not the best to do but i need code to do the samething of
Code:
for each dsg_mark no-lock where dsg_mark.entity-code = "X":

  find dsg_mark_ml no-lock where 
            dsg_mark_ml.entity-code = dsg_mark.entity-code
      and dsg_mark_ml.quote-no    = dsg_mark.quote-no
      and dsg_mark_ml.ml-mark      = dsg_mark.mark no-error.

  if available( dsg_mark_ml ) then
    next.
   else
    display
      dsg_mark.entity-code
      dsg_mark.quote-no
      dsg_mark.mark
    .

end.
 
[code]
 but in a query 
i want all dsg_mark there are no correspondance in the second table
 

longuard

New Member
i have to use a query and in a query a cannot use the next or a can-find
do you have a idea of how to do.
 

RKR

Member
I really hate using next and/or leave in the middle of my code. It makes spaghetti and not lasagna.

I would code it a little different.

Code:
for each dsg_mark no-lock where dsg_mark.entity-code = "X":

  find dsg_mark_ml no-lock where 
            dsg_mark_ml.entity-code = dsg_mark.entity-code
      and dsg_mark_ml.quote-no    = dsg_mark.quote-no
      and dsg_mark_ml.ml-mark      = dsg_mark.mark no-error.

  if not available( dsg_mark_ml ) 
  then
    display
      dsg_mark.entity-code
      dsg_mark.quote-no
      dsg_mark.mark
    .
end.
I think that it is a lot more readable and it is a lot easier to see what the code is actually doing.[/quote]
 

TomBascom

Curmudgeon
A QUERY itself cannot use NEXT but that isn't how you code with a QUERY.

Using OPEN QUERY the code would look something like this:

Code:
define query q for dsg_mark, dsg_mark_ml.

open query q for
  each dsg_mark no-lock where
    dsg_mark.entity-code = "X",
  first dsg_mark_ml no-lock left outer-join where 
    dsg_mark_ml.entity-code = dsg_mark.entity-code and
    dsg_mark_ml.quote-no    = dsg_mark.quote-no and
    dsg_mark_ml.ml-mark      = dsg_mark.mark.

get first q.

do while available( dsg_mark ):

  if not available( dsg_mark_ml ) then
    display
      dsg_mark.entity-code
      dsg_mark.quote-no
      dsg_mark.mark
    .

  get next q.

end.

Eliminating the NEXT isn't unique to using a QUERY -- I could have done it above too...

If your real problem is that you now need to hook that query to a BROWSE then I think that you are going to have to build a temp-table using a loop similar to the one above and then browse on that. Or you might be able to do something interesting with a ProDataSet.
 

TomBascom

Curmudgeon
I really hate using next and/or leave in the middle of my code. It makes spaghetti and not lasagna.

I would code it a little different...

I actually started with that. But then I got to thinking that the NEXT makes it explicit that we're throwing away the record -- leaving it out implies it but I wasn't feeling that it was clear enough.
 

RKR

Member
I understand what you are saying, but if you see how many times programmers use next or leave and even returns in the middle of the code it gives you a small headache. You can simply avoid it by taking a different approach to the problem. It makes shorter code, so it is easier to read and better to maintain. And it prevents problems like forgetting to clean up handles when you no longer need them.


I actually started with that. But then I got to thinking that the NEXT makes it explicit that we're throwing away the record -- leaving it out implies it but I wasn't feeling that it was clear enough.
 

longuard

New Member
i have to use that code in couple of way with a proxy and in a BROWSE
for the prodataset of the proxy, its take 1000 miliseconds to remove the record i did'nt want. I want to find a way its could be more faster and in for the browse a need to change at less code as possible.
 

longuard

New Member
i not sure if that could help but dsg_mark_ml.ml-mark containt the name of a second mark its a circular relation.
 
Top