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!

LEDGER PAGE NO. 3

mohinder singh

Programmer
Jun 30, 2021
11
CA
HI
I WANT TO STORE EACH PAGE NO. IN MY ACCOUNTING LEDGER REPORT FOR INDEX PAGE
 
Last edited:
I was trying to empathize is that it should update a row, rather than insert one into a log.
That's what I understood was asked for anyway: To update a pageno field in a ledger record, which obviously already exists.

And as it is for creating an index page as appendix of the report, perhaps in a separate report, perhaps in the same report which creates that data on the fly, there also is no need to avoid inserting new rows into another table, as this is temporary information about this report run and you can purge it after priting.

I'd consider SYS(2040) even more important, therefore, as it helps to act differently when a report is run with vs without preview. You might not want to preview the index pages, for example and add the data in the printing phase only. You might want the opposie and therefore do it in the preview phase, if there is one, then skip it in the printing phase or you program as you and I suggest with updates that don't create duplicate data.
 
That's what I understood was asked for anyway: To update a pageno field in a ledger record, which obviously already exists.

And as it is for creating an index page as appendix of the report, perhaps in a separate report, perhaps in the same report which creates that data on the fly, there also is no need to avoid inserting new rows into another table, as this is temporary information about this report run and you can purge it after priting.

I'd consider SYS(2040) even more important, therefore, as it helps to act differently when a report is run with vs without preview. You might not want to preview the index pages, for example and add the data in the printing phase only. You might want the opposie and therefore do it in the preview phase, if there is one, then skip it in the printing phase or you program as you and I suggest with updates that don't create duplicate data.
All valid points.

We often see odd requests from people in these forums from developers who don't explain their question well. Then after we offer them advice or even pseudocode we come to realize they likely are modifying a system that was designed by somebody else years ago who had more experience with fundamentals than them.

When he said the suggested code didn't work, I realized he likely tried it word for word and is a new developer who may lack certain skills.

So I just wanted to be sure he realized that the function will run every time that the user reprints or even previews the report, so they understand that whatever index he will be creating should be maintained using updates to existing records rather than inserts to a log.
 
Mohinder Singh,

to me no further posts to a thread are a sign you got it going, but for sake of giving an example:
1. I created an FRX based on Northwind sample data of VFP9 (in the _samples+"Northwind" directory).
2. The report contains grouping by orderid and in the header band of the group I created a report field like this:
1741775587806.png
3. Running the report (orders.frx) with this code:
Code:
* base data for the report
Open Database _samples+"\Northwind\Northwind.dbc"

* pepare a cursor for reporting
Select *, Cast(0 as int) as pageno from Orders as or ;
   left join OrderDetails as od on od.orderid = or.orderid;
   left join Products as pr on od.productid = pr.productid;
   into Cursor ordersreport readwrite

* frx printing that data grouped by orderid
Report Form orders Preview

* Just for sake of verifying it worked list the orders and which pageno they got printed in
Browse Fields order=orderid_a, pageno

* function used in a report field that's part of the group header band
* with the expression UpdateOrderWithPageno(orderid_a,_pageno)

Function UpdateOrderWithPageno(tnOrderid, tnPageno)
    rn = Recno()
    Update ordersreport set pageno=tnPageno where orderid_a = tnOrderid
    Goto rn in ordersreport
    Return ''

I made use of the idea to not print anything at all in the report field that makes the call to the function which updates the report cursor, because I don't print the orderid, I print the orders customer and orderdate as header of the group, the orderid is a techincal database key I decide to never print.

And this is shown by the browse after the report run, I added the pageno field in the SQL Select query into the cursor that's also driving the report and you can see in the function I therefore also make sure I don't move the record pointer away from the current record by first storing current RECNO into a variable and going back to that record after the SQL UPDATE. Because in testing without ensuring to end on the same recno the report end prematurely.

Here's just the start of the final data:
1741776120781.png
That could now be used to print an appendix listing all orders and their respective page number.
 
Last edited:
I understood why the recno was changed by the update, of course: Due to the left join select I have multiple rows per order and so the update always advances to the last orderdetail of an order, if not to the next order.

As a consequence the function can be reduced to

Code:
Function UpdateOrderWithPageno(tnOrderid, tnPageno)
   Replace pageno with tnPageno
   Return ''
And as that doesn't move the record pointer I don't need the GOTO any more.

The end result then only stores the pageno in each first record of an order:
1741777610542.png
Still fine, or you store it into an extra cursor or DBF. At least it all works.

One last notice: If you only preview page 1, the index data will also only cover page 1, so you need a full report run to get the full index data. It should be obvious, I just tell it for sake of completeness of the solution idea.
 
Last edited:
Mohinder Singh,

to me no further posts to a thread are a sign you got it going, but for sake of giving an example:
1. I created an FRX based on Northwind sample data of VFP9 (in the _samples+"Northwind" directory).
2. The report contains grouping by orderid and in the header band of the group I created a report field like this:
View attachment 1873
3. Running the report (orders.frx) with this code:
Code:
* base data for the report
Open Database _samples+"\Northwind\Northwind.dbc"

* pepare a cursor for reporting
Select *, Cast(0 as int) as pageno from Orders as or ;
   left join OrderDetails as od on od.orderid = or.orderid;
   left join Products as pr on od.productid = pr.productid;
   into Cursor ordersreport readwrite

* frx printing that data grouped by orderid
Report Form orders Preview

* Just for sake of verifying it worked list the orders and which pageno they got printed in
Browse Fields order=orderid_a, pageno

* function used in a report field that's part of the group header band
* with the expression UpdateOrderWithPageno(orderid_a,_pageno)

Function UpdateOrderWithPageno(tnOrderid, tnPageno)
    rn = Recno()
    Update ordersreport set pageno=tnPageno where orderid_a = tnOrderid
    Goto rn in ordersreport
    Return ''

I made use of the idea to not print anything at all in the report field that makes the call to the function which updates the report cursor, because I don't print the orderid, I print the orders customer and orderdate as header of the group, the orderid is a techincal database key I decide to never print.

And this is shown by the browse after the report run, I added the pageno field in the SQL Select query into the cursor that's also driving the report and you can see in the function I therefore also make sure I don't move the record pointer away from the current record by first storing current RECNO into a variable and going back to that record after the SQL UPDATE. Because in testing without ensuring to end on the same recno the report end prematurely.

Here's just the start of the final data:
View attachment 1874
That could now be used to print an appendix listing all orders and their respective page number.
Thanks, sir
this code works properly
 

Part and Inventory Search

Sponsor

Back
Top