Wednesday, February 10, 2010

Create contacted string fields via Crystal reports for group and print detail records in group summary by using running total.

I was asked to write a report that calculates daily transportation cost.
The report should be grouped by Date, Driver.
The report should contain daily destinations combined together for every driver.
Actually the report should contact driver destinations together
The report format is as follow





DateDriverKmCostDestinations
05.02.10 01-John3302,000Town1-T2,T2-T3
05.02.10 02-Mohammed4503,500T3-T4,T4-T1
Total for 05.02.107805,500



However my transport file contains one record for every destination as follow:




DateDriverKmCostDestinations
05.02.10 01-John150800Town1-T2
05.02.10 01-John1801200T2-T3
05.02.10 02-Mohammed 2502000T3-T4
05.02.10 02-Mohammed 2001500T4-T1



In order to write this report I declared 2 summary Groups
1:- Date 2:-Driver
Every group has 2 totals fields Km and Cost.
In order to print just total I hide the details and groups headers (GH1,GH2,D).
However the problem is how to print the destinations .












Figure 1

In this report format I declared 2 groups 1:- Date 2:-Driver and every group has 2 totals fields Km and Cost.

In order to create contacted field that contain all destinations I have to

declare 3 calculated fields

1:-Flds that clear contacted field at the beginning of every group (@Desrest).For this purpose I will use whileprintingrecords function and reset the variablethat contains the contacted fields (S).

The field formula is as follow :



whileprintingrecords;

stringvar s;

s:='';


This field should be replaced at the beginning of the group.

2:-Running field that contact destinations.(@des1).

This field contact destinations fields.


Actually for every record contact destinations to previous contacted fields.

The destination fields is {HOVDST.HDTOPLC} and the group field is S.

Also we use whileprintingrecords method to group records.


whileprintingrecords;

stringvar s;

s:=s+trim({HOVDST.HDTOPLC})+" , ";


This filed should be replaced at report detail.

3:-Total fields to be displayed in the report (@desdsp).

We have to declare this field and also we will use whileprintingrecords method.

The field formula is as follow :

whileprintingrecords;

stringvar s;


This field should placed at driver group footer GF2 and it is very important to declare this field.


See also WhilePrintingRecords and WhileReadingRecords.