ABL syntax question

Don't understand the following for loop syntax,

for first customer fields(Name prodcat prodtype) no-lock
where customer.custno = icust
:

end.



Is there any equivalent way to code the above?
 

Cringer

ProgressTalk.com Moderator
Staff member
Why would you want to do it differently? It's valid syntax and makes sense. It' will do whateve is in the loop for the first record where custno is icust.
 
I don't understand why the fields inside the fields() need to be specified. Why not just code it as follows,

find first customer no-lock
where customer.custno = icust no-error.

And what's the difference between the following,

1.
for first customer fields(Name prodcat prodtype) no-lock
where customer.custno = icust

2.
for first customer fields(Name prodcat) no-lock
where customer.custno = icust

3. for first customer no-lock
where customer.custno = icust


The code is confusing with the syntax fields(Name name1, name2.....)
 

Marian EDU

Member
The code is confusing with the syntax fields(Name name1, name2.....)
Fields was used (useful) in regular client-server topology when the network bandwidth used to be the bottleneck sometimes... it actually means the only the fields you specify will be passe on the client side (plus those that need to identify the record if not already specified).

Things have changes a bit in the meantime in terms of network bandwidth but still the help mention this "Specifying a field list (field-list) for record can increase the performance of remote (network) record retrieval substantially over specifying record alone."

What I do find confusing is the usage of FIRST... looks to me you are getting a single record using the PK, if that is not the case why is that first record so special than the others? Plus this will behave like a FIND in terms of buffer scoping, the buffer will still be available after the for block... consider changing this to 'for each' :)
 

Stefan

Well-Known Member
Fields was used (useful) in regular client-server topology when the network bandwidth used to be the bottleneck sometimes... it actually means the only the fields you specify will be passe on the client side (plus those that need to identify the record if not already specified).

The fields phrase also still has its place in the DataServer world in which even an AppServer is still client-serverish.

As to the original poster - when on SQL or whatever - do you SELECT * FROM table when you only need customer id and name? Do you find that confusing?
 

Marian EDU

Member
The fields phrase also still has its place in the DataServer world in which even an AppServer is still client-serverish.
right, but the reason for which this might look confusing is the fact that this is rarely used... not to mention there are few 'oera' frameworks that I know that does use some form of a 'business logic' proxy as the 'model' on the client, hence passing lots of data in between when the client only need a hand-full of fields most of the times :)
 

TomBascom

Curmudgeon
FOR FIRST is almost always a mistake. Even if you get away with it. The thing that you think should be FIRST may not be. Even if you add BY.
 
The fields phrase also still has its place in the DataServer world in which even an AppServer is still client-serverish.

As to the original poster - when on SQL or whatever - do you SELECT * FROM table when you only need customer id and name? Do you find that confusing?

It won't until you don't use the most commonly used SELECT but FOR FIRST (fields...) then it's confusing to me as I will wonder why the hack you don't use the usual SELECT but the totally strange FOR FIRST :).
 
Fields was used (useful) in regular client-server topology when the network bandwidth used to be the bottleneck sometimes... it actually means the only the fields you specify will be passe on the client side (plus those that need to identify the record if not already specified).

Things have changes a bit in the meantime in terms of network bandwidth but still the help mention this "Specifying a field list (field-list) for record can increase the performance of remote (network) record retrieval substantially over specifying record alone."

What I do find confusing is the usage of FIRST... looks to me you are getting a single record using the PK, if that is not the case why is that first record so special than the others? Plus this will behave like a FIND in terms of buffer scoping, the buffer will still be available after the for block... consider changing this to 'for each' :)

Thanks. At least now I understand what the FIELDS(name) is for.

I am actually looking at codes done by an ex colleague. I think that it's just a matter of coding preference. the whole FOR FIRST here is totally uncalled for as it addresses only one record and for that specific record the number of fields is not significant. FIND should have done the same job well and without adding any confusion to those who follow up the codes. It is insignificant untill you loop for a bunch of records with a large number of fields. It's more about bad coding practice than a consideration of performance.
 
FOR FIRST is almost always a mistake. Even if you get away with it. The thing that you think should be FIRST may not be. Even if you add BY.

It is just used as an alternative of FIND FIRST. It saves not much bandwidth but adding confusion to those who follow up the codes.
 

Stefan

Well-Known Member
It is just used as an alternative of FIND FIRST. It saves not much bandwidth but adding confusion to those who follow up the codes.

Beware, if you are using the MS SQL DataServer, FOR FIRST is significantly (10 times when I last measured this in 2004) faster than FIND FIRST and benefits even more when using a field phrase.
 
Top