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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subreport grouping is incorrect

Status
Not open for further replies.

wleonard

Technical User
Jun 8, 2016
1
0
0
US
Hi-
I'm troubleshooting my first Crystal Reports report, working with a main
report that has a subreport that is intended to display all part
information for a given purchase order number. The subreport displays
the individual part records for the purchase order number, and the parts
are meant to be grouped by part ID, then date specified on the part,
then price.

For example, part ID 123 appears on a purchase order 4 times:
1. Date: 1/1/16, Price: 1.00
2. Date: 1/1/16, Price: 1.50
3. Date: 2/3/16, Price: 1.00
4. Date: 2/3/16, Price: 1.00

Using the example, the part should be displayed in 3 groups on the
purchase order, with items 3 and 4 grouped together. Each group should
be assigned an item number. Using the example, following is the desired
result:
Item 1 - 1/1/16 - 1.00
Item 2 - 1/1/16 - 1.50
Item 3 - 2/3/16 - 2.00

Following is what is happening:
Item 1 - 1/1/16, Price: 1.00
Item 2 - 1/1/16, Price: 1.50
Item 3 - 2/3/16, Price: 1.00
Item 4 - 2/3/16, Price: 1.00

The following code is specified in a formula on the main report:

Code:
whileprintingrecords;
stringvar    array polinepart;
datevar      array polinedate;
numbervar    array polineprice;
booleanvar supress := false;
local numbervar x := ubound(polinepart);
local numbervar i;

if not(onfirstrecord) and {PurchaseOrderDetail.PurchaseOrderID} = 

previous({PurchaseOrderDetail.PurchaseOrderID})
then
    (
        for i := 1 to x do
        (
            if 
                polinepart[i] = trim({PurchaseOrderDetail.PartID}) & 

'[]' & trim({PurchaseOrderDetail.PartRevisionID})
                and
                polinedate[i] = {PurchaseOrderDetail.Date}
                and
                polineprice[i] = {PurchaseOrderDetail.Price}
            then
            (
                supress := true;
                exit for;
            )
        )
    )
;

if not supress
then
    (
        redim preserve polinepart[x + 1];
        redim preserve polinedate[x + 1];
        redim preserve polineprice[x + 1];
        
        polinepart[x + 1] := trim({PurchaseOrderDetail.PartID}) & '[]' & 

trim({PurchaseOrderDetail.PartRevisionID});
        polinedate[x + 1] := date({PurchaseOrderDetail.Date});
        polineprice[x + 1] := {PurchaseOrderDetail.Price};
    )

The variable 'supress' is used to determine whether or not to display
the next sequential item number for the records returned from the
subreport. Following is the code behind the item number that appears on
the main report:

Code:
whileprintingrecords;
booleanvar supress;
numbervar itemnumber;

if not supress
then itemnumber := itemnumber + 1

The issue was "resolved" by suppressing the group header on the
subreport, which isn't desirable. The group header contains column
headers for the columns in the subreport, and all but 1 column are text
fields; the other column is a formula field. The group headers should
print once for each group.

As a test, I removed everything in the subreport's group header and
unchecked the Suppress switch on the group header, and again noticed
that the report wasn't grouping. If I suppress the group header, the
report appears to group correctly.

My assumption as to why this is happening is because the code to group
by item number isn't aware of the grouping that is specified on the
subreport. If I'm correct, my plan was to programmatically display group
headers on the subreport, but I don't know where to start to accomplish
this. In the current report setup, I can't see how to employ group
headers without redoing the logic in the report.

Am I on the right track with this? If not, can you tell me where I'm
falling down, or suggest a better approach to accomplish the goal?
Thank you for any input.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top