Professional Documents
Culture Documents
Sriyani De Silva Principal Support Analyst Oracle Asia Pacific Global Support Centre Melbourne - Australia
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 2 _____________________________________________________________________________________________________________
Contents
ORACLE REPORTS - SECRETS FOR DEVELOPERS........................................................................................1 INTRODUCTION...................................................................................................................................3 AUDIENCE..............................................................................................................................................3 OBJECTIVES ...........................................................................................................................................3 ACKNOWLEDGMENTS .............................................................................................................................3 1. HINTS, TIPS AND FUNDAMENTAL CONCEPTS. ........................................................................4 1.1 UPGRADING FROM A PREVIOUS RELEASE.............................................................................................4 1.1a) History of releases....................................................................................................................4 1.1b) Upgrade Path ...........................................................................................................................5 1.2 BUILDING OR MODIFYING A REPORT ...................................................................................................6 1.2a) Data Model ..............................................................................................................................6 1.2b) Layout Model .........................................................................................................................10 1.2c) How the Data Model and Layout Model are related................................................................15 1.3 RUNNING A REPORT ........................................................................................................................16 1.3a) Basic requirements .................................................................................................................16 1.3b) Destination types - where should the output go? .....................................................................16 1.3c) Different ways of calling a report ...........................................................................................17 1.3d) User input at runtime - the Parameter Form ...........................................................................17 1.4 PRINTING FROM ORACLE REPORTS ..................................................................................................18 1.5 WEB REPORTS AND THE REPORTS SERVER .......................................................................................19 1.6 USING ORACLE REPORTS WITH OTHER PRODUCTS............................................................................20 2. TROUBLESHOOTING....................................................................................................................22 2.1 DEBUGGING ...................................................................................................................................22 2.2 SOME COMMON ERRORS AND HOW TO RESOLVE THEM .......................................................................23 CONCLUSION......................................................................................................................................24
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 3 _____________________________________________________________________________________________________________
Introduction
Audience
This paper is written for application developers who have had some basic technical experience with Oracle Reports as a reporting tool.
Objectives
The aim is to share with you, in a concise and simple format, fundamental concepts about the various aspects of Oracle Reports, starting from building or modifying a report, through to troubleshooting methods for quick resolution of errors.
Acknowledgments
I extend my appreciation and thanks to the staff at Oracle, both in Melbourne and Auckland, whom I have worked with since 1994. The many customers I have worked with, for their technical input and diversity of thought. To the Oracle Education staff for the numerous opportunities they offered me to teach Oracle Reports, and to my family and friends, for their encouragement and support.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 4 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 5 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 6 _____________________________________________________________________________________________________________
This example may seem rather trivial, but it forms the basic building block for more complex reports.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 7 _____________________________________________________________________________________________________________
The same concept can be extended to multiple queries. The example above is a straight SELECT * FROM EMP, however another way of listing all employees by department, is to select all the departments in one query, all the employees in another query, and then link the two queries using their primary and foreign keys.
Sort Order
The group heirarchy also determines the sort order of the data. The ORDER BY clause in the SELECT statement can only ever override the LAST group in any given query. So the sorting of records is first determined by the sequence of the groups within a query, then the sequence of the columns within a group, and finally, the last group in a query can be sorted by the ORDER BY clause. Note that to change the sort order, groups and columns can be re-positioned by drag and drop, within the Data Model window, not in the Object Navigator.
Column Aliasing
When writing queries in Oracle Reports, always specify column aliases to keep column names clear and readable. This is extremely useful when future modifications are required to the Data Model. The reason is that the Layout model is driven by the Data model, so any changes in the Data model will cascade down to the Layout model. Using column aliases, protects the Layout model (to a certain degree), from such changes.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 8 _____________________________________________________________________________________________________________
If you want to get the total number of employees in a department, the sum must reset at department level, so the SUMMARY column must be created in the department group. If you want to calculate the commission in dollars for each employee, that is salary times commission percentage, the FORMULA column must be created in the same group as the salary and commission percentage columns, that is the employee group. If you want to create a PLACEHOLDER column, or container into which values are assigned, place it in the same group as the formula column which is performing the assignment, or place it at a higher level. When creating these types of columns, always use the default naming convention. This can save precious hours later if and when the report needs to be modified. For example: Summary column names are prefixed by CS_ Formula column names are prefixed by CF_ Placeholder columns names are prefixed by CP_ If possible try to calculate summary functions and formulae directly in the database, this will be more efficient compared to querying all the records from the server to the client and performing the calculations on the client side.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 9 _____________________________________________________________________________________________________________
System Variables
These are default variables such as Current Date or Physical Page Number, a list of which is found in the Source property of a field.
Global Variables
These can be very useful when you need to assign values to variables in mid-flight, for example in the Between Pages Trigger or in a format trigger. To create a global variable, simply create a local PL/SQL program unit of type Package Spec, then declare a variable in it with the appropriate datatype. A Package Body is not required. To assign values to this global variable, use the following syntax: package_spec_name.variable_name. For example if the package spec is called Global and the variable declared in it is called v_Count, then in the report trigger or format trigger, we can assign a value to it as follows: global.v_count := 10;
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 10 _____________________________________________________________________________________________________________
Visualizing this three-dimensionally, the same diagram will look like this.
Each layer is known as a frequency and is closely linked to the heirarchical structure of the groups and columns in the Data Model. This link is discussed later in this paper.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 11 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 12 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 13 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 14 _____________________________________________________________________________________________________________
Page Breaks
Always use the Maximum Records per Page property on the appropriate Repeating Frame, to control page breaks. For example, if every new department must begin on a new page, go to the Department repeating frame and set the Maximum Records per Page property to 1. Alternatively, if there is a requirement such as: If a new department begins half way down the page and all the employees of that department cannot fit on the same page, then move the entire department to the start of the next page. .. this is achieved by setting the Page Protect property on the department frame.
Conditional Printing
This functionality has been greatly enhanced in recent versions of Reports. The Conditional Formatting property on a layout object allows you to choose the required conditions and format styles without the need for any code. However a simple but powerful block of code to remember is: IF <CONDITION> THEN RETURN (TRUE); ELSE RETURN(FALSE); END IF; This code can be used in the format trigger of ANY layout object, which gives you endless possibilities of how it can be applied. For example, if you wish to suppress the salary field in an employee listing, unless the person running the report is a manager, and assuming p_user_type is a custom variable that stores the user information, then the following code in the format trigger of the salary field, will solve the problem: IF p_user_type <> Manager THEN RETURN (TRUE); ELSE RETURN(FALSE); END IF;
Page Numbering
The page number can be obtained simply by selecting it from the Source property of a field. However to reference a page number programmatically, use the following syntax: DECLARE x NUMBER; BEGIN srw.get_page_num(x); srw.message(0, This is the current page number ||to_char(x)); END;
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 15 _____________________________________________________________________________________________________________
1.2c) How the Data Model and Layout Model are related
The table below shows how the Data Model and Layout Model are so closely linked. Data Model Group Column Layout Model Repeating Frame Field
Therefore, every Repeating Frame must relate back to one Group. Every Field in the layout, must relate back to a Column in the Data Model. This link is established by the Source property of a Repeating Frame or Field. However every Group or Column does not necessarily have to relate to an object in the layout, so it is a one-way dependency. Once the layout is created based on say the department and employee Groups, Columns in the department group will appear as fields in the department repeating frame. Columns in the employee group, will appear as fields in the employee repeating frame. If there are 4 department records returned, the department repeating frame will repeat 4 times. Since the employee group is structured as a child of the department group, the employee repeating frame will be inside, the department repeating frame. The Repeating Frames and Fields get their names from the Groups and Columns in the Data Model. That is why it is important to use meaningful names and column aliases in the Data Model, before the Layout is created. The style of the report layout is also governed by the structure of the groups in the Data Model. For example, for a Tabular style report, one group in the Data Model is sufficient. For a Master-Detail, Group Left or Group Above style report, there must be at least two groups present in the Data Model. For a Matrix style report, there must be at least three groups as well as a cross-product group, and so on. Therefore the Data Model and Layout Model work hand in hand.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 16 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 17 _____________________________________________________________________________________________________________
4.
5.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 18 _____________________________________________________________________________________________________________
When running a report to the printer, this is the path that is followed: Oracle Reports > Printer Driver > Printer Queue > Physical Printer + + + .rdf/.rep file Operating System Network So if for some reason the output is not appearing at the Printer, then follow the path one step at a time, to narrow down the location of the problem. Here are some hints: To check that Oracle Reports is using the Printer Driver correctly: 1. Run a report to file. 2. Open the output file in a text editor such as WordPad. 3. The header of the output file should be readable and have information about the Printer Driver used. To check that the Printer Driver is going to the Printer Queue: 1. Go to the properties of the Printer Driver. 2. Check that the Printer Queue is shown correctly. To check that the Printer Queue is printing to the Printer correctly: 1. Create a dummy text file. 2. Send it to the printer, directly from the operating system. eg: Right-mouse>Print in Windows Explorer, or lp -d<printerqueue> filename on UNIX. 3. If the above step works then the Report should also print.
One more point to note is that if the Report is built as a GUI or Bitmap report ie. With MODE=<default>, but is later run in a Character mode environment, and if the output is still required in Bitmap format, then: Run the report from the command line with BATCH=Yes and MODE=Bitmap.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 19 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 20 _____________________________________________________________________________________________________________
Oracle Graphics
This is another relation to Oracle Reports. Simply create a Chart Object in the reports layout and reference a .ogd or .ogr file generated from Oracle Graphics. At runtime, the Graphics Batch process will start in the background, run the graph, and display it on the report. In Reports 3.0+, there is a Chart Wizard, which will step through the creation of a Graph from within Reports itself.
Oracle Forms
The most common integration with Forms is when the RUN_PRODUCT, RUN_REPORT_OBJECT, WEB.SHOW_DOCUMENT or HOST command is used to call a report from a form. Note that if required, an entire parameter list can be passed from Forms to Reports.
Microsoft Excel
A Character mode report that saves its output to a file with an extension of .csv, will automatically be recognizable by MS Excel. For example, a hyperlink on a Web Report can point to a .csv file, which will automatically startup MS Excel and display the text (assuming the MIME types have been setup correctly in the Web Browser).
Query Builder
Some may recall that Query Builder used to be called Browser in the past and was closely linked with Discoverer/2000. However, Query Builder is now bundled with Developer as a standalone product as well as subcomponent of Reports. A button in the Data Model Wizard starts up Query Builder and provides a graphical representation of a Query, minimizing the need for typing SELECT statements.
Oracle Designer
This suite of products is also very closely linked with Oracle Developer in that, Oracle Designer has the ability to generate Forms and Reports. Oracle Developer is then used to customize these files.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 21 _____________________________________________________________________________________________________________
WebDB
In the next release of Reports, that is Reports 6i, it is possible to tightly integrate Web Reports with WebDB. Here is an excerpt from a paper written by Stacey London of Oracle entitled New Features in Oracle Reports 6i. Oracle WebDB is a powerful HTML-based publishing and development solution for managing and publishing dynamic content on the Web. With Oracle WebDB, you can create powerful web sites, securely organize Web content, and seamlessly publish dynamic data. All that is needed is a Web browser, making it easily accessible and manageable, from site creation to administration tasks. All WebDB content is stored in a repository in an Oracle database and utilizes the Oracle Web Developers Toolkit to display HTML in your browser. WebDB 2.2 has been tightly integrated with Oracle Reports to create a robust and secure reporting environment. New Oracle Reports security wizards have been added to WebDB, permitting an authorized administrator to control access to Report Definition Files, Reports Servers, printers, output formats, report parameters and accessibility to the reporting environment overall. The Site Building capabilities of WebDB provide an easy mechanism with which to publish Oracle Reports for end user access via the Web.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 22 _____________________________________________________________________________________________________________
2. Troubleshooting
2.1 Debugging
When attempting to fix a problem, look for the root of the problem first, before looking for a solution. Try to narrow down the scope by eliminating as many variables as possible. It helps to be aware of the process which is followed when a report is run. The report is called from another product or the command line. If it is called from another product, eliminate that variable by calling it from the command line. The parameter form may or may not be displayed. If the problem relates to passing of runtime variables, then display the parameter form, this will show you whether the parameter values have reached the report successfully. Note that there are several Report level triggers that fire in any report. The Before Parameter Form Trigger fires Parameter Form The After Parameter Form Trigger fires Queries are parsed The Before Report Trigger fires Data is fetched and the first page is formatted If there is more than one page, the Between Pages Trigger fires between the pages The After Report Trigger fires after the report is complete. In each of these triggers, it is possible to display a message, which can be used to check how far the report is executing or what the status of a flag or variable is. The syntax for the message command in Reports is: SRW.MESSAGE(N, TEXTor VARCHAR2 variable); If there are ORA errors resulting from DML or DDL statements to the database, run a SQL*Net client side trace to find out what statements are being sent. A client side SQL*Net trace is obtained by setting TRACE_LEVEL_CLIENT, TRACE_DIRECTORY_CLIENT and TRACE_FILE_CLIENT in the sqlnet.ora file. If the report runs successfully, but does not format or print correctly see section 1.4 above on Printing issues. If it appears that the Report is corrupt, for example it cannot be opened or edited, then try the following file conversion using the Reports Convert utility. RDF (binary/executable) > REX (text) > RDF (binary/executable). This often eliminates any possible corruptions in the RDF file. During design time: If there are errors in the SQL Queries, try running the Query from SQL*Plus first. Ensure that the query returns the correct data. Then copy the query to Reports. If there are errors in the Layout Editor, then re-visit the Mountain Range principle to ensure the objects are layered correctly.
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 23 _____________________________________________________________________________________________________________
Oracle Reports - Secrets for Developers October 19, 1999 by Sriyani De Silva Page 24 _____________________________________________________________________________________________________________
Conclusion
It is my hope that this paper has achieved its objective, by providing a clearer understanding of what Oracle Reports is all about and how best to work with it as a reporting tool.