progress language faq's

nsanthosh

New Member
Hi ,

Can anyone pls answer my q's below:

1. what is the diff b/w "for first" and "find first"?

2. What is stream and usage of stream and advantages/applications?


Rgds,
San
 

jongpau

Member
Hi there,

For First starts a block with the first record that meets the criteria. You can use this for all sorts of purposes, including being lazy and having to type a little less code than with a "find first, if available" construction ;-)

A stream is a handy little "thing" if you want to (or need to) output data to more than one destination (file, screen, printer etc) at the same time.
 

nsanthosh

New Member
is it the only difference, because i have come across some codes in mfg/pro core programs where they have used code like:

for first table_name where criteria: end.
if avail table_name do:
.............
somecode
end.

Rgds,
san
 

joey.jeremiah

ProgressTalk Moderator
Staff member
for blocks/statements can use multiple indexes brackets
to find records

which is not only faster but in some situations
a single index bracket will not include all the desired records
and would require a whole table to be scanned

e.g.

for each customer
where custnum <= 10 and name = "mary":
end.

if only one index would be used as was the case in v6
it would require a whole table scan


find can only use one index bracket

so following find prev/next can use the specified index cursor
to move backwards and forwards

and isn't possible if there are multiple indexes
unless a result-list is used, which isn't supported for find

which has alot to do with the way program were written back in v6
for example v6 browsers

the query object is intended to replace the find
in most cases, sometimes it's still simpler to use find

but why here it from me, you can read about it from da'man gus
technical articles \ the engine crew monographs @peg.com

i'd also recommend subscribing to the peg email group
sorry i sold out guys :)


it is expected behaviour if there is a week scope
e.g. repeat, for each etc.

and progress finds another reference to the buffer outside the scope
to raise the scope to include it

e.g.

for first customer:
end.

display customer with 2 columns.

the buffers scope is raised to include the display statement
you can force a strong scope using do for

you can read up about it in your e-docs
programming handbook \ record buffers and scope
 

joey.jeremiah

ProgressTalk Moderator
Staff member
oh, you also had another question about streams
well, no offence but rtfm

we're not really helping you if we do all the work for you
or something like that

even if you don't have the time to read the programming handbook
to get started with progress ( and i would make the time )

when ever you run into something new or aren't sure about
just take 5 minutes to read about it in you on-line ( f1 ) help


good luck !

read, you'll be an expert in no time
 
point missed ...

I think the important point has been missed. This is basic Progress here.
The difference is the buffer. FIND FIRST will actualy make the record available by moving it into the current buffer, this enables manipulation / edit of the record. FOR FIRST will not allow editing of the record. The record has to be found with the appropriate lock before you can edit it. Good practise is to always use the FIND record, the lock can always be upgraded when editing is required. Simply FIND the record without a lock and upgrade.
 
Stream

For data to exit the database, a stream is required for it to use. A stream enables data exit - record retrieval for display or editing purposes.
Raw data is stored in the db. To make this data available for viewing / editing a stream is required to 'grab the data from the database and move it somewhere else'.
 

vinod_home

Member
One more reason...(while using dataserver). And I would think mfg/pro did that because they support dataservers anymore.

-- Steps for Successful DataServer Development and Deployment

FOR FIRST in Place of FIND FIRST
Using FOR FIRST in place of FIND FIRST can improve the performance when
retrieving a single record that is being accessed NO-LOCK.

For example, if your application uses the following FIND FIRST code:
FIND FIRST <table-name> WHERE <where clause> NO-LOCK.

The code can be replaced with:
FOR FIRST <table-name> WHERE <where clause> NO-LOCK:
END.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
mpowel what are you talking about ???

for first will not allow you to edit the record ???

the record will not be placed into the buffer ???
then where does it place them


whenever you reference a record progress makes
the record avail for your use through a buffer

you can update the record anywhere in the program
as long as it's inside the buffer scope

<snippet>
for first item /* exclusive-lock */ :
catDescription = catDescription = "Hello ".
end.

