Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

save pdf report one record at a time

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    save pdf report one record at a time

    I'm Baaaaaaaaaaaaack :D

    I have a report designed that is filtered based on a logical field value being set to TRUE.

    Instead of saving the report with all the records that match the filter into ONE pdf file, I would like to 'loop' through my table and create a separate report for each record. This way I have a separate pdf file for each customer instead of all of them in one pdf.

    I am sure this is quite simple, but for some reason I cannot figure out how to set my report filter so that it knows to only grab one record at a time.

    This is for billing purposes where I need to create 3 different pdf files for each customer, then combine the three files into one creating the final invoice. I will be using the pdf_append() for this portion and plan to create the report filenames based on a cust_no + report_name.

    Ideas please?
    Thanks
    Cheryl
    #1 Designs By Pagecrazy
    http://pagecrazy.com/

    #2
    Re: save pdf report one record at a time

    I would think that the easiest way would be to build a "while" loop in your calling script which would run the report separately for each customer.


    something like this:

    Code:
    tbl = table.open(your master table name)
    tbl.index_primary_put(your index)
    tbl.fetch_first()
    while .not.tbl.eof()
      filter code here
      report.print(your report)
      tbl.fetch_next()
    end while

    You would obviously need to figure out some sort of scheme to rename the pdf's as they are generated, but I think you can do that in the report itself.

    Tom

    Comment


      #3
      Re: save pdf report one record at a time

      Hi Tom,

      My problem is with determining the filter that I need or perhaps the index I should be using.

      Code:
      tbl = table.open("customer")
      tbl.index_primary_put("Cust_No")
      tbl.fetch_first()
      while .not.tbl.eof()
        report.preview("B_Cast_Test")
        tbl.fetch_next()
      end while
      The above code returns the same ONE report with all the records the same as running the report on its own. The difference being the above is looping through my customer table so I am stuck in an endless loop

      The current filter set in the report itself is:

      Code:
      Broadcast_raw->Report_Date >= "10/01/2007" .AND. Broadcast_raw->Report_Date <= "10/02/2007" .AND. Customer->OK_to_bill = .t.
      The report is based on a set where Broadcast_raw is the parent linked 1:1 on an ID field in an ID table and that linked 1:1 on an ID field (cust_no) in the Customer table.

      I am not sure if the report being based on a set makes a difference or not.

      Lets say in my customer table I have 4 out of 100 customers marked with ok_to_bill as true. Customer numbers would be 001, 002, 003, 004.

      The broadcast_raw table has 12 records that match the dates between 10/01 and 10/02.

      I want one report for customer 001 with the records between 10/01 and 10/02. Then a second report for customer 002, then 003, etc.

      I know this has to be simple and I am just missing the right filter, or possibly the right index.

      Thanks
      Cheryl
      #1 Designs By Pagecrazy
      http://pagecrazy.com/

      Comment


        #4
        Re: save pdf report one record at a time

        Code:
        Dim global which as C
        tbl = table.open("customer")
        tbl.index_primary_put("Cust_No")
        tbl.fetch_first()
        while .not.tbl.eof()
          which = tbl.Cust_No
          report.preview("B_Cast_Test")
          tbl.fetch_next()
        end while
        and change the report filter to


        Code:
        Broadcast_raw->Report_Date >= "10/01/2007" .AND. Broadcast_raw->Report_Date <= "10/02/2007" .AND. Customer->OK_to_bill = .t. .and. Customer->Cust_no = var->which
        There can be only one.

        Comment


          #5
          Re: save pdf report one record at a time

          Thanks Stan. Your suggestion made perfect sense to me and I was certain it was going to work .... but, since I am testing using preview mode just to verify that I am getting the proper results ... I added a query prior to previewing the report so that if there are no matching records, it skips that preview and goes to the next record in my customer table.

          The following code seems to be looping through the table correctly and providing separate previews for each matching customer.

          However, it is not giving me the last matching record. In my testing, when I run my report with the hard coded filter NOT using the which variable for the cust_no value, the report returns correctly with 3 customers in the one report. The following code, however, is only returning the first 2 and not giving me the last customer.

          Code:
          dim global which as c
          
          tbl = table.open("customer.dbf")
          tbl.index_primary_put("Cust_No")
          tbl.fetch_first()
          WHILE .not.tbl.eof()
              which = str(tbl.Cust_No)
              'Check for matching records
              DIM GLOBAL matching_records as N
              matching_records = a5_get_records_in_query( "broadcast-customers.set", "broadcast_raw->Date >= {10/01/2007} .AND. broadcast_raw->Date <= {10/02/2007} .AND. Customer->Ok_To_Bill=.t. .AND. str(Customer->Cust_No)=Var->which" )
              IF ( matching_records > 0 )
                  report.preview("B_Cast_Test2")
                  tbl.fetch_next()
              ELSE
                  END'
              END IF
          END WHILE
          Any ideas?

          Edited: Forgot to mention that the cust_no field is numeric which is why you see the str() in my query. The a5_get_records_in_query filter is exactly the same as the filter I have set in the report.
          Cheryl
          #1 Designs By Pagecrazy
          http://pagecrazy.com/

          Comment


            #6
            Re: save pdf report one record at a time

            In addition to my last post:

            The previous code works in a copy of the db that I made where I stripped down the records to allow for quicker processing during my testing. When I run the same code in the actual db that has tens of thousands of records, I get NO results.

            I have tried compacting the actual db and that did not seem to resolve the issue. However, when running the report without the which variable in the filter, I get the proper three records. So this is the same in both db's, the actual and the test db that I made.

            Thanks
            Cheryl
            #1 Designs By Pagecrazy
            http://pagecrazy.com/

            Comment


              #7
              Re: save pdf report one record at a time

              Good morning, Cheryl.

              I can't see the reason why the additional search term is causing the query to fail. Perhaps it's a timing issue since you DIM the 'which' variable each time through the loop?

              Since your script is stepping through all the customer records and running a set based query for each record I wonder if there might be ways to speed this up? You might try creating an inverted set and then query the inverted set to find the 3 reports you need. Each customer record could then be flagged or marked. Then you'd open the customer table, filter for flagged or marked records and step through the 3 records one at a time (generating a separate report for each), instead of stepping through all 10,000.

              An even better approach would query the set directly, and then step through the resulting query list one at a time. No inverted set would be needed. Here's an example illustrating the query technique I have in mind. The code is running against the vendors set in AlphaSports and is trying to find all the vendors in Massachusetts who have products with descriptions that begin with the letter "F".

              Code:
              stbl = table.open("vendors.set")
              query.order = ""
              query.options = "MT"
              filter = "trim(vendor->state_region) = 'MA' .and. left(product->description,1) = 'F'"
              query.filter = "crosslevel(" + quote(filter) + ")"
              sndx = stbl.query_create()
              ?sndx.records_get()
              = 1
              
              sndx.drop()
              stbl.close()
              It seems to me that once you run a query like this against your set, you could use the pointer to the filtered set (stbl in this example) to step through the records you want to print reports for.
              Last edited by Tom Cone Jr; 10-23-2007, 06:59 AM.

              Comment


                #8
                Re: save pdf report one record at a time

                Originally posted by Cheryl Lemire View Post
                WHILE .not.tbl.eof()
                should be

                WHILE .not. tbl.fetch_eof()

                tbl.eof() occurs when the last record is encountered so it is not processed
                tbl.fetch_eof() occurs when you attempt to fetch past the last record
                Last edited by Stan Mathews; 10-23-2007, 08:44 AM.
                There can be only one.

                Comment


                  #9
                  Re: save pdf report one record at a time

                  Hi Stan,

                  Thanks, that solved the problem with my not getting the last record. That will teach me to just copy/paste somebody's code without actually looking at it :)

                  I still have the second problem unfortunately. That being, the code now works great in my stripped down test db, but returns NOTHING in the actual db. I have rebuilt the indexes on all tables and packed the 3 tables involved in the set. I have also compacted the database with hopes this would resolve the live db issue. None of these things resolved the problem.

                  I am thinking that there is a record or two that would be causing the problem in the live db, but I have no idea what to even look for in the records.

                  Any ideas?

                  Hi Tom,

                  I was trying to play around with your idea as well but keep getting an incorrect data type error when substituting your code with my filter. I tried the following three filters below:

                  Code:
                  dim stbl as p
                  stbl = table.open("broadcast-customers.set")
                  query.order = ""
                  query.options = "MT"
                  filter = "(between(Date,ctod(\"10/01/2007\"),ctod(\"10/02/2007\")) )  .and. (Customer->Ok_to_bill = .t.  )"
                  query.filter = "crosslevel(" + quote(filter) + ")"
                  sndx = stbl.query_create()
                  ?sndx.records_get()
                  ERROR: Argument is incorrect data type
                  Code:
                  dim stbl as p
                  stbl = table.open("broadcast-customers.set")
                  query.order = ""
                  query.options = "MT"
                  filter = "broadcast_raw->Date >= {10/01/2007} .AND. broadcast_raw->Date <= {10/02/2007} .AND. Customer->Ok_To_Bill=.t."
                  query.filter = "crosslevel(" + quote(filter) + ")"
                  sndx = stbl.query_create()
                  ?sndx.records_get()
                  ERROR: Argument is incorrect data type
                  Code:
                  dim stbl as p
                  stbl = table.open("broadcast-customers.set")
                  query.order = ""
                  query.options = "MT"
                  filter = "(between(broadcast_raw->Date,ctod(\"10/01/2007\"),ctod(\"10/02/2007\")) )  .and. (Customer->Ok_to_bill = .t.  )"
                  query.filter = "crosslevel(" + quote(filter) + ")"
                  sndx = stbl.query_create()
                  ?sndx.records_get()
                  ERROR: Argument is incorrect data type
                  Thanks
                  Cheryl
                  #1 Designs By Pagecrazy
                  http://pagecrazy.com/

                  Comment


                    #10
                    Re: save pdf report one record at a time

                    I'm in total agreement with Tom let's say you establish a pointer to a queried group of records "QP"
                    QP.fetch_first()
                    while .not QP.fetch_eof()
                    found_one = QP.recno()
                    query.filter = "recno() = " + alltrim(str(found_one))
                    ::Report.SaveAs("your_name",PDF",query.filter
                    qp.fetch_next()
                    end while

                    Comment


                      #11
                      Re: save pdf report one record at a time

                      Cheryl, it's hard to debug your query filter expression without sample tables, but I would think something like this would work just fine

                      Code:
                      filter = "between(broadcast_raw->Date, {10/01/2007}, {10/02/2007})  .and. Customer->Ok_to_bill"
                      query.filter = "crosslevel(" + quote(filter) + ")"

                      Comment


                        #12
                        Re: save pdf report one record at a time

                        John, I too agree which is why I am playing with that code now.

                        Tom,

                        I am still awaiting permission from the owner to upload my stripped down version to provide a sample. As you know, my BIGGEST problem in Alpha has ALWAYS been with my FILTERS. You would think by now I would get it :(

                        The following does not work either:

                        Code:
                        stbl = table.open("broadcast-customers.set")
                        query.order = ""
                        query.options = "MT"
                        filter = "between(broadcast_raw->Date, {10/01/2007},{10/02/2007}) .AND. Customer->Ok_To_Bill=.t."
                        query.filter = "crosslevel(" + quote(filter) + ")"
                        sndx = stbl.query_create()
                        ?sndx.records_get()
                        ERROR: Argument is incorrect data type
                        Cheryl
                        #1 Designs By Pagecrazy
                        http://pagecrazy.com/

                        Comment


                          #13
                          Re: save pdf report one record at a time

                          Cheryl, how about the expression that I suggested? :)

                          Comment


                            #14
                            Re: save pdf report one record at a time

                            Hi Tom,

                            I did try the one you suggested and it did not work either. But you did not have any value for the ok_to_bill field which needs to be true. Sorry I did not post that, my bad :o

                            Code:
                            stbl = table.open("broadcast-customers.set")
                            query.order = ""
                            query.options = "MT"
                            filter = "between(broadcast_raw->Date, {10/01/2007}, {10/02/2007})  .and. Customer->Ok_to_bill"
                            query.filter = "crosslevel(" + quote(filter) + ")"
                            sndx = stbl.query_create()
                            ?sndx.records_get()
                            ERROR: Argument is incorrect data type
                            Cheryl
                            #1 Designs By Pagecrazy
                            http://pagecrazy.com/

                            Comment


                              #15
                              Re: save pdf report one record at a time

                              Cheryl, break the expression down and test each half separately. Use a script, don't work exclusively in the interactive editor unless you verify that all statements are active.

                              We don't need the app. We don't need the real data. We just need the tables and the specifications for the set.

                              Comment

                              Working...
                              X