Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SCATTER GATHER Question 2

Status
Not open for further replies.

Scott24x7

Programmer
Jul 12, 2001
2,828
JP
All,
Sometimes, I simply need to update some values from a lookup table into my current table. In my 2.6 days, I'd just grab my code table, and do:

SELECT CTCODE
SCATTER MEMVAR
SELECT CUSTOMER
GATHER MEMVAR

Is this still an "Acceptable" method? (I tried it, and it did work... but I've seen so much about "Don't use Scatter Gather" anymore, I'm a little unsure. In this case, every field in the CTCODE table I want updated in the CUSTOMER table. Is there some better "SQL" type instruction I might use???

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
Oh, one other thing... Note that I'm ONLY updating a single record in the CUSTOMER table this way, not a group of them, which is exactly what I want.
Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
scatter/gather should be the best way for your case. I don't know why not???
 
HI
As far as I know, SCATTER GATHER INSERT etc are all well accepted, though some talk sceptical.. probably, newer methods of buffering available. But I use all these while I use newer techniques as well.

Just for awareness..
SCATTER MEMVAR && Memory variables are initialised
SCATTER NAME oTest && oTest Object created and each of the fields are made members of that object.
SO oTest.Field1 oTest.Field2 etc contains the values similar to m.field1 m.field2

Again..
INSERT INTO myTable FROM MEMVAR && faster
or..
APPEND
GATHER MEMVAR
works equivalent with two steps and obviously slower.

However.... what ever you are doing is perfectly acceptable to VFP.
:) ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Ramani,
One point of clarity, will "INSERT INTO" work on a current record, or does it create a New record? Is there a "Clause" that can be added to INSER INTO, or is ther a SQL UPDATE type thing?

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
Ramani, while I usually agree with you, this time I beg to differ. There is almost no reason for a scatter, gather with the table buffering techniques now available.

It just encourages sloppy code and leaving various scattered variable, scattered around (pardon the pun). No where in any of the samples above to I see code that cleans up the variables left about by the scatter.

This is one of the first things I 'break' my new junior programmers of.

In our shop there are only two times to use a scatter/gather. To copy a record in a table to a new record in the same table or to use a scatter memvar to pass a large amount of data to a form.
 
Scott,

The code I inherited (lucky me) was full of SCATTER/GATHER commands. The code is an absolute mess...there are over 700 variables declared PUBLIC in the main PRG file, and ALL of the forms in the project are MODAL. There was no other way for the original author to keep the forms from conflicting with each other!

Call me biased...but I've come to really hate SCATTER MEMVAR.

I still use SCATTER, but I always either use the TO clause to create an array or the NAME clause to create an object. Both of these make cleanup a breeze. A single RELEASE command will do it, or a single LOCAL or PRIVATE declaration.

In your example, I would definitely go with the SCATTER NAME example that Ramani suggested. Something like this:
Code:
LOCAL oTemp
SELECT CTCODE
SCATTER NAME oTemp
SELECT CUSTOMER
GATHER NAME oTemp
 
HI SCOTT,

INSERT adds a record with the values while append add a blank record and then GATHER replaces the values.

Hmmmmmmm...... As I mentioned in my post, you can see the scattered opinions poping up !. As I told, buffering is good (I agree with Fluteplr) in situations like many variables. But in a controled environments with private data scession, the release of forms does the cleanup.. and in a form, I have not used that many variables. Again, when such a situation arises.. NAME objects come into play, if required.

The question is not to get into controversy as to which is better or bad. As for as VFP is concerned, SCATTER / GATHER is perfectly OK as a language. The programmer has to decide which is easy or handy for the situation. This is purely my opinion. :)

ramani :-9
(Subramanian.G),FoxAcc, ramani_g@yahoo.com
 
Hi all;

Q: What do you have when you have 10 FoxPro developers in a room?

A: Eleven different ways to do something. :)

Ed Please let me know if the sugestion(s) I provide are helpful to you.
Sometimes you're the windshield... Sometimes you're the bug.

 
All,
Well, the beauty is, I got more than one question answered... hehe, and I get a result I can live with.
Up to this point, in the Application I'm building, I have not used any Scatter/Gather, as the Tablebuffereing has been beautiful. The problem I encountered is exactly as FLTPlayer put it, which is, I have a record that has a large number of variables that I simply want to move from one table to another. CHPicker provided what others suggested, which I agree is a very pretty, (and quite nice way of doing it) with SCATTER NAME oStuff. That is really cool. It's nice to be able to just issue a RELEASE oStuff as soon as you're done, and get rid of all the misc. vars floating about. Excellent solutions! Many thanks to all!

Thanks,
-Scott

s-) Please let me know if this has helped s-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top