catDescription = catDescription = "World".
</snippet>

the example above works just fine using for statement
haven't you ever updated a table using for each ???

and it works the same
with or without an explicit exclusive lock


along time ago, i promised myself i'll never work
in anything i don't understand

rtfm, you can download them off psdn.com
 

joey.jeremiah

ProgressTalk Moderator
Staff member
sorry for being such a jerk

but, man i missed the part you wrote about streams
i've heard bad superstition that makes more sense

escape the database ???
sounds like the one about pictures stealing your soul


a stream is a source or destination of data
e.g. file, printer, terminal ( even the clipboard )

just like c, funny how much 4gl resembles c
alot of the same concepts, terms, similar syntax etc.


every procedure automatically gets
two unnamed input and output streams

by default progress assigns both of these unnamed streams
to your terminal

i.e. the terminal as the input source, the user types in data
and as the output destination, data is displayed to the user

you can change their source and destination using input/output
e.g. outputting to the printer or receiving input from a file for a batch job


in situations where you need multiple i/o streams
e.g. reading or writing from and to multiple files

you would need to define additional ( named ) streams
besides the two default input/output unnamed streams

or even if you want to keep the unnamed streams as they are
e.g. to receive default/undirected messages and displays to the terminal


you can read up about it in your progress edocs
programming interfaces \ input\output processes
 

John Nebi

Member
I'm confused about the threads. Are you saying you missed what you think I wrote about the streams, or are you addressing someone else? Because I said nothing about streams, I just added that one reply agreeing with you.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
> For data to exit the database, a stream is required for it to use. A stream
> enables data exit - record retrieval for display or editing purposes.
> Raw data is stored in the db. To make this data available for viewing /
> editing a stream is required to 'grab the data from the database and move
> it somewhere else'.

no, i meant mpowell theory on streams
 
Pants

How can my comments be incorrect.
Do you not understand the workings of data.
Data is stored in the database. FACT
To VIEW the data, first the data must be retrieved from the database. FACT.
WHEN VIEWING the data a lock of some kind must be used, to inform **Progress** / the db, that the data is required, whether for viewing or editing.
The fact is that Progress handles this very well.
DO NOT disrespect myself, with utter rubbish. Learn about the topic before you comment, appreciate my points. It is not my fault that you can not follow simple English.
I were just explaining what were happening.
 

John Nebi

Member
No disrespect, it just that what you said was incorrect. Both the FIND and the FOR EACH will bring a record into the buffer, if one is available of course. And, unless it is retrieved with NO-LOCK,it can be updated with an exclusive or shared lock. I'm wondering if you are confusing the FIND with the CAN-FIND, which in fact does not bring a record into the buffer but simply returns true/false.
 

joey.jeremiah

ProgressTalk Moderator
Staff member
and your facts are -

1. Data is stored in the database.
that's a good one where did you learn about that

2. first the data must be retrieved from the database
again, your sharp

3. WHEN VIEWING the data a lock of some kind must be used,
to inform **Progress** / the db, that the data is required,
whether for viewing or editing.

in a monkeys ***, locks in progress or other
are used for managing isolation in transaction

transactions four basic properties, the well-known ACID properties
atomicity, consistency, isolation, and durability

if you're reading only there's no need to lock the record ( no-lock )
in fact if you do lock them it would impact performance

you might be confusing locks with resource latching
but those are split millisecond operations


4. The fact is that Progress handles this very well
again, you've proved me wrong

weren't we talking about buffers and streams
what the hell are you talking about ???


this is like arguing with a crazy person
well, it's been fun, bye
 
The reason MFG/PRO switched from find first to for first was to use "field lists" with eb desktop. A find will return all fields in a record, for first with a field list will only return the fields identified in the list.
 

John Nebi

Member
That makes sense. The fields option, which was added after version 6, perhaps even after version 7, I can't remember anymore, reduces network overhead. But, by default, that is, without the fields option, there will be a record in the buffer with all fields. I would have to test what happens if the fields options is given with no fields specified. Compiler error, perhaps.
 
Top