Print a report from a Queue (Clarion 5.5)

First step: open the sample-app and have a look at the GLOBAL EMBEDs

Here you find the include of the ABREPORT.INC.

ABREPORT.INC is located in your Clarion-LIBSRC-Folder. It contains several declarations of variables and classes which are used in the report.
Have you ever come across that ABREPORT.INC? Oh yes, you did. Each time you made a Report Procedure. It has been included automatically because Clarion knew you would need it then. You did not have to care.
In this sample we have a simple window and we do all this report now on our own, so we need to include that INC ourself.

PrintPreviewClass is one of the classes found in the ABREPORT.INC. We will make an object now which we will use for printing. This leads us to the

Second step: have a look at the LOCAL EMBEDs

At the beginning we initialize our Previewer:

MyPreviewQueue     PreviewQueue
MyPreviewer        PrintPreviewClass
Everything what we will print now gets written into the MyPreviewQueue. This queue has one record per page. Each page is made as a WMF-file. Its a sort of graphics format named Windows Meta Format. While the printing is in progress the application writes the pages into a temporary file (XP: C:\Documents and Settings\[username]\local settings\Temp) with the name CLA_some_number.TMP.

We have the object now, so its time for the

Third step: the miracle begins!

Insert a new piece of source and press Ctrl-F...
You get a selection of different structures to choose from. We decide for Report (Portrait) and suddenly the report formatter apears.
You do not have to do much at this moment, just close the report formatter and do not forget to save.

This is what we receive then:

Report  REPORT,AT(1000,2000,6000,7000),THOUS,PRE(RPT),FONT('Arial',10)
Detail   DETAIL
This is not much, but a complete report! Okay, I admit it is not very useful because we do not get to see anything on the paper when it is printed. We have to populate the detailband with data.

And there is something else: it would be printed immediately because we have not yet told the report that we wish to preview.

Now change
Report  REPORT,AT(1000,2000,6000,7000),THOUS,PRE(RPT),FONT('Arial',10)
Report  REPORT,AT(1000,2000,6000,7000),THOUS,PRE(RPT),FONT('Arial',10),
(NOTE: I inserted a linebreak before PREVIEW(MyPreviewQueue) for a better readability, it has to be in one line or you have to break the line with the pipe-symbol)

Lets do some make-up. Add this line between HEADER,AT..... and END
STRING('Printing a Queue'),AT(302,292,5250,208),USE(?String1),
(NOTE: I inserted a linebreak before TRN for a better readability)

Press Ctrl-F to check the result.

We are amost done! All we need now is to populate the Detailband with our data from the queue. In my sample I generate this queue at the start of the program. It is placed in a routine named GenerateQueue. This queue is a tree containing some countries and some cities.
I want to print that tree with its branch. It has only one level deep but you might enhance that.

Detail   DETAIL
We will LOOP through our DataQueue (DQ) and each time we have a record with
DQ:Level = 1
we know it is the country name - so we print it in the band RPT:DetailLevel1. When its DQ:Level = 2 it is a city which we print indented - we use print RPT:DetailLevel2. (Do't forget the prefix RPT!).

Printing the queue has its own routine named PrintQueue. It is run in the Accept at ?ButtonPrintReport.

If you want to prevent a pagebreak inside a country - Countryname and some cities appear on page 1 and the following cities are orphaned on page 2 - you put a BREAK around the two Detailbands. The break is triggered when a variable changes.
In our queue each record has DQ:Sortline in common.

break1 BREAK(DQ:Sortline)
DetailLevel1 ....
DetailLevel2 ....

You can add some more detailbands to be printed at certain conditions, i. e. one detail with a horizontal line as a separator and do some nested loops, calculations, There is a lot more possible and you are not limited to just one queue. You could also print from tables.

Add salt and pepper as you like....

Sample uploaded: 22. Feb. 2006

Download the sample source (Clarion 5.5) as ZIP.

Here you find some more samples