Anda di halaman 1dari 36

Crystal Report

Crystal report Feature document

Api Maintenance System

Index:
Index:.........................................................................................................................................................2 Insert Filter.................................................................................................................................................3 Translations of fields.................................................................................................................................3 Change color on every sec line..................................................................................................................3 Second time..........................................................................................................................................4 Suppress data from being showed:............................................................................................................4 IsNull command for date fields.................................................................................................................5 Count unit in a group.................................................................................................................................5 Selection of parameter..............................................................................................................................6 Crystal Report Variable Types................................................................................................................10 IF:.............................................................................................................................................................11 Select a part of a text:..............................................................................................................................11 Inset different color on lines:...................................................................................................................11 Chart.........................................................................................................................................................12 Useful Crystal Report Functions.............................................................................................................14 Change database connection:..................................................................................................................17 Tree search for Maintenance object........................................................................................................20 Full tree search for Position.....................................................................................................................26 Version number.......................................................................................................................................35

23. december 2008

page 2 of36

Crystal report Feature document

Api Maintenance System

Insert Filter
Is like *-112-118* All record contain -112-118

Translations of fields
A custom filed must be created first. Insert the formula in the formula workshop EG. (this is the translation in Danish) select {Work_history.job_type} case 'P' : "Forbyggende" case 'C' : "Afhjlpende planlagt" case 'U' : "Afhjlpende Uplanlagt" case 'B' : "kondition" case 'I' : "inspektion" case 'O' : "Andre"

Change color on every sec line.

Workshop: if Remainder (RecordNumber,2) <> 0 then Color (239, 235, 222) else crNoColor

23. december 2008

page 3 of36

Crystal report Feature document

Api Maintenance System

Second time
Define a X-1 field. Workshop: E.G. time ({Log_Work_history.Log-time}\3600, (({Log_Work_history.Log-time} mod 3600)\60),0)

Suppress data from being showed:


