Kbase 17465: Forcing Actuate to not split groups
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  10/05/1998 |
|
Forcing Actuate to not split groups
Objective: To make a group section begin at the top of a page
if it won't fit in the remaining space after the end of the
previous group.
Method: We will build this report from scratch against the
sports database.
In order to accomplish this objective we must first find the
size of the groups involved. Then we need to calculate the
space required for each group. Armed with this information
we can override a method of the group section to reject a
page if the new group will not fit in the remainder.
Step 1. Create a look ahead report.
We need to have to report sections in this report
application. The first will determine the size of all the
groups in the report. The second will generate the actual
report start with a new blank report design. Change the name
of the root object if you so desire. Drag a sequential
section into the root object from the structure palette.This
will allow us to have multiple report sections in the same
report application.
Drag a connection object from the data palette into the
sequential section. Select AcProgressConnection from the
dialog box. Right click on the connection and select
properties to establish the connection to the database, in
this case the sports progress sample database.
Note: If you need help with setting the connection
parameters, check KBase entry 16887.
Drag a report section from the structure palette into the
sequential section. Right click on the report section and
select rename. Change the name to LookAheadReport.
Drag a query data source from the data palette to the
LookAheadReport section. Rename it LookAheadQuerySource. Drag
a data row from the data palette into the data source and
rename it LookAheadDataRow.
Define the look ahead query. Select the LookAheadDataSource
and click the SQL button. Click OK on the resulting dialog
box. Since there is no security on the sports database we
don't need to enter a username and password. Open the sports
database in the db browser and drag the Order-Line table onto
the query editor. Drag the Order-num column onto the Columns
tab ( Make sure the Columns tab is forward before you do
this. ) Click on the box immediately below
Order-Line.Order-num on the Columns tab. Type the word temp
and hit the tab key. It should now show up as
<Computed>.temp. For the same row under the Formula column
enter COUNT(*). Click on the Group By tab. Click on the
Order-Line.Order-num column and click on the left arrow to
add it to the grouping. Click on the Order By tab. Click on
Order-Line.Order-num and click on the left arrow to sort by
the order number. Select File - Close to exit the query
editor.
Step 2. Create a Global Array.
Add a basic source file. Select File - New Basic File. Change
the file name if you wish. Enter the following code:
Declare
Global CountArray(206,2)
End Declare
This will create a global array which we will use to record
the size of the various groups. 206 represents the number of
orders in the database. ( There are actually 207 but the
arrays index begins at zero. )
Step 3. Save the group sizes from the Look Ahead Query.
Override the fetch method of LookAheadQuerySource to enter
the group information into our global array. Right click on
LookAheadQuerySource. Select properties. Click the methods
tab. Select Function Fetch() as AcDataRow. Click the Override
button. Change the function to look like this:
Function Fetch( ) As AcDataRow
Dim aRow As LookAheadDataRow
Dim gSize As Integer
Set aRow = Super::Fetch( )
If aRow Is Nothing Then
Exit Function
End If
CountArray(aRow.RowNumber-1, 0) =
+ aRow.OrderX2DLine_OrderX2Dnum
CountArray(aRow.RowNumber-1, 1) = aRow.temp
' The height of the Before, After and Content frames
' is 720 twips.
gSize = CountArray(aRow.RowNumber-1,1) * 720
gSize = gSize + 720
gSize = gSize + 720
CountArray(aRow.RowNumber-1, 2) = gSize
Set Fetch = aRow
End Function
This code will populate our array with the Order-num in the
first column, the number of lines for that order in the
second column, and the number of twips required for the
section in the third column. Click close to close the Method
Editor, Click close to close the Component Editor.
Step 4. Create a reusable group section.
Open the Project Browser. Select View - Browse - Project or
click the Project Browser helper button on the toolbar. Open
the .rod object by clicking the plus sign next to it. Drag a
group section from the Structure Palette into the Symbols
folder in the Project Browser. Don't bother entering a group
key, we don't need one yet, just click OK. Rename the new
group section PlacingGroupSection. Right click it. Select
properties. Click the variables tab. Click new. Name the new
variable gsCounter. Make its Type integer. Make its storage
Static. Make its visibility Public. Click the Methods tab.
Override the BuildFromRow function. Change the code to read
as follows:
Function BuildFromRow( row As AcDataRow ) As AcBuildStatus
Dim grpSummary As AcGroupSectionSummary
Dim aFlow As AcTopDownFlow
Dim spaceAvail As Integer
Dim aPageList As Retry::SimplePageList
' If no more rows are available then end the
' group. There must be at least one row in
' the group.
If row Is Nothing Then
Assert( RowCount > 0 )
BuildRowContent( Nothing )
BuildFromRow = RejectedRow
' If this is the first row, then record the
' group key, set the TOC entry, print the
' Before component, and add this row to the
' group.
ElseIf RowCount = 0 Then
If Not SummaryObject Is Nothing Then
Set grpSummary =
+ SummaryObject
Assert( IsSameKey
+ ( GetKey( row ),
+ grpSummary.KeyValue
+ ) )
End If
KeyValue = GetKey( row )
SetTocEntry( row )
Set CurrentRow = row
Set LastRowForContent = row
StartGroup( )
BuildRowContent( row )
BuildFromRow = ContinueBuilding
' This is the second or subsequent row. If
' it is in the same group then add it to this
' group.
ElseIf IsSameKey( GetKey( row ), KeyValue )
+ Then
BuildRowContent( row )
BuildFromRow = ContinueBuilding
' This row is the first one of the next
' group. End this group by printing its
' After component.
Else
'CountArray is a global array which
' is a 10*3 array. The last column of
' the array has the total twips
' required for that group section.
If CountArray(gsCounter,2) = 0 Then
Exit Function
End If
gsCounter = gsCounter + 1
Set aPageList = GetPageList()
Set aFlow =
+ aPageList.GetCurrentFlow()
' Calculate the space available on
' the current page.
spaceAvail =
+ aFlow.GetFreeSpace().Height
BuildRowContent( Nothing )
' If the available space is less than
' the space needed for the GS
' Eject the page.
If spaceAvail < CountArray
+ (gsCounter,2) Then
aPageList.EjectPage()
End If
BuildFromRow = RejectedRow
End If
End Function
Step 5. Create the Actual Report.
Drag a report section from the Structure Palette into the
sequential section. Rename it ActualReportSection.
Create an instance of PlacingGroupSection. Drag
PlacingGroupSection from the Project Browser onto
ActualReportSection. Select Create a subclass of the
component. Rename it ActualGroupSection. Assign it to
content. Drag a Query Data Source from the Data Palette to
the ActualReportSection. Click on the SQL button to define
the query. We will make a four table join with Customer,
Order, Order-Line, and Item. For columns we want
Customer.Name, Order.Order-num, Order.Order-Date,
Item.Item-Name, Order-Line.Price, Order-Line.Qty, and
Order-Line.Extended-Price. Add a Frame to the before section
of ActualGroupSection. Add labels and controls to display
Order Number, Customer Name, and Order Date. Add a frame to
the content section of ActualGroupSection. Add controls for
Item Name, Price, Quantity, and Extended Price. Add a frame
to the after section of ActualGroupSection. Place a currency
control with ValueExp SUM([Order-Line.Extended-Price]).
Change the Key property of ActualGroupSection to
[Order.Order-num].
Add a page list from the Page Layout palette to the root
object. Add a page to the page list. Add a flow to the page.
Run it. You will get a warning saying PlacingGroupSection
Key required. You can ignore this because we set the key in
the subclass ActualGroupSection.
Progress Software Technical Support Note # 17465