2. Getting started with DataFlex Reports
2.1 Creating a new report using the Report Creation Wizard
The Report Creation Wizard supports the steps that are needed to create the different parts of a report. The wizard is started from the ‘File’ option in the menu, followed by the ‘New’ and ‘Standard Report Wizard’ options. Another way to start the wizard is by using the Ctrl+ N shortcut.
Click on the button ‘Next’ to select tables to be used in the report.
2.1.1 Step 1: Select the tables
The DataFlex ‘Order Entry’ sample workspace is used for illustrating the use of the wizard. In section 9.1.1 (Available datasources) on page 51 an in depth explanation of datasources is
provided, specifically, the access to data via ODBC.
After selecting ‘DataFlex’ in the treeview and clicking the ‘Open’ button, select the filelist.cfg file that comes with the Order Entry workspace.
filelist.cfg is a DataFlex configuration file where the (metadata of) tables are stored. It is also possible to open DataFlex workspaces (.sws or .ws files) and individual tables without using filelist.cfg.
After selecting filelist.cfg, a ‘+’ symbol will appear next to the DataFlex option. Click on the ’+’
symbol to show all tables.
A table can be added by double-clicking on it. By using the buttons in the center of the dialog, tables can be added or removed from the report.
The buttons with a single > or < symbol can be used to add or remove a single table. The buttons with << and >> apply to all tables.
Select the tables ‘OrderDtl’, ‘OrderHea’, ‘Invt’
and ‘Customer’. Click on the button ‘Next’ to define the relationships between the tables.
2.1.2 Step 2: Defining relationships between tables
If we use the tables of the DataFlex Order Entry workspace, the relationships are automatically recognized by the DataFlex file-system.
The boxes in the links viewer can be dragged around or made smaller or larger.
Clicking "Auto-Arrange" reorganizes the display.
Read the section Relationships to create relationships manually.
Click on the button ‘Next’ to select the database fields used on the report.
2.1.3 Step 3: Select the fields
As with the previous selection dialog, the buttons in the middle section support adding or removing one field or all at once.
The fields will be arranged in sequence as sorted in the right panel. Change the order by selecting a field and clicking the buttons with the Up or Down arrow in the top right of the panel.
Click the ‘Browse Data’ button to see a sample of the actual data in the fields. Click the ‘Find Field’
button to search for a field by name.
Add the fields ‘OrderHea.Order_Number’, ’OrderDtl.Qty_Ordered’, ’Invt.Description’, ’OrderDtl.Price’,
’OrderDtl.Extended_Price’, ’OrderHea.Terms’, ’OrderHea.Ship_Via’, ’OrderHea.Customer_Number’,
’Customer.Name’, ’Customer.Address’, ’Customer.Zip’ and ‘Customer.City’. Click on the button ‘Next’ to group the data.
2.1.4 Step 4: Group the data
After selecting the database fields for the report the wizard continues with the option to group the data. In the case of the ‘Order Entry’ sample data, it makes sense to group by the order-header and order-detail data. An in-depth explanation of this can be found in section 10.6 (Group expert).
In order to create a new group, select the database field in the treeview on the left. In that tree view, find two options:
‘Report Objects’; showing the database fields that have been selected in the previous page of the wizard.
The second is an option for showing the datasource with all tables and fields.
If a database field to be grouped on was already selected for the report, it can be found in both options. The quickest way to select a field is to click on the ‘+’ symbol in front of the ‘Report Objects’ and click on the field.
When clicking the button with the ‘>‘ symbol in the center, the data will be grouped by that field.
The data in the report will be sorted in ascending order by default. In the bottom of the treeview on the right-hand side, this can be changed. For each field that is grouped on, the sort order can be set to ascending or descending.
The Group can easily be removed from the report by selecting it in the panel on the right-hand side and clicking the button with the ‘<‘ symbol.
Group by the fields ‘OrderHea.Customer_Number’ and ‘OrderHea.Order_Number’. Click on the button
‘Next’ to add sum and total fields.
2.1.5 Step 5: Sum values; totaling
Having defined the grouping, a dialog to select fields to total on is displayed.
Similar to the previous steps, the appropriate fields can be selected and moved to the other panel to be designated totals.
By selecting the type of sum in the combo box, several ways of totaling can be opted for. The default choice is ‘sum’.
Select the fields ‘OrderDtl.Qty_Ordered’,
‘OrderDtl.Price’ to add a sum on those fields.
Click on the button ‘Next’ to add data filters.
2.1.6 Step 6: Define data filters
The interface for selecting or removing fields is quite similar to the previous dialogs. The fields to filter on can be added to the column on the right.
Selecting the field in the right box will enable the operator and value dropdown box.
If you click the drop-down arrow of the value dropdown box you will get a sample set of data from the datasource. This is the same as the
‘browse data’ button underneath the 'Available Fields' list would produce. The difference is that you can pick a value from the list.
A more complete description of applying filtering criteria can be found in section 10.2 (Filter function).
Select the field ‘OrderHea.Customer_Number’ and pick ‘is equal to’ from the operator dropdown box. Enter
‘1’ in the Value box. Click on ‘Next’ for the next wizard page.
2.1.7 Step 7: Report options
After having defined the filtering criteria, the wizard will continue to the options screen.
The first combo box lets you select the page size for the report. Selecting a correct size here helps you in the further design of the report. The new report wizard divides the selected fields over the width of the paper, selecting the desired page size will give a different reduction in width if more fields are selected than can be presented on one row.
The work done to select the datasource and create the data-model can be something that is reusable for other reports in the future. By storing
this in the repository, it can be made immediately available at a later time. It helps to give it a meaningful name;
in this case ‘Order Information (DataFlex)’ would be right.
Click the 'Next' button to go to the Finish page. Here you can close the wizard by clicking on the ‘Finish’
button.
2.1.8 Step 8: Change the visual design of the report
After closing the wizard, the report is presented in the visual designer of DataFlex Reports as shown.
The visual designer consists of several parts. A report always has a minimum of the For each group, two extra sections are added to a report:
Group Header
Group Footer
Section Will be printed
Report Header First section of the report that gets printed
Page Header At the beginning of every page
Group Header At the beginning of each group
Details For each row
Group Footer At the end of each group
Page Footer At the bottom of every page
Report Footer Last section of the report that gets printed On the left-hand side of the visual designer the labels of the various sections are shown.
A preview window can be opened to see what the result of the report will look like. Activating the preview window can be done in several different ways:
Select the ‘Preview Report’ option in the menu under ‘View’
Click the ‘Print Preview’ icon in the button bar
Use the Ctrl +R shortcut
Click the ‘Refresh’ icon in the button bar to show and/or refresh the data
Use the F5 function key Hide the report header and footer
In the ‘Section Expert’ sections can be hidden so that they do not get printed. Hiding can be done always or conditionally based on the results of a function. Hover the mouse cursor over the label of the ‘Report Header’ in the left part of the section and click the right mouse button. A context menu shows the option to hide the section. The visual designer will now show the hidden section in a grey, shaded area. The same action can be repeated to hide the section of the ‘Report Footer’.
Moving and resizing of fields and objects
A field can be selected with the mouse, and dragged to the appropriate position. Resizing a field can be done by hovering the cursor over the border of the field. When the cursor shape changes, drag with the mouse to resize the field.
Fields can be selected via a lasso. Hold the Shift key down and drag with the mouse. Fields can also be moved by use of the cursor keys on the keyboard. Resizing can be done by keeping the Shift key pressed, while clicking a cursor
key. When multiple objects are selected with the lasso the order of selection depends on the order in the Report Explorer.
The way the cursor keys react depends on the settings of the grid options. Read more about this in section 4.2 (Options).
A number of fields in the ‘Details’ section needs to be moved to one of the ‘Header’ sections. Before starting to move anything, it makes sense to enlarge the ‘Header’
sections. Move the cursor over the bottom separator of the section. The cursor shape changes and the section can be enlarged by holding the left mouse button down, while dragging the separator down.
Multiple fields can be moved at once: select multiple fields with the mouse while keeping the Ctrl key pressed.
Then move all selected fields to the ‘Group Header #1’
section by dragging the mouse while holding down the left mouse button.
Replace ‘OrderHea.Order_Number’, ‘Orderhea.Terms’ and ‘Orderhea.Ship_Via’ to ‘Group Header #2’ and
‘OrderHea.Customer_Number’‘Customer.Name’, ‘Customer.Address’, ‘Customer.Zip’and ‘Customer.City’ to the ‘Page Header’.
Changing the appearance of fields
Looking at the report in the preview window you may want to change the formatting of certain fields.
The appearance can be changed via field properties. Numeric fields for example will show 2 decimals per default. Start the field properties dialog from the Format menu, choosing the 'Field Properties' menu item or by clicking the right mouse button on the field and then selecting the 'Field Properties' option.
Select object ‘Sum of OrderDtl.Qty_Ordered’
and open the properties dialog. On the last tab page, change the ‘Number format’ to
‘Custom Number’ to have zero decimals and remove the ‘Thousand separator’. Click the
‘OK’ button to save this setting.
Add lines and text objects
There are several ways to add a ‘Text Object’ to a report:
Select the ‘Text Object’ option from the Insert menu.
Click the icon on the toolbar for adding a ‘Text Object’.
Click the right mouse button in the section and choose the
'Insert' option in the context menu, followed by selecting the ‘Text Object’ option.
Draw a ‘Text Object’ in the ‘Page Header’ section. Right click on the ‘Text Object’ and select ‘Edit text’ from the popup menu. Type ‘Printed on’ into the box and click with the mouse outside the box. Move the Special field ‘Print Date and Time’ from the ‘Report Header’ right after the text object.
In the ‘Group Header #2’ and ‘Group Footer #2’ separator lines are added. Select the line object in the toolbar. The cursor changes into a pencil. Move the mouse to the position where the line should start and drag the mouse, while pressing the left mouse button, to the position where the line should end.
Each order on a new page
To place each order from the order entry system on a separate page we have to open the Section Expert. You will find this on the Report menu.
Select the ‘Group footer #2’ and check the box ‘New page after this section’. Click the
‘OK’ button to save this setting.
The preview now shows that each order will be printed on a new page.
2.1.9 Step 9: Storing a report
The screenshot on the right shows the preview of the report that was made using the wizard.
Save the report by choosing ‘Save’ from the File menu, and enter a logical name so that you can find the report again later. For example "orders with details.dr". The report can be stored anywhere on disk as the datasource location is stored in the report. The
reports folder in a DataFlex workspace (e.g. c:\DataFlex Examples\Order Entry\Reports) is the preferred location for report files. The integration wizard used to integrate reports in a DataFlex application will first look in that folder.