Workshop: (TID and Dato is used because these data change over time and the report need to be validated on the first entry.) The TID and `DATO is put into the report Header or groupe header and set suppressed.

In the workshop of the field is put the command; Shared datetimeVar Dato; dato := {Log_Work_history.Log-date}; On the Group section use the section expert:

23. december 2008

page 4 of36

Crystal report Feature document

Api Maintenance System

Workshop: Shared numbervar TID; Shared datetimevar DATO; if DATO < {Transactions_WS.Create_date} then true else if DATO = {Transactions_WS.Create_date} AND TID < {Transactions_WS.Create_time} then true Else False

IsNull command for date fields


If the report must filter on date field that is empthy isnull (field) where the field is selected from the table e.g {purchase_order.expected_delivery} <= today or (isnull ({purchase_order.expected_delivery}))

Count unit in a group


Insert a summery select distinct count.

The summery will be shown in the group footer. Create textbox next to the group and enter the text 23. december 2008 page 5 of36

Crystal report Feature document

Api Maintenance System

Then select the summery and drag it into the textbox.

Selection of parameter
Create the Parameters in the Field Explore:

EG. Parameter:

23. december 2008

page 6 of36

Crystal report Feature document

Api Maintenance System

Start the Fomula Workshop and enter the criteria of parameters: Etc: {work_history.start_date} > {?Start}and {work_history.start_date} < {?End}

23. december 2008

page 7 of36

Crystal report Feature document

Api Maintenance System

Running the report will now show the window for the parameter.

23. december 2008

page 8 of36

Crystal report Feature document

Api Maintenance System

Variabler
Dim var As dataype; Global StringVar y; A variable's scope determines which formulas have access to that variable. You can set the scope so that a variable can only be used within the formula it's declared in, or you can make it available to the rest of the report. There are three operators that are used to declare scope:

Local/Dim:
The variable can only be seen within the current formula. The variable is private to that formula and can't be used anywhere else in the report. This is the default scope if you don't specify it.

Global:
The variable can be seen within any formula inside the same report. Sub-reports do not have access to the variable.

Shared:
Similar to Global, but the variable can also be seen within sub-reports alle elemet in the report can use a shared variable. You can also omit the Global keyword which creates a Global variable by default:
StringVar y; // Same as: Global StringVar y;

Dim HireDate As Date Shared AffiliateCities() As String


//Formula C Global NumberVar x; x := 10; //Formula D //Call the function WhileReadingRecords WhileReadingRecords; Global NumberVar x; x := x + 1

If Formula C is placed in the Report Header and then Formula D is placed in a detail section, Formula C will be evaluated before Formula D. Formula C will be evaluated once and then Formula D will be evaluated for each record appearing in the detail section. Formula C returns 10. For the first detail record, Formula D returns 11. This is because the value 10 of x is retained from when it was set by Formula C. Formula D then adds 1 to this value, setting x to 11 and then returns 11. For the second detail record, formula D return 12, adding 1 to the previously retained value of x which was 11. This process continues for the remaining detail records. The call to WhileReadingRecords tells Crystal Reports to re-evaluate Formula D as it reads in each record of the report. Otherwise, since the formula does not contain any database fields, the program evaluates it only once before reading the records from the database. The formula will then return the value 11 instead of 11, 12, 13, ... as the successive records are processed.

23. december 2008

page 9 of36

Crystal report Feature document

Api Maintenance System

If the expression x := x + 1 is replaced by x := x + {Orders Detail.Quantity}, you create the effect of a running total based on {Orders Detail.Quantity}, although it is one starting at 10 rather than 0 because of Formula C. In this case, you can omit the call to WhileReadingRecords, since it will automatically occur because the formula contains a database field

Crystal Report Variable Types


BooleanVar NumberVar CurrencyVar DateVar TimeVar DateTimeVar StringVar BooleanVar range NumberVar range CurrencyVar range DateVar range TimeVar range DateTimeVar range StringVar range BooleanVar array NumberVar array CurrencyVar array DateVar array TimeVar array DateTimeVar array StringVar array BooleanVar range array NumberVar range array CurrencyVar range array DateVar range array TimeVar range array DateTimeVar range array StringVar range array EKS: In the main report WhilePrintingRecords; Shared numberVar myTotal1; 23. december 2008 page 10 of36

Crystal report Feature document

Api Maintenance System

myTotal1 in the subreport WhilePrintingRecords; Shared numberVar myTotal1 := 0; Shared numberVar myTotal1 := Sum({tt_sub_ac.budget_costs})

IF:
The If command: IF x then Y else Z EX. Enter a specific PO or return all if {?Purchase order key} > "" then {Purchase_order.PO_key} = {?Purchase order key} and {Purchase_order_line.Purchase_status} = "O" else {Purchase_order_line.Purchase_status} = "O" and {Purchase_order.PO_key} > "-"

Select a part of a text:


Account from 1 char to where - exist (-1). Return a part of a sting from the beginning to first time the string has a -. Mid ({Spare_part.Account_key}, 1,(InStr({Spare_part.Account_key},"-")-1))

Inset different color on lines:

Background cooler on the section: if Remainder (RecordNumber,2) <> 0 and count({history_data.rep_key})>0 then Color (239, 235, 222) else crNoColor

23. december 2008

page 11 of36

Crystal report Feature document

Api Maintenance System

Chart
If haveing a distinct count in the report you can insert a chart directly in the footer section. The char will automatict select the data

By selecting the char it is possible to change option just as in an EXEL CHAR

23. december 2008

page 12 of36

Crystal report Feature document

Api Maintenance System

Cross-Tab Insert cross-tab in the header-section or the footer-section

Drag the field that you want to view in the matrix. E.g MO WorkSupplier Transaction amount Down Right Matrix

Group sort expert can be used. ( right click in the empty field top left corner)

23. december 2008

page 13 of36

Crystal report Feature document

Api Maintenance System

Useful Crystal Report Functions


Truncate(x, #places) Returns a number with extra decimal places removed. Truncate(123.45678, 2) returns 123.45 Round(x, #places) Returns a number rounded to the number of decimal places. Round(123.45678, 2) returns 123.46 Sum(field) Get a sum for the whole report ie a grand total Sum(field, conditionfield) Get a sum for a particular group of values Average(field) Get an average for the whole report Average(field, conditionfield) Get an average for a particular group of values Maximum(field) Get the maximum value of the field for the whole report Maximum(field, conditionfield) Get the maximum value in a particular group Minimum(field) Get the minimum value of the field for the whole report Minimum(field, conditionfield) Get the minimum value in a particular group Count(field) Count the number of records for the whole report Count(field, conditionfield) Count the number of records in a particular group Length(field) Get the number of characters in a character string. Trim(field) Return the string field, without leading/trailing spaces TrimLeft(field) Return the string field, without leading spaces 23. december 2008 page 14 of36

Crystal report Feature document

Api Maintenance System

TrimRight(field) Return the string field, without trailing spaces UpperCase(field) Return the string field converted to upper case LowerCase(field) Return the string field converted to lower case ProperCase(field) Return the string field converted to proper case (eg Title Case) StrReverse(field) Return the string field, with all characters reversed (ie last character first) NumericText(field) Returns true if the string is completely numeric (eg 123.45). Returns false if any part of the string is non-numeric (eg 124.23A) ToNumber(field) Converts the field from a string/currency/boolean and returns as a number ToText(field) Convert the field from a number/currency/boolean to a string ToText(field, places) Convert a number/currency field to a string with a set number of decimal places ToText(field, places, thousands) Convert a number/currency field to a string with a set number of decimal places and a character to represent the thousands character ToWords(field) Convert the numeric field to a word representation eg 123 becomes one hundred twenty-three ReplicateString(string, number) Returns the specified string the number of times ReplicateString(xyz, 3) returns xyzxyzxyz Space(number) Returns a number of blank spaces eg Space(10) returns InStr(string1, string2) Returns the position of string2, inside string1 InStr(abcdefgh, de) returns 4 Mid(string, start, length) Returns a part of a string, from start for a certain number of characters. Mid(abcdefgh, 4, 3) returns def

23. december 2008

page 15 of36

Crystal report Feature document

Api Maintenance System

Left(string, length) Returns the left part of a string to a certain number of characters Right(string, length) Returns the right part of a string to a certain number of characters Chr(number) Returns the ASCII character for the number eg chr(65) returns A Replace(inputString, findString, replaceString) Replaces the part of inputString that matches findString, with replaceString. Replace(abcdefgh, de, xy) returns abcxyfgh Date(YYYY, MM, DD) Returns a Date value for the year, month and day numbers passed in. Year(datetime) Returns the year part of a date or datetime value Month(datetime) Returns the month part of a date or datetime value Day(datetime) Returns the day part of a date or datetime value DateAdd(intervalType, number, datetime) Adds the number of intervals (day, month etc) to the datetime and returns the new date. DateAdd(yyyy, 3, CurrentDate) returns the current date plus three years (eg 30/06/2009) DateDiff(intervalType, startdatetime, enddatetime) Returns the difference between the two dates for the chosen interval. DateDiff(d, {@StartOfYear}, CurrentDate) returns the number of days between 01/01/2006 and 30/06/2006 ie 180) MakeArray(x, y, z, .) Returns an array containing all the items entered MakeArray(abc, 123, xyz) would return an array with three items in it (one for each string). Switch(expression1, value1, expression2, value2, ) Evaluates each expression in turn (must be a boolean result), when the criteria for one is satisfied (is true) it returns thevalue which is associated. Switch({Community.Gender} = M, Male, {Community.Gender} = F, Female, True, Unknown). Note the last expression is just True, this is a default value for when the other expressions are not satisfied. IIF(expression, truepart, falsePart) Evaluates the expression (must be boolean result), if true the truepart is returned, otherwise the falsepart is returned. IIF({@Amount} > 0,Good, Bad) Previous(field) 23. december 2008 page 16 of36

Crystal report Feature document

Api Maintenance System

Returns the value of the field, from the prior dataset record Next(field) Returns the value of the field, from the next dataset record IsNull(field) Returns true if the field value is null, otherwise false. PageNumber Returns the current page number of the report TotalPageCount Returns the total number of pages in the report PageNofM Returns eg Page 5 of 10 OnFirstRecord Returns true if the current record is the first one of the dataset OnLastRecord Returns true if the current record is the last one of the dataset ReportTitle Returns the title of the report as entered in File Summary Info Title Useful Crystal Report Formula snippets {vStudents.Surname} + + {vStudents.Preferred} + + ToText({vStudents.ID}, 0, ) - Returns a single string containing the surname, preferred name and ID in the correct order, which can be used for grouping instead of creating a separate group for each field.

Change database connection:


To change the connection in the crystal report. Start the report: e.g. "Hal-pr" report. In the menu "DATABASE" / "SET DATA SOURCE LOCATION" The top windows show the current connection The lower window show the new connection Select the ODBC for the database you want to connect to Select UPDATE

23. december 2008

page 17 of36

Crystal report Feature document

Api Maintenance System

23. december 2008

page 18 of36

Crystal report Feature document

Api Maintenance System

Select Close

23. december 2008

page 19 of36

Crystal report Feature document

Api Maintenance System

Tree search for Maintenance object


How to create a report with tree structure. In crystal report it is possible to create a part of a tree structure. In this example the report will show all transaction for a position and all MO below The crystal report use a SQL script to create a new table with the tree of data. Create the report first.

23. december 2008

page 20 of36

Crystal report Feature document

Api Maintenance System

Select Add command and dobble click.

Create the parameter for the tree start. E.G. position

23. december 2008

page 21 of36

Crystal report Feature document

Api Maintenance System

Insert the following command: with sampleorgchart (MO_key,MO_name, POS_root, Root_MO_key, OrgLevel ) as ( SELECT a.mo_key, a.mo_name, a.POS_key, a.root_mo_key, 0 FROM dbo.maintenance_object a WHERE a.POS_key = '' UNION ALL SELECT a.mo_key, a.mo_name, a.POS_key,a.root_mo_key, b.OrgLevel+1 FROM dbo.maintenance_object a INNER JOIN sampleorgchart b ON a.root_mo_key = b.MO_key ) SELECT * FROM sampleorgchart GO Set your curser between Double click on the parameter to the right

23. december 2008

page 22 of36

Crystal report Feature document

Api Maintenance System

The report will now ask for the value...

Create the join between the new table and the table you want data from

23. december 2008

page 23 of36

Crystal report Feature document

Api Maintenance System

The report should be ready now..

Create the report as use sally.

23. december 2008

page 24 of36

Crystal report Feature document

Api Maintenance System

The report will not take data from the position but from all maintenance object below..

23. december 2008

page 25 of36

Crystal report Feature document

Api Maintenance System

Full tree search for Position


How to create a report with full tree structure from a position In crystal report it is possible to create a part of a tree structure. In this example the report will show all transaction for a position (Sydney) and all Pos and MO below The crystal report use a SQL script to create a new table with the tree of data. Create the report first.

23. december 2008

page 26 of36

Crystal report Feature document

Api Maintenance System

Select Add command and dobble click.

Create the parameter for the tree start. E.G. position

23. december 2008

page 27 of36

Crystal report Feature document

Api Maintenance System

The SQL command is combined by tree step Delete table full_tree Create temp table full_tree Create the tree (Recusision)

23. december 2008

page 28 of36

Crystal report Feature document

Api Maintenance System

drop table Full_tree SELECT position.pos_key, position.root_pos_key, maintenance_object.mo_key, maintenance_object.root_mo_key, maintenance_object.pos_key as POS_key_MO

INTO Full_tree FROM position FULL OUTER JOIN dbo.maintenance_object ON position.pos_key = maintenance_object.pos_key;

with sampleorgchart (POS_key, root_pos_key, MO_key, Root_MO_key, POS_key_MO, OrgLevel ) as ( SELECT a.POS_key, a.root_pos_key, a.mo_key, a.root_mo_key, a.POS_key_MO, 0 FROM dbo.Full_tree a WHERE a.POS_key = '' UNION ALL SELECT a.POS_key, a.root_pos_key, a.mo_key, a.root_mo_key, a.POS_key_MO, b.OrgLevel+1 FROM dbo.Full_tree a INNER JOIN sampleorgchart b ON (a.root_mo_key = b.MO_key or a.root_pos_key = b.POS_key) --INNER JOIN sampleorgchart b ON a.Root_pos_key = b.POS_key --INNER JOIN sampleorgchart b ON a.root_pos_key = b.POS_key ) SELECT * FROM sampleorgchart

23. december 2008

page 29 of36

Crystal report Feature document

Api Maintenance System

Set the curser in between the and double click on the parameter to the rigth. It is very important that the = {?xxx}

Select OK. (The command must have a valid data to begin with othervise it will give an error..) 23. december 2008 page 30 of36

Crystal report Feature document

Api Maintenance System

After the command is created it is important to create the Join between the new table and the selected table (normal procedure).

23. december 2008

page 31 of36

Crystal report Feature document

Api Maintenance System

23. december 2008

page 32 of36

Crystal report Feature document

Api Maintenance System

This is the result of example from the database..

If the parameter should be connected to the list of data in the database it can be don be adding the table and not select a join to it. Then the table can be used to connect to the parameter in the command:

23. december 2008

page 33 of36

Crystal report Feature document

Api Maintenance System

23. december 2008

page 34 of36

Crystal report Feature document

Api Maintenance System

Version number
Crystal report 11 Release I

Crystal report 11 Release II

23. december 2008

page 35 of36

Crystal report Feature document

Api Maintenance System

23. december 2008

page 36 of36

Anda mungkin juga menyukai