Alternative to "Do While"

Hi guys,

This is probably a really easy question to answer but I just cannot seem to get my head round it.

I am compiling a report of orders on a voyage and I need to show the same total charge for each container regardless of how many orders there are in the container. For example:

Order Number      Number of Packages      Weight      Container Number       Charge
AB-123456                                  2                       1235      ABCD123456(0)              2500
AC-234598                                  1                       200              DEFG987654(2)      
AC-258468                                  2                       589              DEFG987654(2)      
AC-987654                                  5                      1800      DEFG987654(2)              2500
AC-789555                                  1                       200              THFC159753(1)      
AC-135879                                 20                      5521      THFC159753(1)              2500

I'm using "Select" to gather the information I need and put it in a table then I scanning it to change some of the values or add other charges. But I can seem to work out how to charge a set amount for all the orders in one container. I did think of using "Do While" but that seems antiquated. Is there a better way of doing it?

I've got this far:

            FROM K:\SSS\S90\S-AOIM02.DBF S_AOIM02;
            WHERE S_AOIM02.M_SHIP_FLT = VOYNO;
            ORDER BY S_AOIM02.M_PONUM;

Please help. My brain hurts.


Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
I don't understand the problem. Maybe if you could post the results you expect, that might help.
davidtottyAuthor Commented:
I obviously didn't explain it very well. I'm trying to give a group total charge for each container in the report. The same amount is charged for each container regardless of how many orders are in it. I want to show the charge next to the last order in the container. Similar to the example above.

Does that explain it better?

Thanks again
Phillip BurtonDirector, Practice Manager and Computing ConsultantCommented:
So you need a charge for (say) the first time that a container is used.


and then use a CTE to apply the charge when MyRowNumber = 1
Introduction to Web Design

Develop a strong foundation and understanding of web design by learning HTML, CSS, and additional tools to help you develop your own website.

davidtottyAuthor Commented:
Thanks Phillip I'll give that a go.
Why the SCAN loop should be antiquated? It is still there so use it. I am sure it will be in all future versions...

OK, you may also create unique index and use it to set the charge:

Let suppose the container number is in the M_CONTNUM column and Charge is currency column containing the container total charge in your TMPVOY table.


You may also delete the temp index now:

To make this REPLACE operation by SQL command would take longer time and the command complexity would also be much higher...

Above code works in VFP 9 SP2.
davidtottyAuthor Commented:
That sounds like a better solution pcelba. I didn't mean the Scan was antiquated I meant "Do While" it feels like an old xbase command.

I'll give your solution a try.

Both DO WHILE and SCAN are old xBase commands. That's OK. The worst thing is FoxPro itself becomes antiquated and unsupported by its owner...

OTOH, community is still improving it:
Unofficial patches:

Free Add-ons:

Olaf DoschkeSoftware DeveloperCommented:
If this is for a report you can have the same charge value for all records of the same container name and make the report only print it once in a group footer.

I'm not a big fan of manipulating the data in the way you print it 1:1 as you see it in a BROWSE. The data is the data and the presentation is the presentation. It's the job of the presentation logic to display it as needed.

So you'd add grouping to your report and group by the container name. Then you put the Charge into the group footer and it will only be printed there.

Bye, Olaf.
Olaf, your post is correct BUT we don't know the existing data structures...

If the container does not have its own table but it is entered into each order (which is wrong) then we should not place the container fee into each order. Such data do not describe the reality. To have the $2500 in each row and use "Print when" is simple a nonsense in such case.

Of course, I am voting for separate Container table which should have the Charge column. Then the "Print when" or Group footer solution is OK.

BTW, to prepare some complex calculations in cursors and then print it to a simple report layout is easier solution to me. I don't like reports where several fields are at one place and complex Print when formulas control printing...
davidtottyAuthor Commented:
Thanks Guys you both have valid points. I'll try using cursors instead.

Thanks for you suggestions.
Olaf DoschkeSoftware DeveloperCommented:
>BTW, to prepare some complex calculations in cursors and then print it to a simple report layout is easier solution to me. I don't like reports where several fields are at one place and complex Print when formulas control printing...

Let's say it this way: The ideal way is you neither need a overly complicated query to get the report cursor as needed nor to have an overly complicated report with complex print when conditions and tricky variables.

I saw the current case as needing the Charge in each last record of the group, which would be the value printed in a group footer, the other records won't matter, if filled with the same value. If you make a report variable summing values and being reset with a group change you'd of course not want the total in each group record, but that wasn't what I thought of.

I merely make a general observation than diving into this problems details.

Bye, Olaf.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
davidtottyAuthor Commented:
Thanks for your help guys
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.