Resolved Using Break By - Error "missing For, Find Or Create"

JoseKreif

Member
This is probably a rookie mistake, but I can't see why it doesn't work.

Code:
for each custs  break by state:


  if first-of(state) then display state.

  accumulate discount (sub-total by state).

  display num name discount (total by state).

  if last-of(state) then
  display state ACCUM sub-total by state (discount).

end.

On line 4 I get
"** Missing FOR, FIND or CREATE for table state. (93)
Could not understand line 4. (196) "


I am using Progress Character-Mode 10.2b.

I'm just playing around with the Accum and break by feature so I can begin optimizing some real reports.

EDIT:

The above code is kind of messy. Here is a more fluent version

Code:
for each custs break by state:

  if first-of(state) then display state.
  display num name discount  (total by state).

end.


EDIT 2: Never mind, I found out that it's an ambiguous problem. I have a table named "State"

I have to display custs.state
 
Last edited:

GregTomkins

Active Member
I am guessing you also have a table named 'state' in your database, and that if you qualify the reference to the field, it will work.
eg: 'if first-of(custs.state) ...'.
Progress does some funny things with making assumptions/guesses for you, and applying defaults, but, so does every language.
 

Osborne

Active Member
Is state a field or a table? If a field then prefix the field with the table name - custs.state instead of just state. Also do that for the other fields - custs.discount, custs.num and custs.name.

However, if a table then need to include in the for each:
Code:
for each custs, each state of custs break by state.fieldName:
 

TheMadDBA

Active Member
Came to post what Greg did... also there are a lot of alternatives to using ACCUM and BREAK-BY. ACCUM works well in simple cases but you will get more mileage out of using temp-tables to accumulate totals. Especially as the requirements get more and more complex and/or the data gets to a point where a BREAK-BY isn't always feasible.

And learn to love putting NO-LOCK on your queries :)
 

JoseKreif

Member
I am guessing you also have a table named 'state' in your database, and that if you qualify the reference to the field, it will work.
eg: 'if first-of(custs.state) ...'.
Progress does some funny things with making assumptions/guesses for you, and applying defaults, but, so does every language.


I didn't see your answer in time, but you're correct. I got a feeling it was that. I went and checked and sure enough, there is a table named "State". So I did reference the current table by doing custs.state

And learn to love putting NO-LOCK on your queries :)

I do, I just leave it out when in my sandbox database for quick code testing
 

tamhas

ProgressTalk.com Sponsor
Along with no-lock, you should qualify all field names with the table name. Then, this kind of thing won't happen.
 
Top