Reference vs Availability

What is the difference between the reference of a table and availability of a table?

For ex:
Code:
FOR EACH customer:
END.
IF customer.name = “something” THEN
MESSAGE “something”.

Compiler will allow me to compile this code without any error or I could reference the table customer outside the block, because for each is a weak scope block and scope of the table is outside the for each block but if I check availability of table customer by AVAILABLE customer then it will return NO, why?

Please suggest.

Thanks & Regards!
Rajat.
 

GregTomkins

Active Member
Read up on record and buffer scoping rules, although your use of the term 'weak scope block' suggests that you already did this. But to cut to the chase:

1) That code will compile, but it will always produce a runtime error. So when you say 'I could reference', that's only true at compile time.

2) You could have included a statement such as 'FIND FIRST customer' prior to the FOR EACH. If the FOR EACH was conditional, that record would still be usable.

I think your question is 'why can't the compiler stop me from doing this?' and the answer is probably 'because it would be difficult for it to figure out all the nuances of record availability statically', so it happens at run time.
 

RealHeavyDude

Well-Known Member
A valid buffer scope does not necessarily mean that it actually holds a record - it just means that the compile will happily accept every reference to the buffer but does not care whether a record is available. There are too many code constructs which can lead to a record being available or not for the compiler to check. Also the compiler won't check whether there are any records in the table that you compile against ...

It is the same as you would code for example:
Code:
find Customer where rowid ( Customer ) = ? no-error.
display customer.name.
This will compile fine but always produce a runtime error as it will never find a record.

Heavy Regards, RealHeavyDude.
 
Thanks for replaying Dude!

So you want to say that the scope of FOR EACH block is available outside the block but it doesn't contain record in the buffer. If yes, then there should be no harm to use weak scope buffer or what is the use of this reference. Please suggest.

Do we have other blocks that holds record in buffer outside its scope.

Thanks!
Rajat.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
The buffer is scoped to the procedure because it is referenced in the IF statement. Look at a COMPILE LISTING for your code:
Code:
{} Line Blk
-- ---- ---
  1  1 FOR EACH customer:
  2    END.
  3    IF customer.name = "something" THEN
  3    MESSAGE "something".
 .\a.p  07/31/2014 09:01:44  PROGRESS(R) Page 2

     File Name       Line Blk. Type   Tran Blk. Label
-------------------- ---- ----------- ---- --------------------------------
.\a.p                   0 Procedure   No
    Buffers: s2k.Customer

.\a.p  1 For  No
The buffer "customer" is scoped to the procedure.

Now if you comment out the IF statement that contains the reference to the buffer outside the FOR block, the scope changes:
Code:
{} Line Blk
-- ---- ---
  1  1 FOR EACH customer:
  2    END.
  3    IF customer.name = "something" THEN
  3    MESSAGE "something".
 .\a.p  07/31/2014 09:01:44  PROGRESS(R) Page 2

     File Name       Line Blk. Type   Tran Blk. Label
-------------------- ---- ----------- ---- --------------------------------
.\a.p                   0 Procedure   No
.\a.p                   1 For         No
    Buffers: s2k.Customer

.\a.p  1 For  No

Now the buffer "customer" is scoped to FOR block.
 
Top