SQR User’s Guide

Version 4.3.2

1080 Marsh Road, Menlo Park, California 94025

SQR User’s Guide, Version 4.3.2 Part Number: 06-M-4302-R01

Copyright © 1998 SQRIB E T ec hnologies All rights reserved. Printed in the USA.

This publication pertains to SQR 4.3.2 and to any subsequent release until otherwise indicated in new editions or technical notes. Information in this document is subject to change without notice. The software described herein is furnished under a license agreement, and it may be used or copied only in accordance with the terms of the agreement.

LIMITED WARRANTY THE SQR PROGRAM AND LANGUAGE TUTORIAL ARE SOLD "AS IS," WITHOUT WARRANT AS TO THEIR PERFORMANCE, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE RESULTS AND PERFORMANCE OF THIS PROGRAM IS ASSUMED BY YOU. HOWEVER, TO THE ORIGINAL PURCHASER ONLY, THE PUBLISHER WARRANTS THE MAGNETIC MEDIUM ON WHICH THE PROGRAM IS RECORDED TO BE FREE FROM DEFECTS IN MATERIALS AND FAULTY WORKMANSHIP UNDER NORMAL USE FOR A PERIOD OF NINETY DAYS FROM THE DATE OF PURCHASE. IF DURING THE NINETY-DAY PERIOD THE MEDIUM SHOULD BECOME DEFECTIVE, IT MAY BE RETURNED TO THE PUBLISHER FOR A REPLACEMENT WITHOUT CHARGE, PROVIDED YOU HAVE PREVIOUSLY EXECUTED A SOFTWARE LICENSE AGREEMENT.

SQRIBE, SQR, SQR Execute, SQR Print, SQR Viewer, VisualSQRIBE, InSQRIBE, PowerSQRIBE, WebSQRIBE, ReportMart, RM/API, RM/InSQRIBE, RM/Publisher, RM/Script, and Instant HTML are trademarks or registered trademarks of SQRIB E T ec hnologies . All other company and product names used herein may be the trademarks or registered trademarks of their respective companies.

Contents
Introduction..................................................................................................................... ix Audience........................................................................................................................ x How to Use the SQR User’s Guide .............................................................................. x Related Documents ...................................................................................................... xi Syntax Conventions .................................................................................................... xii Setting up the Sample Database................................................................................. xii If You Need Help .......................................................................................................xiii

Part 1—SQR Basics
1 A Simple SQR Program ............................................................................................... 1 Creating and Running an SQR Program ..................................................................... 1 SQR Output ................................................................................................................... 2 2 Headings and Footings................................................................................................. 5 3 Selecting Data from the Database .............................................................................. 9 The SQR SELECT Statement ...................................................................................... 11 Syntax of the SELECT Statement ..................................................................... 11 Positioning Data ................................................................................................ 12 4 Column Variables ....................................................................................................... 15 5 Break Logic .................................................................................................................. 19 Using ON-BREAK....................................................................................................... 21 Skipping Lines Between Groups................................................................................ 22 Arranging Multiple Break Columns .......................................................................... 23 Break Processing with Enhancements ....................................................................... 25 Handling Page Breaks ....................................................................................... 29 Printing the Date................................................................................................ 29 Obtaining Totals ................................................................................................ 30 Hyphens and Underscores ............................................................................... 31 Setting Break Procedures with BEFORE and AFTER .............................................. 31 Understanding the Order of Events................................................................. 32 Controlling Page Breaks with Multiple ON-BREAK Columns ............................... 38 Saving a Value When a Break Occurs ....................................................................... 38 Using ON-BREAK on a Hidden Column.................................................................. 39 Restrictions and Limitations of ON-BREAK............................................................. 41 6 The SETUP Section..................................................................................................... 45 Using DECLARE-LAYOUT ....................................................................................... 46

Part 2—SQR Reports
7 Master/Detail Reports ................................................................................................ 49
SQR User’s Guide iii

Contents

SQR 4.3

Correlating Subqueries ............................................................................................... 51 8 Cross-Tabular Reports ................................................................................................ 55 Arrays........................................................................................................................... 56 Creating the Array ...................................................................................................... 59 Grouping by Category ................................................................................................ 60 Using Multiple Arrays ................................................................................................ 63 9 Printing Mailing Labels ............................................................................................. 69 Defining Columns and Rows ..................................................................................... 70 Running the Program.................................................................................................. 72 10 Creating Form Letters ............................................................................................... 75 Laying Out the Letter.................................................................................................. 75 11 Exporting Data to Other Applications .................................................................... 79

Part 3—Fonts and Graphics
12 Using Graphics .......................................................................................................... 83 Adding Graphics ......................................................................................................... 84 Sharing Images among Reports.................................................................................. 88 Printing Bar Codes ...................................................................................................... 92 13 Business Charts ......................................................................................................... 95 Creating a Chart .......................................................................................................... 95 Defining the Chart....................................................................................................... 99 Printing the Chart...................................................................................................... 100 Running the Program................................................................................................ 100 Passing Data to the Chart ......................................................................................... 102 14 Changing Fonts........................................................................................................ 105 Positioning Text ......................................................................................................... 105 Using WRAP.............................................................................................................. 108 15 Writing Printer-Independent Reports .................................................................. 111 Guidelines for Printer-Independent Reports........................................................... 111

Part 4—Advanced SQR Programming
16 Dynamic SQL and Error Checking ....................................................................... 115 Using Variables in SQL ............................................................................................. 115 Dynamic SQL............................................................................................................. 117 SQL Error Checking .................................................................................................. 119 SQL and Substitution Variables ............................................................................... 120 17 Procedures, Argument Passing, and Local Variables ......................................... 123 Procedures ................................................................................................................. 123 Local Variables ................................................................................................. 124
iv SQR User’s Guide

SQR 4.3

Contents

Argument Passing............................................................................................124 18 Multiple Reports......................................................................................................131 19 Using DML and DDL SQL Statements...............................................................137 Using BEGIN-SQL .....................................................................................................137 20 Working with Dates ................................................................................................141 Date Arithmetic .........................................................................................................141 Date Formats..............................................................................................................144 String to Date Conversions .............................................................................145 Date to String Conversions .............................................................................145 Using Dates with the INPUT Command .................................................................146 Date Edit Masks.........................................................................................................146 Declaring Date Variables ..........................................................................................148 21 National Language Support ...................................................................................151 Locales ........................................................................................................................151 Available Locales .............................................................................................151 The Default Locale.....................................................................................................152 Switching Locales ......................................................................................................153 Modifying Locale Preferences ..................................................................................154 Keywords—NUMBER, MONEY, and DATE .........................................................154 22 Interoperability........................................................................................................157 Calling SQR from Another Application...................................................................158 Using the SQR API ....................................................................................................158 Extending SQR—UFUNC.C .....................................................................................161 Adding a User Function............................................................................................162 Step 1. Add Function Prototype.....................................................................162 Step 2. Add Entry to USERFUNCS Table .....................................................163 Step 3. Add Implementation Code ................................................................164 Step 4. Relink SQR...........................................................................................165 ufunc on Windows 95 & NT .....................................................................................165 Implementing New User Functions on Windows 95 & NT ...................................166 23 Testing and Debugging ..........................................................................................167 Using the Test Feature...............................................................................................167 Using the #DEBUG Command .................................................................................168 Using Compiler Directives for Debugging..............................................................169 Common Programming Errors.................................................................................169 24 Performance and Tuning ........................................................................................171 SQR Performance and SQL Statements ...................................................................171 Simplifying a Complex SELECT...............................................................................172 Using LOAD-LOOKUP to Simplify Joins................................................................172

SQR User’s Guide

v

............3 Improving SQL Performance with Dynamic SQL ................................................................................................... 193 27 Using the SQR Command Line .................................................................................. 202 Passing Command-Line Arguments—Other Approaches .... 211 Using -PRINTER:HT....................... 201 How SQR Retrieves the Arguments................................................................... 204 Using Batch Mode ..................................................................................................................................................................................... 185 Tuning SQR Numerics ....................................... 189 26 Printing Issues ...............................Contents SQR 4............................................. 203 Reserved Characters ... 218 Using Additional HTML Procedures................. 186 Buffering Fetched Rows............... 219 Testing ............... 207 Producing HTML Output ............... 185 Compiling SQR Programs and Using SQR Execute .................... Windows 95........................................................................ 214 "Bursting" and Demand Paging............ 204 Creating an Argument File from a Report..................................................................................................................................................................................................................................................................................................................................................................................... 221 vi SQR User’s Guide ...................................................................... 215 Setting Attributes with HTML Procedures............. 186 Processing Limits....................................................... 201 Specifying Arguments and Argument Files .. 205 28 Working with HTML .......................................... 220 Using HTML Procedures in an SQR Program ........................................................... 201 Specifying Command-Line Arguments ......................................................................................................................................................................................................................... 182 Creating Multiple Reports in One Pass ............................................................................................................................................................................. 202 Using an Argument File ................................................................................... 205 UNIX........................... 209 Setting HTML Attributes under -PRINTER:EH.......... and Windows NT ............... 176 Using and Sorting Flat Files ............................................................................................ 187 Executing Programs on the Database Server .................... 175 Avoiding Temporary Database Tables ............................................................................................................................................................................................................................ 205 VAX/VMS ............................................................... 174 Examining SQL Cursor Status.................................................................... 208 HTML Output ................................................................................................................................................................................................ 187 Part 5—Running and Printing 25 Compiling Programs and Using SQR Execute ............. 207 SQR Capabilities Available with HTML ........... 208 Using -PRINTER:EH.............................................................................. 176 Using and Sorting Arrays .......................... 219 Output File Types ........................................... 220 How to Use HTML Procedures ........................................................................................................................................................................................ 199 Command-Line Flags .......

...............................233 Publishing Using a CGI Script .........................................................89 SQR User’s Guide vii .......9 ex5a.............................................................................................................................50 ex8a...................................................................................................................................................83 ex12b........................79 ex12a....................226 Images ....sqr—Printing a Heading and Footing..........................................................................................76 ex11a.................................................sqr—Tabular Report with Graphics..........................................................88 ex12c.....................19 ex5b.........sqr—Program to Create Tab-Delimited File ....................................57 ex8b........................sqr—Program with Multiple ON-BREAK Columns ...........................................................................................................sqr—A Simple Tabular Report.....sqr—Mailing Labels Program (Alternate Layout) .............................................................229 Modifying an Existing SQR Program..................................235 Creating the CGI Script ...........................................................sqr—A Simple Program.............................................................................................................63 ex9a................................................................................225 Highlighting...........................................................................................................227 Paragraph Formatting........223 Headings .33 ex5f..................................39 ex7a..........sqr—Using Break Logic on a Hidden Column ...............................................................................85 acme.............................sqr—A Report with Break Logic.....................249 Sample Programs ex1a.......................sqr—Program with Break Logic and Enhancements ..........................................................1 ex2a..inc..........................................................................................................................................................sqr—Master/Detail Report .........................................................................234 Creating the Fill-Out Form ...................sqr—Cross-Tabular Report with Grouping by Category ....................................................................................................227 Lists ......................................................................................241 Index .....................................................................229 Publishing the Report ........................................................................................69 ex9b..sqr—Cross-Tabular Report with Grouping by Two Categories ................233 Publishing Using an Automated Process ............................................................................................................................................................................................................6 ex3a.............sqr—Form Letter Program ........................61 ex8c....................................................21 ex5c.........................sqr—Mailing Labels Program ........................................................................................................................................................................................sqr—Form Letter with Graphics...........24 ex5d......sqr—Cross-Tabular Report ..........................................................232 Viewing the Published Report ....................................3 Contents Positioning Objects....................................221 Table Procedures.........................................................................sqr—Tabular Report without Graphics.......................25 ex5e..........SQR 4.....................................................................................................................sqr—Order of Events in Break Processing..................................................................................238 29 Tables of Contents.........................................sqr—Selecting Data from the Database .......................228 User-Defined HTML.........................225 Hypertext Links.....................73 ex10a.......236 Passing Arguments to the SQR Program .........................................

............. 96 ex14a......... 116 ex16b....... 223 ex28b.................................. Table 3.................................................sqr—External Files and Database Inserts......... Syntax Conventions..........Contents SQR 4...............................................................sqr—Simple Tabular Program with HTML Procedures.sqr—Check-Writing Program ..................... Table 2............................. 118 ex16c................................................................................................... 191 Command-Line Flags and Output Types..................................... 183 ex28a................................................................................................................................ Table 9............................................................... Table 5.......................................sqr Modified with HTML Procedures............................................... 230 Tables Table 1........................................ Table 7............inc—spell_number procedure ...........sqr—Multiple Report Program.sqr—Report with Multiple Fonts.................................. 178 ex24b.................................. Table 6.......sqr—Business Chart ................ 161 Compile-Time Commands and Run-Time Equivalents ........ 107 ex16a...............................................................................................sqr—Using Variables in SQL ........................................................... 131 ex19a.........sqr—Dynamic SQL ........................ 193 Print Commands by Operating System .................................. 128 ex18a.............................................sqr—QuickSort Procedure ......................sqr—Program ex12a............. 159 Error Values Returned by the SQR API ...........................................sqr—Sorting a Flat File .................................... 196 SQR Command-Line Arguments............ 199 viii SQR User’s Guide ...................................................................3 ex13a.......................xii Commands Available in the SETUP Section............................... Table 4........................................ 146 The SQR API .......................................................................... 125 ex17a............................. 45 Sample Date Edit Masks ...........................sqr—SQL and Substitution Variables........................................................................................ 138 ex24a.................................. 121 spell..... Table 8............

The tips and techniques you find here will help you take advantage of SQR’s advanced capabilities. form letters. • Create reports that can be easily ported between different systems and databases and that support different printer and display types. numbers. • Produce graphs and charts that will help you present data and trends in visual terms.Introduction Welcome to the SQR User’s Guide. This User’s Guide is filled with real examples and sample programs. you will learn how to write SQR programs that select data from a database and present it in a report. a specialized language for database processing and reporting. The next two parts of the User’s Guide describe the advanced features and uses of SQR. This guide is designed to help you learn SQR. SQR User’s Guide ix . • Enhance your reports with typeset-quality fonts and graphics. • Integrate SQR with other software packages. It will help you create the kinds of SQR programs that are important to your organization. Many of these techniques will save you time in developing reports for your organization. • Extend SQR with procedures and functions written in C. • Tune your programs for optimum performance. such as tabular. and envelopes. and we encourage you to copy code from it. You will learn how to: • Create HTML output and publish your reports on the Internet or an Intranet or Extranet. cross-tabular and master/detail reports. • Create reports that format dates. You will learn how to: • Create a variety of reports. By working through code examples. • Produce mailing labels. • Test and debug your programs. The first three parts of the User’s Guide teach basic uses of SQR. and money according to local preferences. such as front-end user interface tools and spreadsheets.

To use this guide effectively. you must first install SQR. You also need to be familiar with your particular database and operating system. x SQR User’s Guide . You can use this book by simply reading it and studying the code examples. you need a working knowledge of SQL and experience in writing software programs. the first three parts (through Chapter 15) will give you everything that you need to get started. you may wish to rerun the installation program to install just these files. If you did not include the User’s Guide files in the original installation. You can run the User’s Guide programs on any hardware platform. and SQLBase databases. If you have not already installed SQR on your system. The rest of the User’s Guide discusses advanced features and more technical issues. see the installation instructions provided with SQR. If you installed all of the program components. We recommend that you adopt this standard style because it will make your code easier for other SQR programmers to read. we encourage you to try these programs for yourself and to experiment with them.3 The code examples also demonstrate good SQR programming style. Audience This guide was written for programmers developing reports for relational databases. How to Use the SQR User’s Guide If this is your first time using SQR. Ingres. consult the SQR ® Language Reference or SQRIBE Technologies Technical Support for additional information. However. If your database is not named here. but you may find it somewhat easier to review SQR program results from the Windows platform using the SQR Viewer. Try making some changes to our examples and see how they run. The examples may also be run against other databases with minor modifications. SYBASE. Informix. you will find the sample programs in the TUTORIAL directory. To try the sample programs.Introduction SQR 4. The program examples in this guide can be run without modification against the Oracle.

the SQR product includes the following documentation: ® • SQR Language Reference contains a complete reference to SQR commands.3 or higher. arguments.SQR 4. • SQR Server Installation Guide contains installation instructions and configuration information specific to your platform.3 Introduction À Note You can set up the sample database and run the sample programs with any user name and password. SQR User’s Guide xi . and command-line flags. This guide describes the features for SQR Version 4. Related Documents In addition to this User’s Guide. • SQR Server Release Notes describes enhancements and new features.3. • VisualSQRIBE User’s Guide explains how to quickly create SQR reports. using the graphical SQR development tool on Windows 95 and Windows NT systems. however. • VisualSQRIBE Installation Guide contains installation instructions and configuration information specific to your platform. We recommend. • VisualSQRIBE Release Notes describes enhancements and new features. and the code examples require SQR Version 4. that you use an account that does not hold important data.

xii SQR User’s Guide . Information and values that you must supply are specified in italics. execute loadall. On the command line. Syntax Conventions . braces. A comma separates multiple arguments. SQR commands and arguments are specified in bold uppercase. Parentheses must enclose an argument or element. or parentheses. you can run loadall. | ’ Description Braces enclose required items.3 Syntax Conventions Syntax and code examples use the following conventions: Symbol {} [] . () BOLD UPPERCASE Italic Setting up the Sample Database To run the sample programs in this guide. An ellipsis shows that the preceding parameter can be repeated..sqr..sqr by double-clicking on the Loadall icon. you will need to create a sample database.Introduction SQR 4. Change to the SAMPLE directory. A vertical bar separates alternatives within brackets. To do so.sqr from the SQR product’s SAMPLEW directory. If your system does not display this icon. Table 1. Square brackets enclose optional items. A single quote starts and ends a literal text constant or any argument that has more than one word. enter: sqr loadall username/password If SQR is installed on Windows NT or Windows 95. run the program loadall.

you will be prompted to: A—Abort the load. S—Skip the specified table. C—Reload all tables. You can also run this as a batch program by the preferred option (A.3 Introduction If an individual table already exists. R—Reload the specified table.SQR 4. For example: sqr loadall username/password a If You Need Help If you are unable to resolve an SQR question or problem using product documentation and you have a valid SQRIBE Technologies support agreement. You may also send an e-mail message to support@sqribe.473.com. you may contact SQRIBE Technical Support from 6:00 AM to 5:30 PM Pacific Time at 1. You will also need to know the version of SQR you are using.436. R.800.437.7489 (outside of North America). SQR User’s Guide xiii .562. or C) on the command-line. Please be prepared to provide a valid customer number and company name. your operating system and database names and versions. + 1. S.1663 (within North America) or. please call 1. If you wish to execute a SQRIBE support agreement.888.6391.

.

1 A Simple SQR Program In this chapter. Use the command appropriate to your operating system to change to the directory in which you saved the program.sqr file found in the TUTORIAL directory. Save this program with the name ex1a. enter the appropriate SQR program command at the system command prompt or from within the SQR application’s graphical user interface. is always run from the command line. Run the sample program. where available. World. Then. Program ex1a. all of the program examples and their output files are included with the installation. Creating and Running an SQR Program Open a text editor and enter the code printed above exactly as shown or open the ex1a. and PRINT.sqr begin-program print ’Hello. If you are actually writing the sample program code. The first sample program is the simplest SQR program. the next step is to save your code. END-PROGRAM. SQR User’s Guide 1 . You will also learn how to create and run an SQR program.sqr. SQR programs are normally given a file extension of . SQR on UNIX systems. You may run SQR from the command line or from a GUI on Windows systems. you will learn three SQR commands: BEGIN-PROGRAM.1) end-program À Note For your convenience. It prints a text string.’ (1.sqr.

Do not worry about its presence at this stage.. The output files should appear as soon as your program has finished running. 2 SQR User’s Guide . the SQR program name and connectivity string. and arguments. If you specified the -KEEP argument.] [args .. SQR Output SQR normally places the SQR program output files in the directory from which you run the program.SPF extension). you may be running SQR on Windows NT against an Oracle database located on another machine in your network. On UNIX systems..3 If you are entering the information from the command line. flags. all on one line.] [@file . The output file will have the same file name as the SQR file that created it but the file extension will differ. SQR Command-Line Arguments and Table 2. On SQR for Windows systems. on Windows platforms with the SQR Viewer GUI (sometimes referred to as an "SPF viewer") or from within VisualSQRIBE using the File|Open menu commands. ex1a.] Consult Table 1. The SQR Viewer is invoked from the command line with "sqrwv". SQR Portable Format will be discussed later in this book but for now.. SQR Command-Line Flags in the SQR Language Reference for a complete explanation of connectivity.. the -KEEP flag is used in our example. one output file will be in SQR Portable Format (recognizeable by its .. password. you should see a command line similar to: sqrw ex1a sammy/baker@rome -KEEP In order to produce the desired output file for this exercise.A Simple SQR Program SQR 4. you may easily view the sample program’s . SQR is invoked from the command line with "sqrw".spf.SPF file output. SQR is invoked from the command line with "sqr". include "sqr" or "sqrw". The following syntax shows you how to run SQR from the command line: [sqr or sqrw] [program] [connectivity] [flags . and servername with the appropriate information. In a common configuration. The command that you should then execute would have the following format: sqrw ex1a username/password@servername -KEEP If you correctly replace username.

the output will look like this: Output for ex1a. These two commands and the code between them make up the PROGRAM section. The PROGRAM section contains a PRINT command. which is the top left corner of the page. MORE. You may view this output file type from the command line with such commands as TYPE on Windows sytems or CAT.sqr." This text is enclosed in single quotation marks (’). the program will also produce an output file with an .LIS file. In this guide.sqr Hello. The PROGRAM section is required. You may also see a character such as ^L.3 A Simple SQR Program On Windows and UNIX systems. World. À Note In SQR. which are used in SQR to distinguish literal text from other program elements. Take another look at sample program ex1a.1)" indicates line one. and VI on UNIX systems. The "(1. It is the form feed character that ejects the last page. and you may have only one. No matter what platform you are using. World. starting with BEGIN-PROGRAM and ending with END-PROGRAM. which in this case prints the text "Hello.LIS extension. you must place each command on a new line. SQR User’s Guide 3 . column one. we do not show the form-feed characters. You may indent SQR commands. An output page can be thought of as a grid of lines and columns. Use the command appropriate to your system to view or print the . which is used to control the order of processing. It is typically placed at or near the top of the program. This program consists of three lines of code. The last element of the PRINT command gives the position on the output page.SQR 4. or <FF> at the end of this output file.

The next chapter explains how to extend your program by printing a title on the top of the page and a page number on the bottom of the page. • The PRINT command can be used to print a text string.A Simple SQR Program SQR 4.3 Summary • The PROGRAM section is where execution of the program begins. • Enter each command on a new line. 4 SQR User’s Guide . • Print position can be expressed by a pair of numbers enclosed in parentheses.

the date. Typically. and footing: Heading lines Body lines Footing lines 1 2 3 4 1 2 3 4 5 6 7 8 9 10 11 1 2 3 4 5 Heading Body Footing The diagram also shows that the heading. body. You can print in each of these page areas using line numbers that are relative to the top corner of that area without being concerned about the size of the other areas. you can print to the first line of the body using line number 1. In other words. The middle part of the page is called the body. Here we normally print the page number. This is where we print the report data. In SQR. Here is the code: SQR User’s Guide 5 . You will learn to use the BEGIN-HEADING and BEGIN-FOOTING commands. and footing each have independent line numbers. the page can be divided into three logical areas.2 Headings and Footings This chapter explains how to create page headings and footings. every page of a report has some information about the report itself. and the page number. This is where we normally print the report title and the date. The program you wrote in the last chapter can be expanded by adding a page heading and footing. The top area of the page is the heading. The bottom area of the page is the footing. body. The following diagram shows the structure of a page with heading. such as the title. independent of the size of the heading.

sqr begin-program print ’Hello. World. The command BEGIN-FOOTING is followed by the number 1. The BEGIN-HEADING command is followed by a number. the heading will take exactly one line and will consist of the text "Tutorial Report.Headings and Footings SQR 4." The CENTER argument ensures that the text is centered on the line. The page footing is defined in the FOOTING section. Note also that line 1 of the body is actually the first line after the heading. Page 1 of 1 The page heading is defined in the HEADING section. In our example. the maximum possible size of the body of our report is reduced by two lines. which means that the footing will take one line.sqr Tutorial Report Hello. This line will consist of the text "Page 1 of 1. 6 SQR User’s Guide . With one line each in the heading and footing.’ (1. The section starts with BEGIN-HEADING and ends with END-HEADING.1) ’Page ’ last-page () ’ of ’ end-footing Output for ex2a. which starts with BEGIN-FOOTING and ends with END-FOOTING.3 Program ex2a. which is the number of lines reserved for the heading.1) end-program begin-heading 1 print ’Tutorial Report’ (1) center end-heading begin-footing 1 ! print "Page n of m" in the footing page-number (1. World." Note that any space reserved for the heading and footing is taken away from the body.

and LAST-PAGE commands. For example: print ’Hello. It is the first line following the body. In our example. World!!’ (1. PAGE-NUMBER.1) The PAGE-NUMBER command prints the text "Page " and the current page number. line 1 of the footing is at the bottom of the page. and they extend from the exclamation mark to the end of the line. What is the order of execution? The PRINT command actually places text in memory. column is the column (character position) and width is the width of the text.3 Headings and Footings The first line in the FOOTING section is a comment. Numbers in these parentheses give the position for printing.1) in the body. Similarly.SQR 4. the print position defaults to the current position." SQR User’s Guide 7 . body. SQR prints "Page 1 of 1" because there is only one page. The LAST-PAGE command prints the number of the last page. SQR always prepares a page in memory before printing it to paper. within the heading. World" is executed first. Comments are preceded by an exclamation mark. "Hello. A position in SQR is expressed as three numbers in parentheses— (line. preceded by the word "of. The position (1. the position following the last item printed. not on paper." which is bracketed by spaces. In many cases. so line 1 of the body is actually the second line of the page. In the program. a position consists only of the line and column numbers. Print position is a point within the area of the page. or footing. then "Tutorial Report" and "Page 1 of 1. you must type it twice to tell SQR not to take it as the beginning of a comment. performing the body first. Line 1 of the body is the first line below the heading. or more precisely. In the example. If you want to print an exclamation mark. the heading has only one line.1) in the heading is not the same as the position (1. Note the parentheses in the PRINT. then the HEADING and FOOTING sections. the LAST-PAGE command has the position "()" so the current position here is the position following the page number. If you also omit the line and column numbers.width)—where line is the line number.column. In this case. The width is normally omitted because it defaults to the width of the text being printed.

8 SQR User’s Guide . The next chapter explains how to write a program that retrieves data from the database and prints it in a report. • Exclamation marks are used to precede comments.3 Summary • An SQR program can have HEADING and FOOTING sections which create the heading and footing of a report page. • Page numbers can be printed in a "Page n of m" format with the PAGE-NUMBER and LAST-PAGE commands. • The CENTER option of the PRINT command centers text on a line. • Print positions are expressed by numbers enclosed in parentheses.Headings and Footings SQR 4.

Here is the code. Program ex3a. which is the principal means of retrieving data from the database and printing it in a report.1) print ’City’ (. you will also learn how to use procedures.32) print ’State’ (.55) position (+1) ! Advance to the next line from customers end-select end-procedure ! list_customers SQR User’s Guide 9 .49) phone (.sqr begin-program do list_customers end-program begin-heading 4 print ’Customer Listing’ (1) center print ’Name’ (3.32) state (.1) city (. You will learn the BEGIN-SELECT command. An explanation of it follows.49) print ’Phone’ (.1) ’Page ’ last-page () ’ of ’ end-footing begin-procedure list_customers begin-select name (.3 Selecting Data from the Database This chapter describes how to write a program that lists data from the database and prints it in columns.55) end-heading begin-footing 1 ! Print "Page n of m" in the footing page-number (1. Because the BEGIN-SELECT command is used in a procedure.

a procedure is a group of commands that are performed one after the other. 2125550021 Harry’s Landmark Diner 3175550948 City Everretsville New York Queens Zanesville Davenport Mamaroneck Teaneck Cleveland Frogline New York Bell Harbor Big Falls New York Miningville State Phone OH NY NY OH IN NY NJ OH NH NY MI NM NY IN Page 1 of 1 The PROGRAM section consists of a single DO command. Four lines are reserved for the heading.sqr Customer Listing Name Gregory Stonehaven 2165553109 Alfred E Newman & Company 2125552311 Eliot Richards 2125554285 Isaiah J Schwartz and Company 5185559813 Harold Alexander Fink 3015553645 Harriet Bailey 9145550144 Clair Butterfield 2015559901 Quentin Fields 2165553341 Jerry’s Junkyard Specialties 6125552877 Kate’s Out of Date Dress Shop 2125559000 Sam Johnson 3135556732 Joe Smith and Company 8085552124 Corks and Bottles. In SQR. 10 SQR User’s Guide . It should normally consist of a few DO commands for the main components of your report. The HEADING section (shown again below) creates headings for the report columns. like a procedure (or subroutine) in other programming languages.3 Output for ex3a. Inc. We recommend that you break your program logic into procedures and keep the PROGRAM section small. which invokes the procedure list_customers. A procedure is invoked with a DO command.Selecting Data from the Database SQR 4.

SQR User’s Guide 11 . the word SELECT is omitted. (You can also omit the exclamation point: END-PROCEDURE main. À Note You must name each individual column in a table—the SELECT * FROM statement is not allowed in SQR. character position 1. PHONE FROM CUSTOMERS Syntax of the SELECT Statement In an SQR SELECT paragraph. The rest of the column-heading commands omit the line numbers in their positions and default to the current line.55) end-heading The title "Customer Listing" is printed on line 1. Line 4 of the heading is left blank. which is helpful when you have a program with many procedures. each column is on its own line. which starts with BEGIN-PROCEDURE and ends with END-PROCEDURE.SQR 4.1) print ’City’ (. The SQR SELECT Statement Look again at the list_customers procedure. It combines a SQL SELECT statement with SQR processing in a seamless way. The SELECT paragraph is unique. It tells you which procedure is being ended.) The procedure itself contains a SELECT paragraph." is positioned at line 3 of the heading. and there are no commas between the column names. STATE. CITY.32) print ’State’ (. Line 2 is left blank. The first column heading. which starts with BEGIN-SELECT and ends with END-SELECT. "Name. Note the comment following the END-PROCEDURE command.49) print ’Phone’ (. You can also place SQR commands between the column names. Instead. The actual SQL statement is: SELECT NAME. and these commands will be executed for every record that the SELECT fetches.3 Selecting Data from the Database begin-heading 4 print ’Customer Listing’ (1) center print ’Name’ (3.

A plus sign moves the print position forward from the current position.55) position (+1) from customers end-select ! Advance to the next line The implied PRINT command is a special SQR feature designed to save you coding time. The rest of the SQR SELECT statement is then written freely. You can think of the SELECT paragraph as a loop. The SQR commands. there is a POSITION command: POSITION(+1).1) city (. omitting the line number in the position lets it default to the current line. Positioning Data In SELECT statement (repeated below). The plus sign (or minus sign) indicates relative positioning in SQR. are executed in a loop. once for each record that is returned by the SELECT.32) state (. SQR commands must be indented at least one space— in the example below. Column names must be placed at the beginning of a line. This positioning implies a PRINT command for that column. you see positioning after each column name. 12 SQR User’s Guide . This command will advance the current print position to the next line. and a minus sign moves it back. be sure your numbers don't specify a position outside the page boundaries. The word FROM must be the first word in a line. After the last column.3 SQR distinguishes column names from SQR commands in a SELECT paragraph by their indentation. including printing of columns. begin-select name (. The loop ends after the last record is returned. The "+1" in our program means one line down from the current line. following SQL syntax. It only works inside a SELECT paragraph.Selecting Data from the Database SQR 4.49) phone (. As before. the POSITION command is indented to prevent it from being taken as a column name. When you indicate print positions using plus or minus signs.

• A SELECT paragraph begins with BEGIN-SELECT and ends with END-SELECT. • The POSITION command is used to give a position. you can print a column by entering it at the beginning of a line with a position qualifier.3 Selecting Data from the Database Summary • The DO command is used to invoke a procedure.SQR 4. SQR User’s Guide 13 . The next chapter describes a special kind of SQR variable called a column variable. These variables hold the results from a SELECT paragraph. This is called an implied PRINT command. • A procedure begins with BEGIN-PROCEDURE and ends with END-PROCEDURE. • In a SELECT statement. • SQR commands in a SELECT paragraph must be indented at least one space to prevent them from being taken for column names.

.

1) end-if position (+1) from customers end-select end-procedure ! list_customers The phone column is considered an SQR column variable. for example.1) else print &phone (. in a condition? The following example shows you how to do this. SQR User’s Guide 15 . You can use their existing value. but you cannot assign a new value to a column variable. Unlike other program variables. you can immediately print them using a position. column variables are read-only.4 Column Variables This chapter explains how to name database columns with variables and how to use their values in conditions and commands. Column variables are preceded with an ampersand (&). For example: begin-select phone (.1) position (+1) from customers end-select But what if you want to use the value of phone for another purpose. begin-program do list_customers end-program begin-procedure list_customers begin-select phone if &phone = ’’ print ’No phone’ (. When you select columns from the database in a SELECT paragraph.

Column Variables SQR 4.3 In the sample program. Note that the column variable &phone inherited its name from the phone column. This is the default. In the condition. state end-select In this example. as the following example demonstrates. date. an empty string.1) else print &cust_phone (.1) end-if position (+1) from customers end-select Why would you want to change the name of the column variable? One reason is that you may want to use a selected column in an expression that has no name. For example: begin-select count(name) &cust_cnt (. depending on its contents. &phone is compared to ’ ’. begin-select phone &cust_phone if &cust_phone = ’’ print ’No phone’ (. If &phone is an empty string. the expression count(name) is selected. In the program. 16 SQR User’s Guide . or numeric variable.1) if &cust_cnt < 100 print ’Less than 100 customers’ end-if position (+1) from customers group by city. the program prints "No phone" instead. but you can change it. &phone is a column variable that you can use in SQR commands as if it were a string. you store this expression in the column variable &cust_cnt and refer to it afterwards by that name.

The next chapter introduces the concept of a report break. We can rename column variables to receive the value of expressions. It will also explain how to print database records across multiple lines in a report.3 Column Variables Summary • In SQR. SQR User’s Guide 17 .SQR 4. • Column variables can be used in commands and conditions. Column variables are preceded with an ampersand (&). we can refer to database columns as variables.

.

and perform additional processing on the count or subtotal. Here is the program without break logic: Program ex5a. There are a number of reasons to use break logic in a report. region. Records with the same value—for example. you can write a program similar to the one in the Chapter 3 and then add break logic to it. The break logic will make the grouping more apparent. To see how a break works. SQR User’s Guide 19 . you may want to prepare a sales report with records grouped by product. It allows you to: • Add white space to your reports • Avoid printing redundant data • Perform conditional processing on variables that change • Print subtotals For example.5 Break Logic This chapter describes techniques for using break logic in your SQR programs. When a break occurs. records with the same value for state—logically belong to a group. A break is a change in the value of a column or variable. subtotal a column. It also presents some additional techniques to enhance the appearance of reports that use break logic. or salesperson (or all three). a new group begins. count records.sqr begin-program do list_customers end-program Program continues on the following page. Break logic will allow you to do all that and more—you can print column headings.

the records are grouped by state.7) (1.55) position (+1) ! Advance to the next line from customers order by state. you can add a break.24) phone (.1) city (. name end-select end-procedure ! list_customers Output for ex5a.55) begin-procedure list_customers begin-select state (. 20 SQR User’s Guide . To make the grouping more apparent.24) (1.1) (1. and name (note the ORDER BY clause in the BEGIN-SELECT).sqr State City IN IN MI NH NJ NM NY NY NY NY NY OH OH OH Davenport Miningville Bell Harbor Frogline Teaneck Big Falls Mamaroneck New York New York New York Queens Cleveland Everretsville Zanesville Name Harold Alexander Fink Harry’s Landmark Diner Sam Johnson Jerry’s Junkyard Specialties Clair Butterfield Joe Smith and Company Harriet Bailey Alfred E Newman & Company Corks and Bottles. Kate’s Out of Date Dress Shop Eliot Richards Quentin Fields Gregory Stonehaven Isaiah J Schwartz and Company Phone 3015553645 3175550948 3135556732 6125552877 2015559901 8085552124 9145550144 2125552311 2125550021 2125559000 2125554285 2165553341 2165553109 5185559813 When the output is sorted by state.sqr (continued) begin-heading 2 print ’State’ print ’City’ print ’Name’ print ’Phone’ end-heading (1. Inc. city.Break Logic SQR 4.7) name (.3 Program ex5a. city.

where state.1) print ’City’ (1. Note that ON-BREAK works as well for implicit as for explicit PRINT commands.55) end-heading begin-procedure list_customers begin-select state (.1) on-break city (.3 Break Logic Using ON-BREAK In the program below.sqr begin-program do list_customers end-program begin-heading 2 print ’State’ (1. name end-select end-procedure ! list_customers The output is shown on the following page.sqr with the exception of the line that prints the state column. such as in the example below.7) print ’Name’ (1. This line is shown in bold. and prints state only when its value changes. name.24) print ’Phone’ (1.7) name (.SQR 4. Program ex5b.24) phone (. city.55) position (+1) ! Advance to the next line from customers order by state. and phone are implicitly printed as part of the SELECT paragraph. The program below is identical to ex5a. SQR User’s Guide 21 . city. the ON-BREAK option of the PRINT command accomplishes two related tasks—it starts a new group each time the value of state changes.

with the modified line shown in bold: begin-select state (. Inc. Here is the list_customers procedure from ex5b. To do so.55) position (+1) ! Advance to the next line from customers order by state.7) name (.sqr.Break Logic SQR 4. Skipping Lines Between Groups You can further enhance the visual effect of break processing by inserting one or more lines between groups.24) phone (.3 Output for ex5b.sqr State City IN MI NH NJ NM NY Davenport Miningville Bell Harbor Frogline Teaneck Big Falls Mamaroneck New York New York New York Queens Cleveland Everretsville Zanesville Name Harold Alexander Fink Harry’s Landmark Diner Sam Johnson Jerry’s Junkyard Specialties Clair Butterfield Joe Smith and Company Harriet Bailey Alfred E Newman & Company Corks and Bottles. the state abbreviation is printed only once for each group. name end-select The output is shown below. Kate’s Out of Date Dress Shop Eliot Richards Quentin Fields Gregory Stonehaven Isaiah J Schwartz and Company Phone 3015553645 3175550948 3135556732 6125552877 2015559901 8085552124 9145550144 2125552311 2125550021 2125559000 2125554285 2165553341 2165553109 5185559813 OH With break processing. city. 22 SQR User’s Guide . use the SKIPLINES qualifier with ON-BREAK.1) on-break skiplines=1 city (.

and the breaks are said to be nested.3 Break Logic State IN MI NH NJ NM NY City Davenport Miningville Bell Harbor Frogline Teaneck Big Falls Mamaroneck New York New York New York Queens Cleveland Everretsville Zanesville Name Harold Alexander Fink Harry’s Landmark Diner Sam Johnson Jerry’s Junkyard Specialties Clair Butterfield Joe Smith and Company Harriet Bailey Alfred E Newman & Company Corks and Bottles. Number your breaks in the same order in which they are sorted in the ORDER BY clause." on page 31. When you have multiple breaks.SQR 4. then city. This sort of arrangement is called nesting. see "Understanding the Order of Events. You can apply the same break concept to the city column to make this grouping of customers more apparent. Add another ON-BREAK to the program so that city will also be printed only when its value changes. You will learn more about this technique in the section "Setting Break Procedures with BEFORE and AFTER. Kate’s Out of Date Dress Shop Eliot Richards Quentin Fields Gregory Stonehaven Isaiah J Schwartz and Company Phone 3015553645 3175550948 3135556732 6125552877 2015559901 8085552124 9145550144 2125552311 2125550021 2125559000 2125554285 2165553341 2165553109 5185559813 OH Arranging Multiple Break Columns As you can see in the previous example." on page 32. Inc. you must arrange them in a hierarchy. In the sample program. so it is logical to arrange them according to size—first state. To ensure that the breaks are properly nested. use the LEVEL keyword. This argument numbers breaks by level and specifies that the columns are printed in order of increasing break levels. you can also have multiple customers within a city. SQR User’s Guide 23 . from left to right. the breaks concern geographical units. For more information on LEVEL. The LEVEL qualifier allows you to control the order in which you call break procedures.

Kate’s Out of Date Dress Shop Eliot Richards Quentin Fields Gregory Stonehaven Isaiah J Schwartz and Company Phone 3015553645 3175550948 3135556732 6125552877 2015559901 8085552124 9145550144 2125552311 2125550021 2125559000 2125554285 2165553341 2165553109 5185559813 OH As you can see.sqr begin-program do list_customers end-program begin-heading 2 print ’State’ print ’City’ print ’Name’ print ’Phone’ end-heading (1.7) (1. Inc.1) on-break level=1 city (.7) on-break level=2 name (.55) position (+1) ! Advance to the next line from customers order by state. These two lines are shown in bold.1) (1. 24 SQR User’s Guide . there are three customers in New York.24) phone (.sqr with the exception of the two lines that print the state and city columns.sqr State City IN MI NH NJ NM NY Davenport Miningville Bell Harbor Frogline Teaneck Big Falls Mamaroneck New York New York New York Queens Cleveland Everretsville Zanesville Name Harold Alexander Fink Harry’s Landmark Diner Sam Johnson Jerry’s Junkyard Specialties Clair Butterfield Joe Smith and Company Harriet Bailey Alfred E Newman & Company Corks and Bottles.55) begin-procedure list_customers begin-select state (. Program ex5c.3 The next example is identical to ex5a.Break Logic SQR 4.24) (1. city. so the city name for the second and third customers is left blank. name end-select end-procedure ! list_customers Output for ex5c.

1) print ’Customer Name. let #cust_total = #cust_total + #state_total let #state_total = 0 end-procedure ! state_tot Program continues on the following page. address.1) Edit ’DD-Mon-YYYY’ print ’State’ (3. The break processing is performed on the state column. The following example illustrates these techniques. you may want to enhance your report by controlling page breaks or calculating counts and totals for the ON-BREAK column.1) ’Page ’ last-page () ’ of ’ end-footing begin-procedure state_tot print ’ Total Customers for State: ’ (+1.1.999 position (+3. The program selects the customer’s name.9) fill print ’-’ (4. and telephone number from the database.11) print ’-’ (4. Here is the code: Program ex5d.sqr begin-program do list_customers end-program begin-heading 4 print ’Customers Listed by State’ (1) center print $current-date (1.SQR 4. SQR User’s Guide 25 .1) print #state_total () edit 999.40) fill end-heading begin-footing 2 ! print "Page n of m" page-number (1.1) ! Leave 2 blank lines.11. Address and Phone Number’ (.3 Break Logic Break Processing with Enhancements When you use break logic.

11) ! continue on second line addr2 (+1.1) end-if end-procedure ! list_customers The output is shown on the following pages. The procedure ’state_tot’ will also be ! executed only when the value of ’state’ changes.3 Program ex5d.1) on-break print=change/top-page after=state_tot name (.11) ! continue on third line city (+1.999 ! Total customers printed.’ (1.11) addr1 (+1.+2) edit (xxx)bxxx-xxxx ! Edit for easy reading. 26 SQR User’s Guide . else print ’No customers.sqr (continued) begin-procedure list_customers let #state_total = 0 let #cust_total = 0 begin-select ! The ’state’ field will only be printed when it ! changes. name end-select if #cust_total > 0 print ’ Total Customers: ’ (+3. we specify ’need=4’ to ! prevent a customer’s data from being broken across two pages.Break Logic SQR 4. state (. ! Skip 1 line between listings. ! Since each listing takes 4 lines.11) ! continue on fourth line phone (. next-listing skiplines=1 need=4 let #state_total = #state_total + 1 from customers order by state.1) print #cust_total () edit 999.

---------------------------------------IN Harold Alexander Fink 32077 Cedar Street West End Davenport (301) 555-3645 Harry’s Landmark Diner 17043 Silverfish Road South Park Miningville (317) 555-0948 Total Customers for State: MI 2 Sam Johnson 37 Cleaver Street Sandy Acres Bell Harbor (313) 555-6732 Total Customers for State: 1 NH Jerry’s Junkyard Specialties Crazy Lakes Cottages Rural Delivery #27 Frogline (612) 555-2877 Total Customers for State: 1 NJ Clair Butterfield 371 Youngstown Blvd Quit Woods Teaneck (201) 555-9901 Total Customers for State: 1 NM Joe Smith and Company 1711 Sunset Blvd East River Big Falls (808) 555-2124 Total Customers for State: 1 NY Alfred E Newman & Company 2837 East Third Street Greenwich Village New York (212) 555-2311 Page 1 of 2 SQR User’s Guide 27 . Address and Phone Number --------.3 Break Logic Output for ex5d.SQR 4.sqr 29-Apr-1996 Customers Listed by State State Customer Name.

3 29-Apr-1996 Customers Listed by State State Customer Name.Break Logic SQR 4. Jamaica New York (212) 555-0021 Eliot Richards 2134 Partridge Ave Jamaica Queens (212) 555-4285 Harriet Bailey 47 Season Street Bellevue Park Mamaroneck (914) 555-0144 Kate’s Out of Date Dress Shop 2100 Park Ave East Side City New York (212) 555-9000 Total Customers for State: OH 5 Gregory Stonehaven Middlebrook Road Grey Quarter Everretsville (216) 555-3109 Isaiah J Schwartz and Company 37211 Columbia Blvd Sweet Acres Zanesville (518) 555-9813 Quentin Fields 37021 Cedar Road Beachwood Cleveland (216) 555-3341 Total Customers for State: 3 Total Customers: 14 Page 2 of 2 28 SQR User’s Guide .---------------------------------------NY Corks and Bottles. 167 East Blvd. Address and Phone Number --------. Inc.

The EDIT argument specifies an edit mask. and strings. see the SQR Language Reference. SQR User’s Guide 29 . if there are fewer than four lines left on a page. the complete command is PRINT $current-date (1.1 of the heading. They are fully described in the SQR Language Reference. In this example. the value of the ON-BREAK column will be printed when it changes and after every page break. then renumbers the current line as line 1. It prints the date and time at position 1.1) EDIT ’DD/MM/YYYY’.3 Break Logic Take a close look at the code. With this qualifier. use PRINT=CHANGE/TOP-PAGE. use the NEXT-LISTING command. In this case. the value of state will be printed not only when it changes. for printing the date. This command serves two purposes. For a complete listing of reserved variables. the reserved variable $current-date is used to print the date and the time. but whenever the report starts a new page. To format records. This variable is initialized with the date and time of the client machine at the start of program execution. The order of processing is explained in the section "Setting Break Procedures with BEFORE and AFTER. dates. you may want to reprint headings and the value of the break column at the top of the new page.SQR 4. SQR provides a large variety of edit masks for use in formatting numbers. variables for a variety of uses. SQR will start a new page. To control the printing of the value. The SKIPLINES=1 argument skips one line between records." on page 31. In this example. The program also uses the argument AFTER=STATE_TOT. This argument calls the state_tot procedure after each change in the value of state. Handling Page Breaks If a page break occurs within a group. SQR provides predefined. or format. The state and the customer name are printed on the first line. The NEED=4 argument prevents a listing from being split over two pages by specifying the minimum number of lines needed to write a new listing on the current page. or reserved. The data is printed using a SELECT paragraph in the list_customers procedure. Printing the Date In the HEADING section. The customer’s address and phone number are printed on the next three lines.

the program calls the state_tot procedure and prints the value of #state_total. one for the subtotals and one for the grand totals. When a new value is assigned to a string variable. The variable #state_total is incremented by 1 for every row selected. which formats the number. numeric and string variables are not explicitly declared. Instead. Their names are #state_total and #cust_total. so the order of these commands doesn’t matter as long as you use the correct print position qualifiers. All numeric variables in SQR are preceded with a pound sign (#) and all string variables are preceded with a dollar sign ($). When the value of state changes. we print the "Page n of m" as we did in earlier examples. An additional SQR variable type is the date variable (see Chapter 20). In the list_customers procedure. Obtaining Totals The program ex5d. Note the use of the edit mask EDIT 999. #state_total and #cust_total are set to zero at the beginning of the procedure. It tells SQR to fill the specified width with this pattern. SQR has a small set of variable types. they are implicitly defined by their first use. In the FOOTING section. These calculations are performed with two numeric variables. All numeric variables start out as zero and all string variables start out as null. The last two commands in the HEADING section print a string of hyphens under the column headings. This initialization is optional and is done for clarity only. so there is normally no need to initialize them.sqr also prints two totals—a subtotal of customers in each state and a grand total of all customers.3 Note that the PRINT command for the report title precedes the command for the $current-date reserved variable. even though the date is on the left and the title is on the right. It’s a good way to print a line. 30 SQR User’s Guide .Break Logic SQR 4. In SQR. its length is automatically adjusted. respectively.999. SQR always assembles a page in memory before printing. The string variables are of varying length and can hold long strings of characters as well as short ones. Note the use of the FILL option of the PRINT command. The most common types are numeric variables and the string variables.

if there is an ELSE part to the IF. Procedure and variable names may contain either a hyphen or underscore. Otherwise. At the end of the procedure. If the expression evaluates to true or to a number other than zero." Hyphens and Underscores You may have noticed that many SQR commands. the query has not returned any data. For example: begin-select state (. such as BEGIN-PROGRAM and BEGIN-SELECT. The list_customers procedure contains an example of SQR’s if-then-else logic. the query has returned rows of data. and the program will print the string "Total Customers: " and the value of #cust_total. It will also prevent confusion when you mix variable names and numbers in an expression. the value of #cust_total is examined. Setting Break Procedures with BEFORE and AFTER When you print variables with ON-BREAK. use a hyphen. those commands are executed. Here. #state_total is reset to zero. The BEFORE and AFTER qualifiers give you this capability. In this case. In that case. LET is used to add the value of #state_total to #cust_total.SQR 4. and it lets you build complex expressions. you can automatically call procedures before and after each break in a column. whereas procedure and variable names use an underscore. IF commands always end with an END-IF.1) on-break before=state_heading after=state_tot SQR User’s Guide 31 . the subsequent commands are executed. LET is the assignment command in SQR.3 Break Logic This procedure also employs the LET command. If #cust_total is equal to zero. where hyphens could be mistaken for minus signs. The condition starts with IF followed by an expression. Using underscores in procedure and variable names will help you distinguish them from SQR commands. the program prints the string "No customers. but we strongly recommend you use an underscore. If it is greater than zero.

city. lines skipped.7) on-break level=2 after=city_tot skiplines=1 zip (. The following SELECT statement has breaks on three levels: begin-select state (.Break Logic SQR 4. particularly where there are multiple ON-BREAK columns. Similarly. All BEFORE procedures are automatically invoked before each break. the AFTER qualifier automatically calls the state_tot procedure to print totals after each group of records. and two lines are skipped after the state_tot procedure is executed. A break on a variable can trigger many other events. including the first—in other words. In the sample program. the city_tot procedure is executed. zip end-select The breaks are processed as follows: 1. state was defined as LEVEL=1 and city as LEVEL=2. When zip breaks. 32 SQR User’s Guide . and the old value saved. city. for example. 2. Understanding the Order of Events You can define a hierarchy of break columns by using the LEVEL qualifier of ON-BREAK.45) on-break level=3 after=zip_tot from customers order by state. city_tot. it also forces breaks on variables with higher LEVEL qualifiers. and state_tot procedures are processed in that order. The value may be printed. before the SELECT is even processed. 3. Both city and zip are printed in the next record. procedures automatically called. It is important to know the order of events. One line is skipped after the city_tot procedure is executed. Similarly.sqr. the zip_tot. then the city_tot procedure is executed.3 The BEFORE qualifier automatically calls the state_heading procedure to print headings before each group of records of the same state.1) on-break level=1 after=state_tot skiplines=2 city (. In ex5c. All three columns—state. When city breaks. When state breaks. and one line is skipped (SKIPLINES=1). upon completion of the SELECT. first the zip_tot procedure is executed. and zip—are printed in the next record. including the last group—in other words. When a break occurs at one level. a break on state also means a break on city. all AFTER procedures are invoked after each break.

40) end-procedure begin-procedure b print ’AFTER Procedure city LEVEL 2’ (+1. It has three ON-BREAK columns. each with a LEVEL argument and a BEFORE and AFTER procedure.sqr begin-setup declare-Layout default end-declare end-setup begin-program do main end-program begin-procedure a print ’AFTER Procedure for state LEVEL 1’ (+1.sqr) demonstrates the order of events in break processing.40) end-procedure begin-procedure aa print ’BEFORE Procedure state LEVEL 1’ (+1.SQR 4.40) end-procedure The program continues on the following page. SQR User’s Guide 33 . Program ex5e. The BEFORE and AFTER procedures print strings to indicate the order of processing.40) end-procedure begin-procedure cc print ’BEFORE Procedure zip LEVEL 3’ (+1.40) end-procedure begin-procedure c print ’AFTER Procedure zip LEVEL 3’ (+1.40) end-procedure begin-procedure bb print ’BEFORE Procedure city LEVEL 2’ (+1.3 Break Logic The following program (ex5e.

1) On-Break Level=1 after=a before=aa city (3.city.Break Logic SQR 4.3 Program ex5e.sqr (continued) begin-procedure main local begin-select add 1 to #count print ’Retrieved row #’ (+1.10) On-Break Level=2 after=b before=bb zip (3.25) print ’Break Processing sequence’ (3.10) print ’ZIP’ (3.zip end-select end-procedure begin-heading 3 print $current-date (1.25) On-Break Level=3 after=c before=cc Edit xxxxx next-listing Need=10 from customers order by state.60) ’Page ’ last-page () ’ of ’ print ’STATE’ (3.1) edit ’DD-MM-YYYY’ page-number (1.40) print #count (.40) end-heading The output is shown on the following pages.1) print ’CITY’ (3. 34 SQR User’s Guide .+10)Edit 9999 position (+1) state (3.

SQR 4.3 Break Logic Output for ex5e.sqr 02-05-1996 STATE IN CITY Davenport ZIP 62130 Page 1 of 3 Break Processing sequence BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # 1 Retrieved row # Miningville 40622 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # MI Bell Harbor 40674 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # NH Frogline 04821 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # NJ Teaneck 00355 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # NM Big Falls 87893 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 6 5 4 3 2 SQR User’s Guide 35 .

Break Logic SQR 4.3 02-05-1996 STATE NY CITY Mamaroneck ZIP 10833 Page 2 of 3 Break Processing sequence Retrieved row # 7 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # New York 10002 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # 10134 AFTER Procedure zip LEVEL 3 BEFORE Procedure zip LEVEL 3 Retrieved row # 10204 AFTER Procedure zip LEVEL 3 BEFORE Procedure zip LEVEL 3 Retrieved row # Queens 10213 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # OH Cleveland 44121 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 BEFORE Procedure state LEVEL 1 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 Retrieved row # Everretsville 40233 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 13 12 11 10 9 8 36 SQR User’s Guide .

the current line position is advanced. Select Subsequent Rows of Data Processing of the SELECT continues. Events occur in the following order: 1. 5. When a break occurs on any column.SQR 4. AFTER procedures are processed in descending order from the highest level to the level of the current ON-BREAK column. Step 1. 4. The value of the new group is printed (unless PRINT=NEVER is specified). SAVE variables are set with the value of the previous ON-BREAK column. Step 3. Process BEFORE Procedures BEFORE procedures are processed in ascending order by LEVEL before the first row of the query is retrieved. If no data is selected. BEFORE procedures are processed in ascending order from the current level to the highest level.3 Break Logic 02-05-1996 STATE CITY Zanesville ZIP 44900 Page 3 of 3 Break Processing sequence Retrieved row # 14 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 BEFORE Procedure city LEVEL 2 BEFORE Procedure zip LEVEL 3 AFTER Procedure zip LEVEL 3 AFTER Procedure city LEVEL 2 AFTER Procedure for state LEVEL 1 The following steps explain the order of processing in detail. Select First Row of Data The first row of data is selected. Step 2. SQR User’s Guide 37 . If SKIPLINES was specified. BEFORE procedures are not executed. See "Saving a Value When a Break Occurs. it also triggers breaks on columns at the same or higher levels." below. for an explanation of the SAVE argument. 3. 2.

• Avoid using WRAP and ON-BREAK together on one column.3 Step 4. Simply printing the value of state will not work because its value will have changed by the time the AFTER procedure is called. you may wish to print the previous value of the ON-BREAK column in the AFTER procedure. For example. the state_tot procedure prints the total number of customers per state. To do this. Sometimes. this procedure is executed only after the value of the ON-BREAK column. has changed. if any rows were selected. AFTER procedures are processed in descending order by LEVEL. you probably would not want to have one within a record. Process AFTER Procedures After the SELECT is complete. • Use the same line positions for all ON-BREAK columns. The answer is to save the previous break value in a string variable. you may want to print the state name along with the totals for each state.sqr. however. For example: begin-select state (. use the SAVE qualifier of ON-BREAK. 38 SQR User’s Guide .Break Logic SQR 4. You can prevent page breaks within a record by following four simple rules: • Place ON-BREAK columns ahead of other columns in your SELECT statement. Because it is called with the AFTER argument. state.1) on-break after=state_tot save=$old_state You can then print the value of $old_state in the state_tot procedure. page breaks call for careful planning. • Place the lower-level ON-BREAK columns ahead of the higher-level ON-BREAK columns in your SELECT statement. While it may be acceptable to have a page break within a group. Controlling Page Breaks with Multiple ON-BREAK Columns Where there are multiple columns with ON-BREAK. Saving a Value When a Break Occurs In ex5d.

name end-select end-procedure ! list_customers begin-procedure state_heading print ’State: ’ (+1.sqr begin-program do list_customers end-program begin-procedure list_customers begin-select state () on-break before=state_heading print=never level=1 city (.58) fill position (+1) ! Advance to the next line end-procedure ! state_heading Note that this program has no HEADING section.1) on-break level=2 name (. a procedure prints column headings for each state rather than at the top of each page. For example.1) bold ! Advance a line and print ’City’ print ’Name’ (.49) bold print ’-’ (+1.1. SQR User’s Guide 39 . The way to create such a report is to "hide" the break variable with the PRINT=NEVER qualifier and print it in a heading procedure called by BEFORE. The following code is based on the program ex5b. This format might make your report more readable. It is also useful when you want to leave room on the page for additional columns. you may want to incorporate the ON-BREAK variable into a subheading.18) phone (. Instead. you may want to use the features of break processing without printing the ON-BREAK variable.sqr.18) bold print ’Phone’ (.8) bold ! Print the state column here print ’City’ (+1.49) position (+1) ! Advance to the next line from customers order by state. city.SQR 4. Program ex5f.1) bold ! Advance a line and print ’State:’ print &state (.3 Break Logic Using ON-BREAK on a Hidden Column In some reports. The key lines are shown in bold.

The city column is assigned a LEVEL=2 break. Instead.3 Note also that the &state variable can be referenced throughout the program. this break is set to LEVEL=1. The most interesting line in the program is this one from the SELECT statement: state () on-break before=state_heading print=never level=1 This line defines the break processing for state. The output is shown below. even though the state column was not printed as part of the break. The BEFORE qualifier specifies that the state_heading procedure will be called automatically before each change in state. The PRINT=NEVER qualifier makes the state column a hidden column and specifies that it won’t be printed as part of the SELECT statement. it is printed in the state_heading procedure. 40 SQR User’s Guide . In this procedure.Break Logic SQR 4. the state column is referred to as the column variable &state. In this program.

If you need to perform break processing on a numeric variable. you must first move its value to a string variable and set ON-BREAK on that. 2125550021 Kate’s Out of Date Dress Shop 2125559000 Queens Eliot Richards 2125554285 State: OH City Name Phone ---------------------------------------------------------Cleveland Quentin Fields 2165553341 Everretsville Gregory Stonehaven 2165553109 Zanesville Isaiah J Schwartz and Company 5185559813 Restrictions and Limitations of ON-BREAK ON-BREAK cannot be used with SQR numeric variables.sqr State: IN City Name Phone ---------------------------------------------------------Davenport Harold Alexander Fink 3015553645 Miningville Harry’s Landmark Diner 3175550948 State: MI City Name Phone ---------------------------------------------------------Bell Harbor Sam Johnson 3135556732 State: NH City Name Phone ---------------------------------------------------------Frogline Jerry’s Junkyard Specialties 6125552877 State: NJ City Name Phone ---------------------------------------------------------Teaneck Clair Butterfield 2015559901 State: NM City Name Phone ---------------------------------------------------------Big Falls Joe Smith and Company 8085552124 State: NY City Name Phone ---------------------------------------------------------Mamaroneck Harriet Bailey 9145550144 New York Alfred E Newman & Company 2125552311 Corks and Bottles. For example: SQR User’s Guide 41 .SQR 4. Inc.3 Break Logic Output for ex5f.

• The SAVE qualifier saves the value of a previous group to a variable. • The SET and LEVEL qualifiers. but you may increase this setting. • The SQR reserved variable $current-date holds the current date and time.INI. such as the state column in a listing of customer addresses. Its maximum value is 64K-1 (65.999. Summary • PRINT ON-BREAK performs special processing when a value changes. • LET is the SQR assignment command. For more information on SQR. • SQR provides numeric.535). The default is 30. • ON-BREAK LEVEL arranges breaks hierarchically. Numeric variables are preceded with a pound sign (#) and start out as 0.99 print $amount (+1.3 begin-select amount_received &amount move &amount to $amount $$9.Break Logic SQR 4. and date variables. • PRINT=CHANGE/TOP-PAGE prints a column after a page break or after a change in the column’s value. see the SQR Language Reference.1) on-break from cash_receipts order by amount_received end-select The maximum number of ON-BREAK levels is determined by the ON-BREAK setting in the [Processing-Limits] section of the SQR. • The BEFORE and AFTER arguments set break procedures. in conjunction with BEFORE and AFTER. • ON-BREAK SKIPLINES inserts space between groups of records. There is no need to initialize either variable type. String variables are preceded with a dollar sign ($) and start out as null. determine the order of events.INI file. string. • NEXT-LISTING keeps a group of lines on the same page. It allows you to build expressions. 42 SQR User’s Guide .

SQR User’s Guide 43 .INI file determines the maximum number of ON-BREAK levels in a program.SQR 4. • The ON-BREAK setting in the SQR. If you need to perform break processing on a numeric variable. you must first move its value to a string variable and set ON-BREAK on that. For more information on the ON-BREAK argument. see the PRINT command in the SQR Language Reference. The next chapter describes the SETUP section of an SQR program.3 Break Logic • ON-BREAK cannot be used with SQR numeric variables.

6

The SETUP Section
This chapter introduces the SQR SETUP section. This section is not required in a program, but it is very useful. The SETUP section holds all the declarations. Declarations define certain report characteristics and the source and attributes of various report components, such as charts and images. The SETUP section is evaluated when your program is compiled. The SETUP section, if present, is typically placed at the top of the program before the PROGRAM section. It begins with BEGIN-SETUP and ends with END-SETUP. The following commands can be issued in the SETUP section. If used, they are processed at compile time, before the program begins executing. For more information about the following commands, see the SQR Language Reference.

Command
ALTER-LOCALE ASK BEGIN-SQL CREATE-ARRAY DECLARE-CHART DECLARE-IMAGE DECLARE-LAYOUT DECLARE-PRINTER DECLARE-PROCEDURE DECLARE-REPORT DECLARE-TOC DECLARE-VARIABLE LOAD-LOOKUP USE

Comments
Can also appear in a procedure. Allowed only in SETUP section. Can also appear in a procedure. Executed when a run-time file (.SQT) is loaded. Can also appear in a procedure.

Can also appear in a local procedure. Can also appear in a procedure. SYBASE only.

Table 2. Commands Available in the SETUP Section

SQR User’s Guide

45

The SETUP Section

SQR 4.3

Using DECLARE-LAYOUT
One common declaration used in the SETUP section is the DECLARE-LAYOUT command. This command sets the page layout and includes such important options as the paper size and margins. Here is a typical SETUP section:
begin-setup ! Declare the default layout for this report declare-layout default paper-size=(8.5,11) left-margin=1 right-margin=1 top-margin=1 bottom-margin=1 end-declare end-setup

In the above example, the DECLARE-LAYOUT command sets the paper size to 8 1/2 by 11 inches, with all margins at 1 inch. In SQR, data is positioned on the page using line and character position coordinates. Think of the page as a grid where each cell holds one character. With such a grid, in a position qualifier consisting of (line,column,width), column and width are numbers that denote characters and spaces. The SQR page layout is shown below:
Character width Paper size (width) Top margin

Line height Paper size (height)

Right margin

Left margin

Bottom margin

46

SQR User’s Guide

SQR 4.3

The SETUP Section

The diagram shows how the main attributes of the DECLARE-LAYOUT command affect the structure of the page. The PAPER-SIZE argument defines the dimensions of the entire page, including margins. The arguments TOP-MARGIN, LEFT-MARGIN, BOTTOM-MARGIN, and RIGHT-MARGIN define the margins. In SQR, you cannot print in the margins. In the sample code above, the left margin will use 10 spaces and the top margin will use 6 lines. The page width will accommodate 65 characters (without the margins) and 54 lines. The default mapping of characters and lines to inches is 10 CPI (characters per inch) and 6 LPI (lines per inch). This means that each character cell is 1/10 inch wide and 1/6 inch high. These settings are used when a program does not contain a DECLARE-LAYOUT command. You can override the default settings by using the LINE-HEIGHT and CHAR-WIDTH arguments in the DECLARE-LAYOUT command. These arguments will adjust the dimensions of the grid, which implies a change in the meaning of column and line. If your DECLARE-LAYOUT paragraph includes the arguments LINE-HEIGHT=1 and CHAR-WIDTH=1, the cells in the grid will measure 1 point by 1 point (1 point = 1/72 inch or approx. 0.35 mm). In that case, column will be a dimension given in points. The length of a string, however, will still be given in characters. Alternatively, you can use the MAX-LINES and MAX-COLUMNS arguments of the DECLARE-LAYOUT command to specify the number of lines on the page and the number of characters to fit across the page. SQR will calculate the line height and character width based on these settings and the size of the page and margins. Coordinates are specified in terms of lines and character positions. The first line from the top is 1 and the first column (from the left) is 1. There is no coordinate 0. The DECLARE-LAYOUT command also allows you to declare the page orientation. Note that this declaration does not affect how SQR uses position coordinates. Line and character positions are not transposed when page orientation is switched. The only effect of the ORIENTATION option of the DECLARE-LAYOUT command is that SQR will switch the printer to the specified orientation, portrait or landscape. The default mode is portrait.

SQR User’s Guide

47

The SETUP Section

SQR 4.3

Summary
• The SETUP section holds declarations and several commands. Most commands in the SETUP section are performed at compile time. • DECLARE-LAYOUT sets the page layout and includes such important options as the paper size and margins.
The next chapter explains how to create a master/detail report, which combines information from multiple tables.

48

SQR User’s Guide

this type of report will not meet your needs." to group the detail records for each master record. which show hierarchical information. In our example. two additional BEGIN-SELECT commands are performed. followed by separate SELECT statements that retrieve the detail records associated with each master record. the data from the master table is joined with data from the detail table. it will not be displayed. You can implement break logic as described in Chapter 5.7 Master/Detail Reports This chapter presents master/detail reports. one BEGIN-SELECT returns the names of customers. The code example in this chapter produces just such a report. one to retrieve order information and another to retrieve payment information. In such a program. "Break Logic. This type of report has one major disadvantage—if a master record has no associated detail records. The following diagram depicts the BEGIN-SELECT structure in this example: Customers Orders Payments SQR User’s Guide 49 . The customer information is the "master" and the orders are the "detail. The solution is to create a master/detail report with one SELECT that retrieves records from the master table. The information is normally retrieved from multiple tables that have a one-to-many relationship. For each customer." In many cases. such as customers and orders. you can obtain such information with a single SQR SELECT statement. whether they have detail records or not. If you need to show all master records.

1.10.+1.45) Fill name (+1. each one retrieving records that correspond to the current customer.20) edit ’DD-MON-YY’ amount_received (. In our sample program.+1.2) cust_num do cash_receipts(&cust_num) do orders(&cust_num) position (+2.99 from cash_receipts a where a.1) Print ’-’ (+1." for a more detailed explanation of bind variables.10) let #any = 1 end-if date_received (+1. one query returns customer names and two nested queries return detail information. The nested queries are invoked once for each customer. The subqueries are correlated with a bind variable in the WHERE clause. This variable correlates the customer number (cust_num) with the current customer record.) Program ex7a.25) city (. (See Chapter 16.3 When one query returns master information and another query returns detail information.13) Edit $$$$.Master/Detail Reports SQR 4. 50 SQR User’s Guide .sqr begin-program do main end-program begin-procedure main begin-select Print ’Customer Information’ (.1) from customers end-select end-procedure ! main begin-procedure cash_receipts (#cust_num) let #any = 0 begin-select if not #any print ’Cash Received’ (+2.$$0.10) print ’-------------’ (+1.cust_num = #cust_num end-select end-procedure ! cash_receipts Program continues on the following page. the detail query is nested within the master query.16) state (. "Dynamic SQL and Error Checking.1.+1.

" As you can see.$$0.order_num and b.product_code and a. which correspond to the three queries.+1.10) let #any = 1 end-if a.price * b. if there are any. SQR will not execute the following PRINT commands. "Procedures.order_num order_date (+1. the headings for these procedures are only displayed for those customers who have records in the detail tables.13) Edit $$$$. This feature is discussed in more detail in Chapter 17.1) Edit ’DD-MON-YYYY’ page-number (1.20) Edit ’DD-MON-YY’ description (.20) c. and orders.69) ’Page ’ end-heading Correlating Subqueries The above program consists of three procedures. and orders to list the customer’s orders.quantity (. we invoke the procedures cash_receipts to list the cash receipts.cust_num = #cust_num end-select end-procedure ! orders begin-heading 3 print $current-date (1. cash_receipts.+1. It retrieves the customer names. The procedure main is the master. Each time. Thus. When the BEGIN-SELECT command returns no records. SQR User’s Guide 51 . The procedures take the variable cust_num as an argument. once for each customer.10. Note the use of the IF command and the numeric variable #any in these procedures.product_code = c. if there are any.sqr (continued) begin-procedure orders (#cust_num) let #any = 0 begin-select if not #any print ’Orders Booked’ (+2. main.SQR 4. Argument Passing.3 Master/Detail Reports Program ex7a. For each customer. ordlines b.10) print ’-------------’ (+1. and Local Variables. cash_receipts and orders are called many times. the procedures perform the same query with a different value for the cust_num variable in the WHERE clause. products c where a.order_num = b.99 from orders a.

980.19 $3.25 Output continues on the following page. 52 SQR User’s Guide .3 The procedure orders demonstrates the use of an expression in the BEGIN-SELECT.99. If there are fewer digits than the six that we allowed here. "Working with Dates. À Note See Chapter 20. Output for ex7a.sqr 26-APR-1996 Page 1 Customer Information --------------------------------------------Gregory Stonehaven Everretsville OH Cash Received ------------01-FEB-94 $130. The expression is c.00 Customer Information --------------------------------------------Alfred E Newman & Company New York NY Cash Received ------------01-MAR-94 $140.00 Whirlybobs Canisters $239.quantity.price * b. the dollar sign will float to the right and stay close to the number." for more information on formatting dates. Finally.12 $260." This format uses a "floating-to-the-right" money symbol.00 Customer Information --------------------------------------------Eliot Richards Queens NY Cash Received ------------16-JAN-94 17-JAN-94 Orders Booked ------------02-MAY-94 02-MAY-94 $220.Master/Detail Reports SQR 4.$$0. note that the format given to the dollar amount with the argument EDIT "$$$$.

sqr Customer Information --------------------------------------------Isaiah J Schwartz and Com Zanesville OH Cash Received ------------18-JAN-94 02-JAN-94 Orders Booked ------------02-MAY-94 02-MAY-94 $190. • Subqueries are joined to the main query by use of bind variables.00 Ginger snaps Modeling clay $44.00 $19.90 Customer Information --------------------------------------------Harold Alexander Fink Davenport IN Cash Received ------------01-FEB-94 01-MAR-94 Orders Booked ------------19-MAY-94 19-MAY-94 $1.SQR 4.872.300. • Queries that retrieve detail information are said to be nested in the queries that retrieve master information.902.00 Hop scotch kits Wire rings $6.28 $517. SQR User’s Guide 53 .00 $1.3 Master/Detail Reports Output for ex7a.00 $1.05 Summary • Multiple BEGIN-SELECT commands can be used to retrieve detail information that is contained in different database tables.100.200. The next chapter describes how to create cross-tabular reports and assemble data in an SQR array.

.

The three middle columns correspond to sales channel categories.222 $1.-----------.8 Cross-Tabular Reports This chapter presents cross-tabular reports.------Total $2. Some groups have no sales (such as mail order for Product A). The records fall into nine groups: three products sold through three sales channels. A category may also represent a range. SQR User’s Guide 55 . Cross-tabular reports vary in format.--------.520 $1.100 $1.----------. These reports are useful for presenting summary numeric data. as demonstrated in the next example: Orders by Product by Product Category Less than 10 10 to 100 ----------. Products are classified as durable and nondurable. Resellers can be domestic resellers plus international distributors.443 $5. For example. which shows sales revenue summarized by product by sales channel: Revenue by Product by Sales Channel Product Direct Sales Resellers Mail Order Total ---------.------0 320 924 1876 ------------.309 B $120 $311 $519 $950 C $2 $0 $924 $926 ---------.-----------.--------Durable 200 120 Nondurable 122 311 ----------. The columns represent categories that are ranges of order size.185 This report is based on many sales records.------A $2.----------.-----------.209 $0 $3.or spreadsheet-like reports.--------. which are matrix.-----------. the rows correspond to nondiscrete categories.------1443 2196 In this example.--------Total 322 431 Order Size More than 100 Total ------------. Each category may be a discrete value of some database column or a set of values. Look at the following example. Each row corresponds to a product.

but it exists only in memory." This example demonstrates an SQR feature called a "three-dimensional array. therefore. the row number. The data can even be presented in a chart. an array called order_qty is created to hold the sum of the quantity of orders in a given month. The subscript can be a literal or an SQR numeric variable." It has fields (columns) and rows. Repeating fields are also numbered starting with zero.sub2]). The numbers in the cells are counts. In the next sample program. but they could be sums. the program must determine the range to which it belongs and add 1 to the count for that category. but as you will see later. the program must process all the records before it can begin printing the data. The second field is the order quantity of each month. this field occurs (repeats) three times. Arrays In a many cases. the program needs to keep the data in some buffer where it can accumulate the numbers. using one can be beneficial. This specific example could be programmed without an array. averages. and it also has repeating fields (the "third dimension"). An array is similar to a database table. or any other expression. Sub1 is the first subscript. The second subscript (sub2) is specified when the field repeats. the first field is the product description. An array is a unit of storage that consists of rows and columns and exists in memory. There are three months in the example. During the processing. In the order_qty array. These reports become more complex when the number of columns is not predefined and when there are more columns than can fit across the page. SQR arrays are referenced in expressions as array_name. as we will see later in Chapter 13. Rows are numbered starting with zero.3 For each record selected. This can be done in an SQR array. Of course.Cross-Tabular Reports SQR 4. "Business Charts. Data retrieved once and stored in an array can be presented in many ways without additional database queries. there are other types of cross-tabular reports.field(sub1[. 56 SQR User’s Guide .

9) edit 9.999.999.1.9) edit 9.3 Cross-Tabular Reports Program ex8a.0) let #feb = order_qty.999 print #prod_tot (.sqr #define max_products 100 begin-setup create-array name=order_qty field=product:char end-setup begin-program do select_data do print_array end-program begin-procedure print_array let #entry_cnt = #i let #i = 0 while #i <= #entry_cnt let $product = order_qty.999 print #grand_total (.999 print #mar_total (.999 print #feb (.9) edit 9.1) print #jan_total (.999.9) edit 9.999.42.product(#i) let #jan = order_qty.999.999 print #mar (.30) print #jan (.999.9) edit 9.52. SQR User’s Guide 57 .999 print #feb_total (.999.month_qty(#i.999 end-procedure print_array size={max_products} field=month_qty:number:3 Program continues on the following page.62.999 position (+1) let #jan_total = #jan_total + #jan let #feb_total = #feb_total + #feb let #mar_total = #mar_total + #mar let #i = #i + 1 end-while let #grand_total = #jan_total + #feb_total + #mar_total print ’Totals’ (+2.month_qty(#i.32.9) edit 9.999.month_qty(#i.2) let #prod_tot = #jan + #feb + #mar print $product (.62.32.9) edit 9.1) let #mar = order_qty.9) edit 9.42.SQR 4.52.

1) print ’ January’ (. ordlines b.64) ’Page ’ print ’Product’ (3.order_num = b.product(#i) = &description end-if if order_qty.52) print ’ Total’ (.product(#i) = ’’ let order_qty. products c where a.order_num and b.1.’MM’)) .1) print ’Order Quantity by Product by Month’ (1.32) print ’ February’ (.product(#i) = &description end-if let #j = to_number(datetostr(&order_date.month_qty(#i.3 Program ex8a.42) print ’ March’ (.Cross-Tabular Reports SQR 4.18) page-number (1.#j) = order_qty.product_code = c.product_code order by description end-select end-procedure ! select_data begin-heading 4 print $current-date (1.70) Fill end-heading 58 SQR User’s Guide .1 if #j < 3 let order_qty.month_qty(#i.#j) + &quantity end-if from orders a.62) print ’-’ (4.product(#i) != &description let #i = #i + 1 if #i >= {max_products} display ’Error: There are more than {max_products} products’ stop end-if let order_qty.sqr (continued) begin-procedure select_data begin-select order_date ! The quantity for this order quantity ! the product for this order description if #i = 0 and order_qty.

All SQR arrays are created before the program begins executing. (The 'MM' edit mask specifies that only the month part will be converted. the program checks to see if it’s a new product. It is a good practice to use #DEFINE because it displays our limit at the top of the program source. The command #DEFINE MAX_PRODUCTS 100 defines the constant max_products as a substitution variable. which are the records ordered by the product description. The program creates the array order_qty with a size of 100. the procedure print_array does two things: It loops through the array and prints the data. as its name suggests. The report summarizes the product order quantities for each month.SQR 4. even though the program only uses 12 rows to process the sample data. and is added to the array. Select_data performs the database query. it would be buried in the code. SQR User’s Guide 59 . There is one complication with this program—how to obtain the month. Their size must be known at compile time. In the example. It then fills the array one product at a time. For each record selected. Otherwise.1 This function converts the order_date column into a string. When the processing is over. you must over-allocate and specify an upper bound. While the database records are being processed. The key is the datetostr function in the following command: let #j = to_number(datetostr(&order_date. ’MM’)) . it represents January. and to write truly portable code calls for careful planning. It also adds up the month totals and prints them at the bottom. The program also adds the quantity to the corresponding entry in the array based on the month. if it is. The SETUP section creates the array using the CREATE-ARRAY command. nothing is printed. if it is less than 3.) The resulting string is then converted to a number. Date manipulation can vary among databases. The above program has two procedures: select_data and print_array. or March. and the data accumulates in the array. the array is incremented by row subscript #i. The sample program uses this constant to define the size of the array.3 Cross-Tabular Reports Creating the Array You must define the size of an array when you create it. the array has 100 rows. February. If you do not know exactly how many rows you will have.

The example shows how to do it without sorting the data. to process the records in order of price category. or 2. Then it adds the order quantity to the array cell that corresponds to the price category (row) and the month (column).3 Grouping by Category The next example is a cross-tabular report that groups the products by price range. the program would have to sort the table by price.sqr 11-JUN-96 Order Quantity by Product by Month Page 1 Product January February March Total ---------------------------------------------------------------------Canisters 3 0 0 3 Curtain rods 2 8 18 28 Ginger snaps 1 10 0 11 Hanging plants 1 20 0 21 Hookup wire 16 15 0 31 Hop scotch kits 2 0 0 2 Modeling clay 5 0 0 5 New car 1 9 0 10 Thimble 7 20 0 27 Thingamajigs 17 0 120 137 Widgets 4 0 12 16 Wire rings 1 0 0 1 Totals 60 82 150 292 60 SQR User’s Guide . The program uses an SQR EVALUATE command to determine the price category and assign the array subscript #i to 0. 1.Cross-Tabular Reports SQR 4. Output for ex8a. Moreover. This grouping cannot be done using a SQL GROUP BY clause.

month_qty(#i.month_qty(#i.9) edit 9.999.62.9) edit 9.9) edit 9.999.SQR 4.9) edit 9.00’ let order_qty.999.42.999.1) print #jan_total (.999 print #feb_total (. SQR User’s Guide 61 .999 print #mar (.00-$100.42.999 print #feb (.month_qty(#i.category(#i) let #jan = order_qty.category(1) = ’$5.999 print #mar_total (.999.31) print #jan (.9) edit 9.2) let #category_tot = #jan + #feb + #mar print $category (.0) let #feb = order_qty.1) let #mar = order_qty.9) edit 9.9) edit 9.sqr #define max_categories 3 begin-setup create-array name=order_qty field=category:char end-setup begin-program do select_data do print_array end-program begin-procedure print_array let #i = 0 while #i < {max_categories} let $category = order_qty.32.category(0) = ’$0-$4.9) edit 9.99’ let order_qty.52.52.999 print #grand_total (.999 end-procedure print_array begin-procedure select_data let order_qty.category(2) = ’Over $100’ size={max_categories} field=month_qty:number:3 Program continues on the following page.999 position (+1) let #jan_total = #jan_total + #jan let #feb_total = #feb_total + #feb let #mar_total = #mar_total + #mar let #i = #i + 1 end-while let #grand_total = #jan_total + #feb_total + #mar_total print ’Totals’ (+2.999.999 print #category_tot (.62.32.1.3 Cross-Tabular Reports Program ex8b.999.999.

month_qty(#i.Cross-Tabular Reports SQR 4.32) print ’ February’ (.0 let #i = 0 break when <= 100.order_num = b.#j) = order_qty.42) print ’ March’ (. ordlines b.sqr (continued) begin-select order_date ! the price / price category for the order c.70) Fill end-heading The output is shown on the following page.0 let #i = 1 break when-other let #i = 2 break end-evaluate ! The quantity for this order quantity let #j = to_number(datetostr(&order_date.product_code = c.64) ’Page ’ print ’Order Quantity by Product Price Category by Month’ (2.month_qty(#i. products c where a.3 Program ex8b.product_code end-select end-procedure ! select_data begin-heading 5 print $current-date (1.’MM’)) .1) page-number (1.62) print ’-’ (5.11) print ’Product Price Category’ (4. 62 SQR User’s Guide .1.1 if #j < 3 let order_qty.price &price move &price to #price_num evaluate #price_num when < 5.#j) + &quantity end-if from orders a.52) print ’ Total’ (.order_num and b.1) print ’ January’ (.

sqr #define max_categories 3 #define max_products 100 begin-setup create-array name=order_qty field=product:char create-array name=order_qty2 field=category:char end-setup size={max_products} field=month_qty:number:3 size={max_categories} field=month_qty:number:3 Program continues on the following page. SQR User’s Guide 63 .sqr 11-JUN-96 Order Quantity by Product Price Category by Month Product Price Category January February March Total ---------------------------------------------------------------------$0-$4.SQR 4. you saw how it eliminated the need to sort the data. In the last example. two arrays are created—one to summarize monthly orders by product.99 28 45 12 85 $5. Program ex8c. and another to summarize monthly orders by price range.3 Cross-Tabular Reports Output for ex8b.00-$100. Another advantage is that you can combine the two sample reports into one. The next sample program performs the work done by the first two programs. With one pass on the data.00 25 28 138 191 Over $100 7 9 0 16 Totals 60 82 150 292 Page 1 Using Multiple Arrays Using SQR arrays to buffer the data offers several advantages. In the SETUP section. you can fill the two arrays and then print the two parts of the report.

999.42.1) let #mar = order_qty2.30) print #jan (.9) edit 9.999.31) print #jan (.1) print #jan_total (.52.9) edit 9.9) edit 9.month_qty(#i.9) edit 9.9) edit 9.999 print #category_tot (.42.999.62.32.52.999.month_qty(#i.999.0) let #feb = order_qty2.999 print #mar (.999.999.42.category(#i) let #jan = order_qty2.32.1.62.month_qty(#i.999.9) edit 9.62.999 print #feb (.999 position (+1) let #jan_total = #jan_total + #jan let #feb_total = #feb_total + #feb let #mar_total = #mar_total + #mar let #i = #i + 1 end-while let #grand_total = #jan_total + #feb_total + #mar_total print ’Totals’ (+2. 64 SQR User’s Guide .1.2) let #prod_tot = #jan + #feb + #mar print $product (.0) let #feb = order_qty.999 print #grand_total (.999 print #feb (.month_qty(#i.month_qty(#i.999.9) edit 9.9) edit 9.9) edit 9.999.999.999 print #mar (.70) fill position (+1) do print_array2 end-program begin-procedure print_array let #entry_cnt = #i let #i = 0 while #i <= #entry_cnt let $product = order_qty.Cross-Tabular Reports SQR 4.sqr (continued) begin-program do select_data do print_array print ’-’ (+2.999 print #prod_tot (.1.32.9) edit 9.2) let #category_tot = #jan + #feb + #mar print $category (.9) edit 9.3 Program ex8c.1) let #mar = order_qty.999 print #feb_total (.9) edit 9.52.product(#i) let #jan = order_qty.999.999 end-procedure ! print_array2 Program continues on the following page.999 position (+1) let #i = #i + 1 end-while end-procedure ! print_array begin-procedure print_array2 let #i = 0 while #i < {max_categories} let $category = order_qty2.month_qty(#i.999 print #mar_total (.

category(1)=’$5. products c where a.order_num = b.00’ let order_qty2.1 if #j < 3 let order_qty2.price &price move &price to #price_num evaluate #price_num when < 5.#j) + &quantity end-if ! the product for this order description if #i = 0 and order_qty. ordlines b.SQR 4.product_code order by description end-select end-procedure ! select_data Program continues on the following page.product_code = c.3 Cross-Tabular Reports Program ex8c.category(0)=’$0-$4.product(#i) = ’’ let order_qty.month_qty(#i.month_qty(#i.category(2)=’Over $100’ begin-select order_date ! the price / price category for the order c.#j) = order_qty2.product(#i) = &description end-if if #j < 3 let order_qty.product(#i) = &description end-if if order_qty.month_qty(#x.0 let #x = 0 break when <= 100.order_num and b.sqr (continued) begin-procedure select_data let order_qty2.product(#i) != &description let #i = #i + 1 if #i >= {max_products} display ’Error: There are more than {max_products} products’ stop end-if let order_qty.0 let #x = 1 break when-other let #x = 2 break end-evaluate ! The quantity for this order quantity let #j = to_number(datetostr(&order_date.#j) = order_qty.month_qty(#x.99’ let order_qty2.00-$100.#j) + &quantity end-if from orders a. SQR User’s Guide 65 .’MM’)) .

" 66 SQR User’s Guide .99 28 45 12 85 $5.32) print ’ February’ (. For more information on charts.64) ’Page ’ print ’Order Quantity by Product and Price Category by Month’ (2.sqr 11-JUN-96 Page 1 Order Quantity by Product and Price Category by Month Product / Price Category January February March Total ---------------------------------------------------------------------Canisters 3 0 0 3 Curtain rods 2 8 18 28 Ginger snaps 1 10 0 11 Hanging plants 1 20 0 21 Hookup wire 16 15 0 31 Hop scotch kits 2 0 0 2 Modeling clay 5 0 0 5 New car 1 9 0 10 Thimble 7 20 0 27 Thingamajigs 17 0 120 137 Widgets 4 0 12 16 Wire rings 1 0 0 1 ---------------------------------------------------------------------$0-$4.00-$100.sqr (continued) begin-heading 5 print $current-date (1.00 25 28 138 191 Over $100 7 9 0 16 Totals 60 82 150 292 SQR arrays are also advantageous in programs that produce charts. see Chapter 13. presenting the above cross-tab as a bar chart is easy.3 Program ex8c.Cross-Tabular Reports SQR 4.1) page-number (1.62) print ’-’ (5.10) print ’Product / Price Category’ (4.1. "Business Charts.42) print ’ March’ (.52) print ’ Total’ (.70) Fill end-heading Output for ex8c. With the data for the chart already in the array.1) print ’ January’ (.

• Procedures can be written to select data for an array and print it.or spreadsheet-like reports that are useful for presenting summary data. • CREATE-ARRAY can be used to assemble data for a report in arrays.SQR 4.3 Cross-Tabular Reports Summary • Cross-tabular reports are matrix. • EVALUATE can be used to place data in the correct row of the array. The next chapter explains how to use SQR to print mailing labels or other data in columns. • Arrays can be referenced in expressions. • Using multiple arrays can allow you to reduce database calls. SQR User’s Guide 67 .

.

A SQR SELECT paragraph retrieves the addresses and prints them on the page. Program ex9a. The process is quite simple. in conjunction with NEXT-LISTING. It also counts the number of labels printed and prints that number on the last sheet of the report.9 Printing Mailing Labels This chapter explains how to print mailing labels and similar information. The page then becomes a matrix of rows and columns of labels.11) left-margin=0. SQR User’s Guide 69 . The following program prints mailing labels in a format of three columns by ten rows.sqr #define MAX_LABEL_LINES #define LINES_BETWEEN_LABELS 10 3 begin-setup declare-layout default paper-size=(10. Sometimes you’ll need to print labels in multiple columns. SQR allows you to print into columns with the commands COLUMNS and NEXT-COLUMN.33 end-declare end-setup begin-program do mailing_labels end-program begin-procedure mailing_labels let #label_count = 0 let #label_lines = 0 columns 1 29 57 ! enable columns alter-printer font=5 point-size=10 Program continues on the following page.

1) print $current-date () print ’Total labels printed = ’ (+1.30) next-column at-end=newline add 1 to #label_count if #current-column = 1 add 1 to #label_lines if #label_lines = {MAX_LABEL_LINES} new-page let #label_lines = 0 else next-listing no-advance skiplines={LINES_BETWEEN_LABELS} end-if end-if from customers end-select use-column 0 ! disable columns new-page print ’Labels printed on ’ (. and the third at character position 57. After the last page of labels has been printed.1) print #label_count () edit 9.1. 70 SQR User’s Guide . just below the first label. the second address into the second. When ten lines of labels are complete.1. the second at character position 29. the program prints a summary page showing the number of labels printed.30) addr1 (2. ’ || &state || ’ ’ || $zip print $last_line (3.30) city state zip move &zip to $zip XXXXX-XXXX let $last_line = &city || ’. a new page is started. The fourth address will go into the second row of the first column.999 end-procedure ! mailing_labels Defining Columns and Rows The command COLUMNS 1 29 57 defines the starting position for three columns.3 Program ex9a.Printing Mailing Labels SQR 4.999.1. The first column starts at character position 1. The above program writes the first address into the first column.sqr (continued) begin-select name (1. the third address into the third.

On other platforms. NEXT-LISTING skips the specified number of lines (SKIPLINES) from the last line that was printed (NO-ADVANCE) and sets the new position as line 1. The 10-point Times Roman used here. and zip columns are moved to string variables. ’ || &state || ’ ’ || $zip combines the city. you can use proportionally spaced fonts with any printer that supports fonts or graphics. After each row of labels. state. and zip code. which would cause the third column to print beyond the paper edge if this report used the default font. The city. counts the number of rows of labels that were printed. "Printing Issues. The program defines two counters. In Windows. When the program has printed the number of lines defined by {MAX_LABEL_LINES}. This width accommodates the printing of the third column. #label_count and #label_lines. "Changing Fonts. "Changing Fonts. which is a proportionally spaced font." The sample program prints the labels in 10-point Times Roman. The command LET $last_line = &city || ’. SQR User’s Guide 71 . it starts a new page and resets the #label_lines counter. #label_lines. condenses the text so that it will fit on the page." In the sample program. see Chapter 14. #label_count. see Chapter 14. city. The first counter. SQR assumes a default character grid of 10 characters per inch. In this way. SQR directly supports HP LaserJet printers and PostScript printers. state. Note the use of the ALTER-PRINTER command. This command changes the font in which the report is printed. Printing and printer support are explained in greater detail in Chapter 26. For more information on changing fonts in SQR. and zip code are printed without unnecessary gaps. which it stores in the variable $last_line. however. the NEXT-LISTING command redefines the position where the next row of labels will be printed as line 1. into a string. plus appropriate punctuation and spacing. which contains 30 characters and begins at character position 57. The page width is set at 10 inches to prevent SQR from treating the third-column print position as an error.3 Printing Mailing Labels Note the technique for composing the last line of the label. the command DECLARE-LAYOUT defines a page width of 10 inches. counts the total number of labels and prints it on the summary page.SQR 4. The second counter." For more information on using proportionally spaced fonts. state.

The output will automatically appear in the Viewer window after the report has been run.3 Running the Program When you print with a proportionally spaced font. NH 04821-9876 Kate’s Out of Date Dress Shop 2100 Park Ave New York. If you are using a PostScript printer. NY 10833-1660 Clair Butterfield 371 Youngstown Blvd Teaneck. Here is a portion of the output: Output for ex9a. OH 44900-1300 Harold Alexander Fink 32077 Cedar Street Davenport. 167 East Blvd. NJ 00355-4530 Quentin Fields 37021 Cedar Road Cleveland. New York. You will still need to use the -PRINTER:xx flag when printing.sqr Gregory Stonehaven Middlebrook Road Everretsville. you must use a slightly different technique for running the program and viewing the output.Printing Mailing Labels SQR 4. SQR Portable File format is covered in greater detail in Chapter 26. OH 44121-9475 Jerry’s Junkyard Specialties Crazy Lake Cottages Frogline. enter -PRINTER:HP (or -printer:hp). NM 87893-7070 Corks and Bottles. In the example above. specify the printer type with the -PRINTER:xx flag. OH 40233-1000 Alfred E Newman & Company 2837 East Third Street New York. Inc. NY 10213-1002 Isaiah J Schwartz and Company 37211 Columbia Blvd Zanesville. MI 40674-3900 Joe Smith and Company 1711 Sunset Blvd Big Falls. If you are using a platform such as UNIX or VMS. 72 SQR User’s Guide . NY 10002-1001 Eliot Richards 2134 Partridge Ave Queens. filling each row of labels before moving down the page. NY 10204-1234 Harry’s Landmark Diner 17043 Silverfish Road Miningville. IN 62130-1025 Harriet Bailey 47 Season Street Mamaroneck. NY 10134-2030 Sam Johnson 37 Cleaver Street Bell Harbor. the report prints the labels left to right. For example: sqr ex9a username/password -printer:hp You may also use the -KEEP command-line flag to produce output in the SQR Portable File format (SPF) and print it using SQR Print. neither -PRINTER:xx nor -KEEP is required. If you are using an HP LaserJet. IN 40622-4321 The report produces the output in three columns corresponding to the dimensions of a sheet of mailing label stock. enter -PRINTER:PS (or -printer:ps) on the command line. With VisualSQRIBE.

999.11) left-margin=0. filling each column before moving to the next column of labels.1) print #label_count () edit 9.1.1) print $current-date () print ’Total labels printed = ’ (+1.SQR 4.33 end-declare end-setup begin-program do mailing_labels end-program begin-procedure mailing_labels let #Label_Count = 0 let #Label_Lines = 0 columns 1 29 57 ! enable columns alter-printer font=5 point-size=10 begin-select name (0.3 Printing Mailing Labels You can also print the labels from the top down.1. The code is shown below. The differences between this code and the previous one are shown in bold.999 end-procedure ! mailing_labels SQR User’s Guide 73 .30) addr1 (+1. but you can run the file and view it using the same procedure you used for the previous example.30) city state zip move &zip to $zip xxxxx-xxxx let $last_line = &city || ’. The output is not printed here. Program ex9b.sqr #define MAX_LABEL_LINES #define LINES_BETWEEN_LABELS 10 3 begin-setup declare-layout default paper-size=(10.1.30) add 1 to #label_count add 1 to #label_lines if #label_lines = {MAX_LABEL_LINES} next-column goto-top=1 at-end=newpage let #label_lines = 0 else position (+1) position (+{LINES_BETWEEN_LABELS}) end-if from customers end-select use-column 0 ! disable columns new-page print ’Labels printed on ’ (. ’ || &state || ’ ’ || $zip print $last_line (+1.

• ALTER-PRINTER can be used to specify fonts. produce summary information about a report. • Counters. Counters also determine when a page is full. The next chapter describes how to create form letters. such as #label_count and #label_lines.Printing Mailing Labels SQR 4.3 Summary • A SELECT paragraph is used to retrieve data for mailing labels and other similar reports. 74 SQR User’s Guide . • NEXT-LISTING ends the current listing and begins another. • COLUMNS is used to define report columns. such as the number of labels printed.

In between you lay out the letter and insert variables where you want data from the database to be inserted. Using a document marker is less direct. These are placeholders in the DOCUMENT section where you can print data after the DOCUMENT section is printed. You will be introduced to the SQR DOCUMENT section and two new commands: BEGIN-DOCUMENT and END-DOCUMENT.b (see the sample code below). The sample program demonstrates the use of variables as well as document markers. but it gives more flexibility in positioning the contents of variables. SQR will print the contents of the variable in the position where it is placed in the DOCUMENT section. Another way to mix data with the letter is to use document markers. you must explicitly mark them with a . state. you use a DOCUMENT section. For example. To leave blank lines in a letter.10 Creating Form Letters This chapter explains how to create a form letter. the customer’s name is printed on the first line. Document markers are denoted with a name preceded by the at sign (@). For most purposes. and zip code because the city name varies in length and thus affects the position of the state name and zip code. a variable would do. in the program below. Laying Out the Letter To create form letters. The sample program uses a document marker to position the city. SQR will insert the value of the variable when the document is printed. This use of document markers is demonstrated in the simple form letter program below. It starts with a BEGIN-DOCUMENT command and ends with an END-DOCUMENT command. SQR User’s Guide 75 .

Yes. During this month. our entire inventory is marked down by 25%.1) &name &addr1 &addr2 @city_state_zip .b $current-date Dear Sir or Madam: .b Sincerely. .Creating Form Letters SQR 4.b Thank you for your recent purchases from ACME Inc.b . ’ () print &state () print ’ ’ () print &zip () edit xxxxx-xxxx new-page end-procedure ! write_letter 76 SQR User’s Guide . To place an order simply dial 800-555-ACME. Delivery is free too. Clark Axelotle ACME Inc. so don’t wait.sqr begin-program do main end-program begin-procedure main begin-select name addr1 addr2 city state zip do write_letter from customers order by name end-select end-procedure ! main begin-procedure write_letter begin-document (1. end-document position () @city_state_zip print &city () print ’. you can buy your favorite merchandise and save too.3 Program ex10a. We would like to tell you about our limited-time offer.b .

The program prints the city. you can buy your favorite merchandise and save too. The state name. Next. then continues printing the other elements to the current position." Summary • To print form letters. To place an order simply dial 800-555-ACME. Alfred E Newman & Company 2837 East Third Street Greenwich Village New York. SQR performs the main procedure and the SELECT statement. use variables or document markers inserted in the DOCUMENT section to place data in the text. Below is the first page of the output of our program for ex10a. Sincerely. which is given by the marker @city_state_zip. and zip code are automatically printed in the correct positions with appropriate punctuation. The POSITION command sets the position to the appropriate line. SQR User’s Guide 77 . We would like to tell you about our limited-time offer. "Using Graphics. You will find another example of a form letter in Chapter 12. During this month. so don’t wait. Yes. it performs the write_letter procedure and the DOCUMENT section.SQR 4. NY 10002-1001 10-MAY-1996 Dear Sir or Madam: Thank you for your recent purchases from ACME Inc. Clark Axelotle ACME Inc. Delivery is free too.3 Creating Form Letters First. The next chapter explains how to export data to other applications. our entire inventory is marked down by 25%.sqr.

.

11 Exporting Data to Other Applications This chapter shows you how to create a tab-delimited file that is suitable for exporting data to many applications. Program ex11a. The tabs create columns in your spreadsheet or word processing document which will correspond to the columns in your database table. SQR User’s Guide 79 .sqr begin-setup ! No margins. wide enough for the widest record ! and no page breaks declare-layout default left-margin=0 top-margin=0 max_columns=160 formfeed=no end-declare end-setup begin-program do main end-program begin-procedure main encode ’<009>’ into $sep ! Separator character is TAB let $cust_num = ’Customer Number’ let $name = ’Customer Name’ let $addr1 = ’Address Line 1’ let $addr2 = ’Address Line 2’ let $city = ’City’ let $state = ’State’ let $zip = ’Zip Code’ let $phone = ’Phone Number’ let $tot = ’Total’ string $cust_num $name $addr1 $addr2 $city $state $zip $phone $tot by $sep into $col_hds print $col_hds (1. which you can load into a document such as a spreadsheet. The following program example creates such a file.1) new-page Program continues on the following page.

The code (9) is enclosed in angle brackets to indicate that it is a non-display character.lis) into a spreadsheet or other application. There is no page ejection because of the FORMFEED=NO argument in the DECLARE-LAYOUT command.sqr (continued) begin-select cust_num name addr1 addr2 city state zip phone tot string &cust_num &name &addr1 &addr2 &city &state &zip &phone &tot by $sep into $db_cols print $db_cols () new-page from customers end-select end-procedure ! main The ENCODE command stores the ASCII code for the tab character in the variable $sep. You can now load the output file (ex11a. with each record similarly separated by a tab. It really causes a new line and carriage return at the end of each record. this time to combine the records (named as column variables) in the $db_cols variable. not printed.3 Program ex11a. ENCODE is a useful way to place nonalpha and nonnumeric characters into variables. we use the STRING command again.Exporting Data to Other Applications SQR 4. SQR will then treat it as a character code and set the variable accordingly. with each heading separated by a tab. The STRING command combines these variables in the $col_hds variable. this report is meant to be exported. Remember. 80 SQR User’s Guide . The LET command creates variables for the text strings used as column headings in the export file. The NEW-PAGE command is used in this example in an unusual way. In the SELECT paragraph. with the line number reset to 1.

• LET can be used to place text in variables for export. • STRING can be used to create a variable holding several text or data items separated by a variable representing a tab or other separator character. • ENCODE can be used to place the ASCII code for a tab into a value. The next chapter explains how to create graphical reports.SQR 4.3 Exporting Data to Other Applications Summary • A tab-delimited output file can be used to export data into other applications. SQR User’s Guide 81 . • The contents of database column variables can also be exported.

.

sqr begin-setup declare-layout default end-declare end-setup begin-program do main end-program begin-procedure main begin-select name (. You will learn how to include a logo or other graphic in a report.+1. and draw solid lines.30) city (.+1.40) print #grand_total (.11) edit 99999999.1) Edit ’DD-MON-YYYY’ page-number (1.1.32) print ’State’ (. Program ex12a.1.+1.99 end-procedure ! main begin-heading 5 print $current-date (1.99 next-listing no-advance need=1 let #grand_total = #grand_total + &tot from customers end-select print ’-’ (.55.5) tot (. change the font.11) edit 99999999.65) fill end-heading SQR User’s Guide 83 .16) state (.1) print ’City’ (. The following example produces a simple tabular report similar to the one in Chapter 3.49) print ’Total’ (.61) print ’-’ (4.55.11) fill print ’Grand Total’ (+1.60) ’Page ’ print ’Name’ (3.12 Using Graphics This chapter explains how to add graphical features to SQR reports.

however. 84 SQR User’s Guide . "Adding Graphics.Using Graphics SQR 4.00 12. The purpose of specifying the default layout is to use its margin settings. Note the PRINT command with the FILL option. This command produces dashed lines.00 21. The next section. it is possible to draw solid lines. which is a simple way to draw lines for a report printed on a line printer.00 Grand Total Adding Graphics The next sample program includes graphical features—a logo. Inc.00 18.00 33.00 15. and a change of font in the heading.3 The SETUP section contains a DECLARE-LAYOUT command that specifies the default layout without defining any options.00 36. the report would have no margins. On a graphical printer.00 30. solid lines.00 27. 06-JUN-96 Page 1 Name City State Total --------------------------------------------------------------Gregory Stonehaven Alfred E Newman & Company Eliot Richards Isaiah J Schwartz and Company Harold Alexander Fink Harriet Bailey Clair Butterfield Quentin Fields Jerry’s Junkyard Specialties Kate’s Out of Date Dress Shop Sam Johnson Joe Smith and Company Corks and Bottles. Text that has changed is shown in bold.00 42.00 24.00 9." shows you how to take advantage of this feature.00 3. Without DECLARE-LAYOUT.00 6.00 --------315. Harry’s Landmark Diner Everretsville New York Queens Zanesville Davenport Mamaroneck Teaneck Cleveland Frogline New York Bell Harbor Big Falls New York Miningville OH NY NY OH IN NY NJ OH NH NY MI NM NY IN 39. which are defined as 1/2 inch.

+1.40) print #grand_total (.60) ’Page ’ alter-printer point-size=14 font=4 ! switch font print ’Name’ (9. See Chapter 6 for more information on character grids.55.99 next-listing no-advance need=1 let #grand_total = #grand_total + &tot from customers end-select graphic (.1) page-number (1.49) bold print ’Total’ (. Note that the third number in the position specifier is the length of the line.+1.16) state (.1. (The actual width of a character cell is determined by the CHAR-WIDTH or MAX-COLUMNS arguments of DECLARE-LAYOUT.61) bold alter-printer point-size=12 font=3 ! restore font graphic (9.30) city (.sqr begin-setup declare-layout default end-declare end-setup begin-program do main end-program begin-procedure main begin-select name (.3 Using Graphics Program ex12b. The line is positioned using a normal SQR position specifier.+1.23) type=bmp-file image-size=(21.32) bold print ’State’ (.1. which is given in characters.5) tot (.5) source=’acmelogo.11) Edit 99999999.1) bold print ’City’ (.bmp’ end-heading The GRAPHIC command is used to draw solid lines with the HORZLINE option.99 end-procedure ! main begin-heading 11 print $current-date (1.SQR 4.12) horz-line 20 print ’Grand Total’ (+2.55.11) edit 99999999.) SQR User’s Guide 85 .66) horz-line 20 print-image (1.

The TYPE option specifies the image file type. These formats are: • Windows—bmp-file images • PostScript printer or viewer—eps-file • HP LaserJet—hpgl-file images • HTML output—GIF or JPEG formats (gif-file or jpeg-file) 86 SQR User’s Guide .Using Graphics SQR 4. In the example. font 4 is Helvetica.sqr.3 The HORZ-LINE argument of the GRAPHIC HORZ-LINE command is the thickness of the line. boxes and shaded boxes. images are always stored in external files.sqr changes the font for the heading.66) horz-line 20 specifies a horizontal line below line 10 in the report starting with position 1 (the left side of the report) and stretching for 66 character positions (at 10 characters per inch this is 6. You can use a whole number or even a fraction (for example. but the number is printerspecific. The following command changes the font to 14-point Helvetica: alter-printer point-size=14 font=4 ! switch font The PRINT-IMAGE command inserts the logo. POINT-SIZE=10. the image is 30 characters wide (3 inches) and 7 lines high (1 1/6 inches).1. The POINT-SIZE option specifies type size in points. PRINT-IMAGE is followed by a print position corresponding to the top left corner of the image (line 1. The ALTER-PRINTER command in ex12b. which is in your SAMPLE (or SAMPLEW) subdirectory.6 inches). For example. The GRAPHIC command in the SQR Language Reference also provides more information. it restores the normal font for the rest of the report. The format of the image must match that of the printer you are using. and font 5 is Times Roman. The GRAPHIC command can also be used to draw vertical lines. font 3 is Courier. and it is specified in decipoints (there are 720 decipoints per inch). The thickness of the line is 20 decipoints. for an example. column 19 in our example). see DECLARE-PRINTER in the SQR Language Reference. the command graphic (10. The FONT option selects a font (typeface) that is supported by the printer. In our example the image is stored in Windows bitmap format (bmp-file). For more information on fonts. See the program sqrlaser. for example. which is 1/36 of an inch (about 0. The size of the image is specified in terms of columns (width) and lines (height). On a PostScript printer.5). In SQR.7 millimeters). The font is specified by number. When used a second time.

" The SOURCE option specifies the file name of the image file. however. as long as you specify a full pathname for the image file.BMP. SQR can also produce printerindependent output files in a special format called SQR Portable Format (SPF).SQR 4. Output for ex12b. the file is ACMELOGO.3 Using Graphics For more information on HTML output. SQR User’s Guide 87 . "Working with HTML. The file is assumed to reside in the current directory or in the directory where SQR is installed (you can place the logo file in either of these two places). see Chapter 28. The file may reside in any directory.sqr The output file now contains graphic language commands. SQR can produce output suitable for HP LaserJet printers in a file format that uses the HP PCL language or output suitable for PostScript printers in a file format that uses the PostScript language. In our example.

The image size is specified and provides the default. see Chapter 26.sqr prints a simple form letter. you only need to change it in one place. The declaration includes the type and source file for the image.SPF). As you will see. When you create an . However. It specifies the logo used in the last sample program.LIS file from an . when printer-specific output is generated.inc: File acme.LIS file) or create the output in portable format (. It shows how to print a logo using the DECLARE-IMAGE and PRINT-IMAGE commands and how to print a signature using only PRINT-IMAGE. When using . acme.SPF files.inc.Using Graphics SQR 4. If you later need to change an attribute. the DECLARE-IMAGE command is useful if you want several programs to share the definition of an image.LIS file or by using SQR Print to generate an .3 SQR can create a printer-specific output file (an ." Sharing Images among Reports You can place logos and other images in a report using only the PRINT-IMAGE command. 88 SQR User’s Guide . you do not need to respecify these attributes. Because the image is shared among several reports.bmp’ end-declare This file declares an image with "acme-logo" as the name. the command DECLARE-IMAGE is contained in this file. You can create printer-specific output by using SQR or SQR Execute to directly generate an . "Printing Issues. Multiple programs can share the declaration and include the file acme.SPF file. such as the source. For more information on SQR Portable Format.inc declare-image acme_logo type=bmp-file image-size=(30. when the image is printed. and the image is processed at print time.7) source=’acmelogo. a change in the contents of the image file will be reflected in the report the next time you print it or view it. Program ex12c. the name of the image file is copied into it.SPF file.

Program ex12c.sqr begin-setup #include ’acme. use the IMAGE-SIZE argument of the PRINT-IMAGE command.inc’ end-setup begin-program do main end-program begin-procedure main begin-select name addr1 addr2 city state zip phone do write_letter from customers order by name end-select end-procedure ! main begin-procedure write_letter move &city to $csz concat ’.3 Using Graphics If you need to change the size of an image in a particular report. SQR User’s Guide 89 .SQR 4. Program continues on the following page. It will override the image size specified in DECLARE-IMAGE. ’ with $csz concat &state with $csz concat ’ ’ with $csz move &zip to $zip xxxxx-xxxx concat $zip with $csz move &phone to $phone_no (xxx)bxxx-xxxx ! Edit phone number.

jazz. Maestro!! can even teach you to improvise your own solos. Maestro!! begins with a step-by-step approach to some of America’s favorite songs.4) position () @signature print-image () type=bmp-file image-size=(12.b Now anyone who can hum a tune can play one too. From there.b @logo $current-date Dear &name .b . You’ll learn the correct keyboarding while hearing the sounds you make through the headphones provided with the Encore. Maestro!!. @signature .bmp’ new-page end-procedure ! write_letter 90 SQR User’s Guide . .Using Graphics SQR 4.3) source=’clark.b A local representative will be calling you at $phone_no to set up an in-house demonstration. If you’ve always wanted to play an instrument but felt you could never master one. Encore. Maestro!! is made for you.b Whether you like classical.sqr (continued) begin-document (1.b . . you’ll advance to intricate compositions with dazzling melodic runs. Maestro!! system. Maestro!! is the music teacher for you.3 Program ex12c. Encore.b Thank you for your inquiry regarding Encore.0) &name &addr1 &addr2 $csz . Encore.b .b Clark Axelotle end-document position () @logo print-image acme-logo () image-size=(16. Encore. so get ready to play your favorite tunes!! . our revolutionary teaching system for piano and organ. pop.b Sincerely.1. . or blues.

for example. variables retain their predefined size. The DOCUMENT section begins with a BEGIN-DOCUMENT command and ends with an END-DOCUMENT command. The date is prepared with the reserved variable $current-date. and the phone number. Document markers are placeholders in the letter. because they fall at the end of a line.INC’ includes the code from the file acme. you simply print to the current position. however. The program uses variables for the name and address. In this program. The program uses the CONCAT command to put together the city. and zip code. the date. SQR User’s Guide 91 . You can print the date and phone number directly. see the command #INCLUDE ’ACME. without any following text. is used to pull in text from another file. will remain the width of the column as defined in the database. It is printed directly in the DOCUMENT section without issuing a PRINT command. The output of our program is shown on the following page.inc in this program. It uses document markers for the logo and signature. In the DOCUMENT section. The document markers make it unnecessary to specify the position of these items in the PRINT-IMAGE command. A column variable.3 Using Graphics The #INCLUDE command. It uses variables and document markers to print inside the letter.SQR 4. The program uses the document markers @logo and @signature in a POSITION command before printing each image. state. Instead. which is performed at compile time.

5 text=’01234567890’ caption=’0 12345 67890’ 92 SQR User’s Guide . use the PRINT-BAR-CODE command. To create a bar code. specify the bar code type. and optional check sum. caption. text to be encoded. Specify the position of the bar code in an ordinary position qualifier. In separate arguments.1) type=1 height=0.Using Graphics SQR 4. height.spf Printing Bar Codes You can also include bar codes in your SQR report.3 File ex12c. SQR supports a wide variety of bar code types. For example: print-bar-code (1.

see the PRINT-BAR-CODE command in the SQR Language Reference. • PRINT-IMAGE prints a logo or other graphic in the report. SQR User’s Guide 93 . • PRINT-BAR-CODE can be used to create bar codes.SQR 4. Summary • DECLARE-LAYOUT can be used to set a margin. • CONCAT is used to combine multiple data elements into one variable.3 Using Graphics Arguments to PRINT-BAR-CODE may be variables or literals. • GRAPHIC can be used to draw solid lines or shaded boxes. The example above will produce the following bar code: For further information. • ALTER-PRINTER chooses a font. • DECLARE-IMAGE allows you to share images among reports. The next chapter shows how to present information visually with charts and other graphics. • The #INCLUDE command is used to include commands from other files in a program.

.

SQR charts are also portable—you can move them from one hardware platform to another. The following program produces two charts corresponding to the two cross-tabs. bar. You can customize many attributes of SQR charts by turning on threedimensional effects or setting titles and legends. SQR User’s Guide 95 . That example combined the two reports in one program. overlapped bar. "CrossTabular Reports and the Use of Arrays" (ex8c. Here is the code. A business chart can be prepared using data held in an array.sqr).13 Business Charts This chapter shows how to present information visually with graphs. and histograms. DECLARE-CHART and PRINT-CHART. The lines that were changed or added are shown in bold. histogram. SQR provides two commands for creating charts. and a rich set of chart types—line. Creating a Chart The following example builds on the report created in Chapter 8. If you've already written a crosstabular report. xy-scatter plot and high-low-close. 100% bar. 100% area. it's just one more step to make a chart using the data already collected in the array. just like a cross-tabular report (see Chapter 8). stacked area. charts. pie. area. floating bar. stacked bar. Business charts are useful tools for presenting summary data.

70) fill position (+1) do print_array2 new-page let $done = ’YES’ ! Don’t need heading any more do print_the_charts end-program begin-procedure print_array let #entry_cnt = #i let #i = 0 while #i <= #entry_cnt let $product = order_qty.product(#i) let #jan = order_qty.999 print #mar (.62.2) let #prod_tot = #jan + #feb + #mar print $product (.999 print #prod_tot (.1.999.32.999.1) let #mar = order_qty.30) title=’Order Quantity’ legend-title=’Month’ type=stacked-bar end-declare ! orders-stacked-bar end-setup begin-program do select_data do print_array print ’-’ (+2.30) print #jan (.999 print #feb (.month_qty(#i.1.month_qty(#i.9) edit 9. 96 SQR User’s Guide .999.52.sqr #define max-categories 3 #define max-products 100 begin-setup create-array name=order_qty size={max-products} field=product:char field=month_qty:number:3 create-array name=order_qty2 size={max-categories} field=category:char field=month_qty:number:3 declare-chart orders-stacked-bar chart-size=(70.9) edit 9.42.999 position (+1) let #i = #i + 1 end-while end-procedure ! print_array Program continues on the following page.9) edit 9.month_qty(#i.Business Charts SQR 4.999.3 Program ex13a.9) edit 9.0) let #feb = order_qty.

1.999 print #feb (.999 print #feb_total (.9) edit 9.month_qty(#i.category(2)=’Over $100’ begin-select order_date ! the price / price category for the order c.99’ let order_qty2.9) edit 9.32.999 print #mar (.42.1) let #mar = order_qty2.999 end-procedure ! print_array2 begin-procedure select_data let order_qty2.62.999.999 position (+1) let #jan_total = #jan_total + #jan let #feb_total = #feb_total + #feb let #mar_total = #mar_total + #mar let #i = #i + 1 end-while let #grand_total = #jan_total + #feb_total + #mar_total print ’Totals’ (+2.category(#i) let #jan = order_qty2.category(0)=’$0-$4.9) edit 9.00’ let order_qty2.9) edit 9.42.999.9) edit 9.9) edit 9.999.999.sqr (continued) begin-procedure print_array2 let #i = 0 while #i < {max_categories} let $category = order_qty2.31) print #jan (.999.2) let #category_tot = #jan + #feb + #mar print $category (.52.9) edit 9.month_qty(#i.category(1)=’$5.52.32.999.999.0 let #x = 0 break when <= 100.999 print #grand_total (.price &price move &price to #price_num evaluate #price_num when < 5.9) edit 9.00-$100.62.0) let #feb = order_qty2.999 print #mar_total (.3 Business Charts Program ex13a. SQR User’s Guide 97 .999.999 print #category_tot (.SQR 4.1) print #jan_total (.month_qty(#i.0 let #x = 1 break Program continues on the following page.

month_qty(#i.product_code order by description end-select end-procedure ! select_data begin-heading 5 if not ($done = ’YES’) print $current-date (1.product(#i) = &description end-if if order_qty.month_qty(#i.42) print ’ March’ (.order_num and b.1) page-number (1.product(#i) = ’’ let order_qty.order_num = b.1 if #j < 3 let order_qty2.32) print ’ February’ (.#j) + &quantity end-if ! the product for this order description if #i = 0 and order_qty.Business Charts SQR 4.sqr (continued) when-other let #x = 2 break end-evaluate ! The quantity for this order quantity let #j = to_number(datetostr(&order_date.product(#i) = &description end-if if #j < 3 let order_qty.month_qty(#x. 98 SQR User’s Guide . products c where a.#j) + &quantity end-if from orders a.52) print ’ Total’ (. ordlines b.1) print ’ January’ (.1.month_qty(#x.10) print ’Product / Price Category’ (4.#j) = order_qty2.70) Fill end-if end-heading Program continues on the following page.64) ’Page ’ print ’Order Quantity by Product and Price Category by Month’ (2.product_code = c.product(#i) != &description let #i = #i + 1 if #i >= {max_products} display ’Error: There are more than {max_products} products’ stop end-if let order_qty.62) Print ’-’ (5.’MM’)) .#j) = order_qty.3 Program ex13a.

SQR 4.1) data-array=order_qty data-array-row-count=12 data-array-column-count=4 data-array-column-labels=(’Jan’. Here is the DECLARE-CHART command: declare-chart orders-stacked-bar chart-size=(70. The height (or depth.’Feb’. In general. SQR User’s Guide 99 . The text generated by LEGEND-TITLE must fit in the small legend box above the categories. which translates to 5 inches at 6 lines per inch. which is 7 inches on a default layout.30) title=’Order Quantity’ legend-title=’Month’ type=stacked-bar end-declare ! orders-stacked-bar The heading is disabled for the last two pages where the charts are printed. these terms are used interchangeably) of the charts is 30 lines. The charts generated by this program will be 70 characters wide. The title is centered at the top of the chart.’Mar’) sub-title=’By Price Category By Month’ end-procedure ! print_the_charts Defining the Chart The two charts in program ex13a.’Mar’) sub-title=’By Product By Month’ new-page print-chart orders-stacked-bar (+2.’Feb’. so keep this description short. but you can disable it using the qualifier BORDER=NO. The width and height of the charts are specified in terms of character cells. you’ll find that charts look best when the text items are short.3 Business Charts Program ex13a.sqr are based on the DECLARE-CHART command in the SETUP section and are named orders-stacked-bar. The box that surrounds the chart is drawn by default.sqr (continued) begin-procedure print_the_charts print-chart orders-stacked-bar (+2. These dimensions define a rectangle that contains the chart.1) data-array=order_qty2 data-array-row-count=3 data-array-column-count=4 data-array-column-labels=(’Jan’.

A legend is used to label the series. Running the Program When you create a graphical report.’Feb’.’Mar’) sub-title=’By Price Category By Month’ The data source is specified using the DATA-ARRAY option.Business Charts SQR 4. The named array is expected to have a certain structure that is specified by the TYPE option. specify the printer type with the flag -PRINTER:xx. If you are using an HP LaserJet. you must use a slightly different technique for running the program and viewing the output. The subtitle goes under the title and can be used as a second line of the title. The argument DATA-ARRAY-ROW-COUNT is the number of rows (bars) to chart and DATA-ARRAY-COLUMN-COUNT is the number of fields in the array that the chart uses. For a stacked-bar chart. print-chart orders-stacked-bar (+2.’Mar’) sub-title=’By Product By Month’ new-page print-chart orders-stacked-bar (+2.’Feb’. The argument DATA-ARRAY-COLUMN-LABELS is used to pass these labels.1) data-array=order_qty2 data-array-row-count=3 data-array-column-count=4 data-array-column-labels=(’Jan’. enter -PRINTER:HP (or -printer:hp).3 Printing the Chart Now look at the PRINT-CHART commands. For example: sqr ex9a username/password -printer:hp 100 SQR User’s Guide . If you are using a platform such as UNIX or VMS. enter -PRINTER:PS (or -printer:ps) on the command line. There are four fields in the array—the product (or price category) field plus the three series (months). the first field in the array gives the names of the categories for the bars. In this case. The rest of the fields are series of numbers. If you are using a PostScript printer. each series corresponds to a month. Both are based on the orders-stacked-bar chart that was declared above.1) data-array=order_qty data-array-row-count=12 data-array-column-count=4 data-array-column-labels=(’Jan’.

Output for file ex13a. The output will automatically appear in the Viewer window after the report has been run.spf SQR User’s Guide 101 . SQR Portable File format is covered in greater detail in Chapter 26. With VisualSQRIBE. Here is a portion of the output: The charts will appear on pages 2 and 3 of the report.3 Business Charts You may also use the -KEEP command-line flag to produce output in the SQR Portable File format (SPF) and print it using SQR Print.SQR 4. You will still need to use the -PRINTER:xx flag when printing. neither -PRINTER:xx nor -KEEP is required.

you can have a series of ’Y’ and ’N’ values which indicate whether or not to explode the segment.. bar.Business Charts SQR 4. you cannot omit the first field with the descriptions.2. and 100% area.. This procedure is common to many chart types.3 Passing Data to the Chart The procedure for passing the data to the chart is to use the first field for the descriptions of bars (or lines or areas) and then use one or more additional fields with series of numbers. area. only one series is allowed. stacked-bar. histogram.) for the bars. 102 SQR User’s Guide . With pie charts. If ’Y’ is the value in the first row of the array. . 100% bar. Using a third field in the array. including line. Pie charts are also a special case because you can specify which segments to "explode. You can omit the first field and SQR will use cardinal numbers (1. Pie charts cannot have more than 12 segments. the pie segment that corresponds to the first row will be exploded. For pie charts." or pull away. overlapped bar. from the center of the pie. Only text fields will be used for these options. stacked-area.

SQR User’s Guide 103 . For both types. you can have one or more pairs of series. In addition. A pair in a floating-bar chart represents the base and height of the bars. SQR displays the percentage next to the value. The next chapter gives details on changing fonts. In a floating-bar chart. The description is displayed in the legend.SQR 4. A pair in an xy-scatter plot represents x and y coordinates. Summary • DECLARE-CHART and PRINT-CHART are used to print charts. In an xy-scatter plot. You can disable this feature by using the qualifier PIE-SEGMENT-PERCENT-DISPLAY=NO. the first field does not have descriptions. the first field may or may not have descriptions for the bars. When data is passed to an xy scatter plot or a floating-bar chart. • Data arrays must be used to assemble and process the data used in making a chart.3 Business Charts Pie charts display the numeric value next to each segment. the series are paired.

.

in the illustration below.14 Changing Fonts This chapter explains how to print text in different fonts. Fonts will print in the size set by DECLARE-PRINTER or ALTER-PRINTER. To select a font in SQR. use ALTER-PRINTER. Note however that character grid and character size function independently of one another. you use the commands DECLARE-PRINTER and ALTER-PRINTER. If you are writing a printer-independent report. For example. That grid is set by default to 10 characters per inch and 6 lines per inch. the word "Proportionally" fills only 9 cells. although it contains 14 letters. text is positioned according to a grid. If you want to set a font for the entire report. To specify a printer at print time. Positioning Text In SQR. at the beginning of the program. not in an actual linear measurement. the number of letters that you print may no longer match the number of character cells that the text actually fills. such as inches or picas. A character grid is best used for positioning the first character in a string. When you use a proportionally spaced font. but you can give it another definition by altering the CHAR-WIDTH and LINE-HEIGHT parameters of the DECLARE-LAYOUT command. The ALTER-PRINTER command changes the font anywhere in the report. and the change remains in effect until the next ALTER-PRINTER. use the -PRINTER:xx command-line flag. The DECLARE-PRINTER command sets the default font for the entire report. SQR User’s Guide 105 . not the size defined by the grid. It can only express the width of a string in terms of the number of characters it contains. be aware that the attributes you set with DECLARE-PRINTER only take effect when you print your report with the printer you specify with the TYPE argument. which is not printer-specific.

3 Large Times Roman font at position (4. Look at the sample program.3) F ixed pitch fon t . after the output example. For example.Proportionally spaced font 12-pt Times Roman font at position (10. They both calculate the text length based on the character count in the grid. plus Helvetica bold. 106 SQR User’s Guide . the actual position at the end of a string may differ from the position SQR assumes according to the grid. The use of these options with proportional fonts is explained below. instead of writing code such as: alter-printer font=5 print &first_name () print ’ ’ () print &last_name () alter-printer font=3 ! ! ! ! ! select a proportional font print first name print a space print the last name restore the font You should write code such as: alter-printer font=5 ! select a proportional font ! concatenate the name let $full_name = &first_name || ’ ’ || &last_name print $full_name () ! print the name alter-printer font=3 ! restore the font The WRAP and CENTER options of the PRINT command also require special consideration when used with proportional fonts.4) . which is not the same as its dimensional width. It is printed in a mix of fonts—Times Roman in two different sizes.2) When you print consecutive text strings. It consists of a list of reminders from the reminders table.Changing Fonts SQR 4. For this reason.Report Title SQR default font at position (8. we advise you to concatenate consecutive pieces of text and print them as one.

1.60) ’Page ’ ! Use large font for the title alter-printer font=5 point-size=24 print ’Reminder List’ (3.1) bold print ’Reminder’ (6.22) bold graphic (6. which is Times Roman. The font is set at the beginning of the main procedure to font 5. SQR User’s Guide 107 .11) end-declare end-setup begin-program do main end-program begin-procedure main ! Set Times Roman as the font for the report alter-printer font=5 point-size=12 begin-select remind_date (. so it remains at the default of 12. The BOLD option of the PRINT command specifies that they are printed in bold.SQR 4. The point size was not set.20) edit ’DD-MON-YY’ reminder (. In the HEADING section.66) horz-line ! Restore the font alter-printer font=5 point-size=12 end-heading The report uses the default layout grid of 10 characters per inch and 6 lines per inch.3 Changing Fonts Program ex14a. both for positioning the text and for setting the length of the solid line.1) Edit ’DD-MON-YYYY’ page-number (1. The column headings are set to 12-point Helvetica with the command ALTER-PRINTER FONT=4 POINT-SIZE=12.25) ! Use Helvetica for the column headings alter-printer font=4 point-size=12 print ’Date’ (6. its size is set to 24 points to print the title.sqr begin-setup declare-layout default paper-size=(10.1.+1) wrap 60 5 position (+2) from reminders end-select end-procedure ! main begin-heading 7 print $current-date (1.

108 SQR User’s Guide . Positioning the title requires careful coding. A font change in the heading will not affect the font used in the body of the current page. position the title by estimating its length. Using WRAP The WRAP option of the PRINT command is used to print the text of the reminder column. the same as the column headings. Instead. the font is restored to Times Roman. which is 60 characters in the sample program. Remember that the character grid used for positioning assumes 10 characters per inch.3 Under the column headings. Note that it is positioned at line 6." which is line 3.Changing Fonts SQR 4.25). Make sure you keep track of your font changes. The character coordinates will be "(3. This option wraps text based on a given width. The CENTER option of the PRINT command won’t work because it does not account for the actual size of the text. the report heading is performed after the body. although it will change the font used in the body of subsequent pages. SQR is designed to draw the solid line as an underline. In this case. there is a solid line. At the end the HEADING section. 25 characters translates to 2 1/2 inches. Therefore. We recommend that you return fonts to their original settings in the same section in which you change them. Program ex14a.spf In an SQR program. character position 25. the title should start 2 1/2 inches from the left margin.

It does not depend on the font. ALTER-PRINTER is printerneutral. • The BOLD. 8 1/2 inches minus the inch used in the margins is 7 1/2 inches. This definition is given by the argument PAPERSIZE=(10. The other argument of the WRAP option is the maximum number of lines. no more than 5 lines are needed.11) in the DECLARE-LAYOUT command. Remember. Text printed in Times Roman takes about 30-50 percent less room than the same text in Courier (the default font. this setting only specifies the maximum number of lines. SQR will not use more lines than are needed. at 60 characters per line. The next chapter explains how to write reports that can be printed on any printer. and WRAP options of the PRINT command are used to format text. specify a width of 60. which is a fixed-size font).SQR 4. or 75 characters at 10 CPI. Printing 60 characters starting from position 22 could exceed this maximum and cause an error or undesirable output. To avoid this error. This means that a column with a nominal width of 44 characters (that’s the width of the reminder column) can actually hold as many as 66 letters when printed in the Times Roman font. In the sample program. SQR User’s Guide 109 . define the page as wider than it actually is.3 Changing Fonts The WRAP option works only on the basis of the width given in the character grid. Since the reminder column in the database is 240 characters wide. CENTER. Summary • DECLARE-PRINTER and ALTER-PRINTER are used to specify fonts. SQR calculates the maximum number of characters on a line using the page dimensions in the DECLARE-LAYOUT command (the default is 8 1/2 inches wide). To be conservative. • DECLARE-PRINTER is printer-specific.

.

15 Writing Printer-Independent Reports This chapter explains how to prepare printer-independent reports. • Use only a small set of fonts. Guidelines for Printer-Independent Reports • Your program should not assume or require a specific printer. Your program should be free of the following commands: GRAPHIC FONT (use ALTER-PRINTER instead). To create a printer-independent report. However. 4. as demonstrated below). PRINTER-DEINIT. the better. USE-PRINTER-TYPE (except for using this command to select a printer at run time. 5 and their boldface versions are the same regardless of the type of printer you use (except for a line printer). PRINT-DIRECT. complete printer independence may be too restrictive. Graphics or solid lines printed with the graphic command are not printed on a line printer. Test your graphical report on a line printer. the closer you can get to a truly printer-independent report. and the SYMBOL-SET argument of the ALTER-PRINTER command only define behavior when a specific printer is used. the CODE or CODE-PRINTER qualifiers of the PRINT command. Note that on some HP printers. Font numbers 3. and font 5 is Times Roman. This reduces the common fonts to fonts 3 and 5 only. • Your report should be readable if printed on a line printer. PRINTER-INIT. and the CODE-PRINTER and CODE qualifiers of the PRINT command. Helvetica may not be available. • DECLARE-PRINTER. SQR User’s Guide 111 . As you will see. Font 3 is Courier. you must write a program that avoids using any characteristics that are unique to a specific printer. which can be run on any printer that SQR supports or distributed electronically. font 4 is Helvetica.

enter the following on the command line: sqr test username/password -printer:ps The second way of specifying the printer type is by using the USE-PRINTER-TYPE command. -PRINTER:WP for Windows output. -PRINTER:HP for HP LaserJet output.sqr modified to prompt the user to select the printer type at run time. you can specify the printer at run time in two ways.Writing Printer-Independent Reports SQR 4. which specifies the output type for your report.’ 112 SQR User’s Guide . Eps-file images can only be printed on PostScript printers. The first way is to use the -PRINTER:xx command-line flag. or -PRINTER:HT for HTML output.3 • Be aware of certain limitations. PRINTIMAGE and PRINT-CHART may not work with old printers that use PostScript Level 1 or HP LaserJet Series II. If you are using VisualSQRIBE. Use -PRINTER:LP for lineprinter output. enter this command-line flag in the Parameters field of the Run dialog box. If you are using the system shell. The added lines are shown in bold type. you can see the PROGRAM section of the program ex3a. If your report is printer-neutral and does not specify a printer. Bmp-file images can only be printed using Windows. In the next example. begin-program input $p ’Printer type’ let $p = lower($p) evaluate $p when = ’hp’ when = ’hplaserjet’ use-printer-type hp break when = ’lp’ when = ’lineprinter’ use-printer-type lp break when = ’ps’ when = ’postscript’ use-printer-type ps break when-other display ’Invalid printer stop end-evaluate ! Prompt user for printer type ! Convert type to lowercase ! Case statement ! HP LaserJet ! Line Printer ! PostScript type. Hpgl-file images can only be printed on HP LaserJet Series 3 or higher or printers that emulate HP PCL at that level. Gif-file and jpeg-file images are suitable only for HTML output. -PRINTER:PS for PostScript output.

the INPUT command prompts the user to enter the printer type. The next chapter describes how to produce reports that vary according to the report parameters and selection criteria supplied by the user. the EVALUATE command is used to test for the six possible values and set the printer type accordingly. The EVALUATE command is similar to a switch statement in the C language. It compares a variable to multiple constants and executes the appropriate code. Summary • Reports can be made printer-independent by writing programs that do not require a certain printer.3 Writing Printer-Independent Reports do list_customers end-program In the code above.SQR 4. SQR User’s Guide 113 . Because the USE-PRINTER-TYPE command does not accept a variable as an argument. • The -PRINTER:xx command-line flag and the USE-PRINTER-TYPE and EVALUATE commands prompt the user to specify the printer at run time.

.

the database can parse the statement before the values for the variables are given. SQR User’s Guide 115 . Since SQL only allows variables in places where literals are allowed (such as in a WHERE clause or INSERT statement). SQR provides three ways to vary a SQL statement: • Using variables in SQL • Dynamic SQL • SQL and substitution variables SQR provides three ways to do error checking: • ON-ERROR procedures • Commands with ON-ERROR options • The INPUT command These techniques are described in more detail in the following sections. Using Variables in SQL The SQL language supports the use of variables. even if the values of the variables change. A SQL statement containing variables is considered static. When SQR executes this statement several times. it is considered as executing the same statement. This sample program selects customers from a state that the user specifies.16 Dynamic SQL and Error Checking This chapter describes how to vary the SQL statement based on a user’s selection criteria or other report parameters.

INPUT reprompts. At the prompt. state is uppercase in the database. When you run this program. enter IN. SQR allows you to write database-independent code by moving the use of such SQL extensions to the SQR code. The program converts the contents of the $state variable to uppercase. SQR "binds" the variable before the SQL is executed. NH. The example shows the LET command used with the SQR upper function. NY. In this program. When you use a variable in a SQL statement in SQR. If you enter NY (the state where most of the customers in the sample data reside). the SQL statement sent to the database contains that variable.3 Program ex16a.Dynamic SQL and Error Checking SQR 4. SQR will generate the output shown below. You would do so by using "where state = upper($state)" if you are using Oracle or SYBASE or by using "where state = ucase($state)" if you are using another database. the database only needs to parse the SQL statement once. which allows the user to input the state without worrying about the case. If the entry is incorrect. You could let the SQL perform the conversion to uppercase. ensuring that the user enters a string of no more than two characters. The only thing that changes between executions of the SELECT statement is the value of the variable. This is the most common example of varying a SELECT statement. the INPUT command prompts the user to enter the value of state. MI.1) position (+1) from customers where state = $state end-select end-procedure ! list_customers_for_state Note the use of the $state variable in the SELECT paragraph. NM. However.sqr begin-program do list_customers_for_state end-program begin-procedure list_customers_for_state input $state maxlen=2 type=char ’Enter state abbreviation’ let $state = upper($state) begin-select name (. you must specify one of the states included in the sample data for the program to return any records. 116 SQR User’s Guide . or OH. NJ. In many cases. The arguments MAXLEN and TYPE check the input. In the example.

Dynamic SQL You may find the restriction against using variables where only literals are allowed too limiting in some cases. To take full advantage of the error-handling procedure. city The second SELECT statement will be: select city. SQR User’s Guide 117 . The second time.sqr Alfred E Newman & Company Eliot Richards Harriet Bailey Kate’s Out of Date Dress Shop Corks and Bottles. The program runs the SELECT twice. In the following example. the ordering of the records is changed based on the user’s selection. the first column is called name and the second column is called city. and the program sorts the records by name with a secondary sort by city. name As you can see.SQR 4. name from customers order by city. It is illustrated in the following example. Inc. The first SELECT statement will therefore be: select name. the first column is the city and the second is name. SQR actually constructs the statement each time before executing it. The first time. city from customers order by name. and the program sorts by city with a secondary sort by name. the statements are different. run it with the command-line flag -CB. This technique is called dynamic SQL.3 Dynamic SQL and Error Checking Output for ex16a.

a new statement is compiled and executed.Dynamic SQL and Error Checking SQR 4. Note that the data in the first half of the report is sorted differently than the data in the second half. SQR will place the text from the variable $my_order in that statement." 118 SQR User’s Guide . when you use the dynamic variable [$my_order] in the ORDER BY clause of the SELECT statement. you make them dynamic variables by enclosing them in square brackets.sqr begin-program let $col1 = ’name’ let $col2 = ’city’ let #pos = 32 do list_customers_for_state position (+1) let $col1 = ’city’ let $col2 = ’name’ let #pos = 18 do list_customers_for_state end-program begin-procedure give_warning display ’Database error occurred’ display $sql-error end-procedure ! give_warning begin-procedure list_customers_for_state let $my_order = $col1 || ’. if the text changes. You can use dynamic variables to produce reports like this one. They substitute the names of the columns in the SELECT statement.1) [$col2] &column2=char (. The variables &column1 and &column2 are column variables.3 Program ex16b. Each time the statement is executed.#pos) position (+1) from customers order by [$my_order] end-select end-procedure ! list_customers_for_state When you use variables in a SQL statement in SQR to replace more than literals. Note the error-handling procedure give_warning. Other dynamic variables used are [$col1] and [$col2].’ || $col2 begin-select on-error=give_warning [$col1] &column1=char (. It is discussed below in "SQL Error Checking. For example.

and abort the program. Kate’s Out of Date Dress Shop Eliot Richards Clair Butterfield Isaiah J Schwartz and Company SQL Error Checking SQR checks and reports database errors for SQL statements. the content of the dynamic variable is used to construct the SQL statement. Eliot Richards Gregory Stonehaven Harold Alexander Fink Harriet Bailey Harry’s Landmark Diner Isaiah J Schwartz and Company Jerry’s Junkyard Specialties Joe Smith and Company Kate’s Out of Date Dress Shop Quentin Fields Sam Johnson Bell Harbor Big Falls Cleveland Davenport Everretsville Frogline Mamaroneck Miningville New York New York New York Queens Teaneck Zanesville New York Teaneck New York Queens Everretsville Davenport Mamaroneck Miningville Zanesville Frogline Big Falls New York Cleveland Bell Harbor Sam Johnson Joe Smith and Company Quentin Fields Harold Alexander Fink Gregory Stonehaven Jerry’s Junkyard Specialties Harriet Bailey Harry’s Landmark Diner Alfred E Newman & Company Corks and Bottles. When an SQR program is compiled. In that case. Errors could occur if the dynamic variables selected or used in a WHERE or ORDER BY clause were incorrect. If you want to change this default behavior. use the ON-ERROR option of the BEGIN-SELECT or BEGIN-SQL paragraphs.SQR 4. and DELETE SQL statements in your program. INSERT. When you use dynamic SQL. SQR cannot check the syntax until run time.3 Dynamic SQL and Error Checking Output for ex16b. which can allow syntax errors to occur in run time. report the error. Inc. UPDATE. SQR checks the syntax of the SELECT. Inc. SQR User’s Guide 119 .sqr Alfred E Newman & Company Clair Butterfield Corks and Bottles. before the execution of the report begins. Any SQL syntax error will be detected and reported at compile time. SQR will trap any run-time error.

see the table "SQR Reserved Variables" in the SQR Language Reference. argument. The value that the user enters is placed in a special kind of variable called a substitution variable. 120 SQR User’s Guide . or predefined. SQL and Substitution Variables SQR uses the value of this substitution variable to complete the SELECT statement at compile time. the ASK command in the SETUP section prompts the user at compile time. the value of {my_order} cannot change and the SQL statement is considered static. the variable $sqr-program has the name of the program that is running.3 begin-select on-error=give_warning [$col1] &column1=char (.#pos) position (+1) from customers order by [$my_order] end-select In the above example. but it demonstrates the difference between compile-time and run-time substitutions. Write this procedure as follows: begin-procedure give_warning display ’Database error occurred’ display $sql-error end-procedure ! give_warning This procedure displays the error message but does not abort the execution of the program. execution would continue at the statement immediately following the SQL or SELECT paragraph. In the following program. SQR has a number of reserved. Because the SELECT statement is complete at compile time. and they are very useful. From this point on. The variable $username has the user name that was used to log on to the database. SQR can check its syntax before execution begins. This example is less common.Dynamic SQL and Error Checking SQR 4. The variable #page-count has the page number for the current page. This variable can be used to substitute any command. For example. Instead. Note the use of the variable $sql-error. For a complete list of reserved variables. SQR will invoke a procedure called give_warning instead of reporting the problem and aborting. if a database error occurs. variables. This is a special SQR reserved variable. or part of a SQL statement at compile time. It contains the error message text from the database and is automatically set by SQR after a database error occurs.1) [$col2] &column2=char (.

We have seen an example of reprompting in the section "Using Variables in SQL. You can validate the length and type of data input and reprompt if it is not valid. all ASK commands are performed before any INPUT command is performed.SQR 4. INPUT is more flexible than ASK. Substitution variables set in an ASK command let you modify commands that are normally quite restrictive.3 Dynamic SQL and Error Checking Program ex16c. SQR User’s Guide 121 . The program will produce a report sorted accordingly.sqr begin-setup ask my_order ’Enter the column name to sort by (name or city)’ end-setup begin-program do list_customers_for_state end-program begin-procedure give_warning display ’Database error occurred’ display $sql-error end-procedure ! give_warning begin-procedure list_customers_for_state begin-select on-error=give_warning name (. When you run this program. You can use INPUT inside loops. ASK commands are always performed at compile time before program execution begins." earlier in this chapter. or both (in either order and separated by a comma).32) position (+1) from customers order by {my_order} end-select end-procedure ! list_customers_for_state In this case. there will be no prompt. city. The following code shows this technique.1) city (. Therefore. which will be used to sort the output. ASK can be more powerful. The ASK command can only be used in the SETUP section. enter name. If the argument is passed on the command line. the ASK command prompts the user for the value of the substitution variable {my_order}.

Dynamic SQL and Error Checking

SQR 4.3

begin-setup ask hlines ’Number of lines for heading’ end-setup begin-program print ’Hello, World!!’ (1,1) end-program begin-heading {hlines} print ’Report Title’ () center end-heading

In this example, the substitution variable {hlines} defines the number of lines that the heading will occupy. The BEGIN-HEADING command normally expects a literal and does not allow a run-time variable. When a substitution variable is used with this command, its value is modified at compile time. For further information on the ASK and INPUT commands, see Chapter 25, "Compiling Programs and Using SQR Execute."

Summary
• Dynamic variables are variables used in a SQL statement to replace more than literals. They are enclosed in square brackets. • You can customize SQR’s run-time error handling. • SQR has a number of reserved variables. For a full listing, see the table "SQR Reserved Variables" in the SQR Language Reference. • Substitution variables entered by the ASK command can be used in place of any command, argument, or SQL statement at compile time. They are enclosed in curly braces.
In the next chapter, you will learn more about SQR procedures.

122

SQR User’s Guide

17

Procedures, Argument Passing, and Local Variables
This chapter examines SQR procedures. It explains how to pass parameters and illustrates the difference between global and local procedures. In particular, it shows how to reference global variables from within a local procedure. The sample code in this chapter shows a procedure that spells out a number and a program for printing checks that uses this procedure. When printing checks, you normally need to spell out the dollar amount, as shown below.

In the sample program, it is assumed that the checks are preprinted and that our program only has to print such items as the date, name, and amount.

Procedures
SQR procedures that contain variables which are visible throughout the program are called global procedures. These procedures can also directly reference any program variable.

SQR User’s Guide

123

Procedures, Argument Passing, and Local Variables

SQR 4.3

In contrast, procedures that take arguments, such as the spell_number procedure in this chapter’s check-printing sample code, are local procedures. In SQR, any procedure that takes arguments is automatically considered local. Variables introduced in a local procedure are only readable inside the procedure. This useful feature avoids name collisions. In the sample program, the spell_number procedure is placed in an include file because other reports may also want to use it.

Local Variables
When you create library procedures that may be used in many programs, make them local. Then, if a program has a variable with the same name as a variable used in the procedure, there will not be a collision. SQR treats the two variables as separate. We recommend that you declare a procedure as local even if it does not take any arguments. Simply place the keyword LOCAL after the procedure name in the BEGIN-PROCEDURE command. To reference a global variable from a local procedure, insert an underscore between the prefix character (#, $, or &) and the variable name. Note also that the same technique is used to reference reserved variables such as #current-line. These variables are always global. You can reference #_current-line from a local procedure. SQR supports recursive procedure calls, but it maintains only one copy of a local variable. A procedure will not allocate new instances of the local variables on a stack, as C or Pascal would.

Argument Passing
Procedure arguments are treated as local variables. Arguments may be either numeric, date, or text variables or strings. If an argument is preceded with a colon, its value will be passed back to the calling procedure. In the example below, spell_number takes two arguments. The first argument is the check amount. This argument is a number, and the program passes it to the procedure. There is no need for the procedure to pass it back.

124

SQR User’s Guide

SQR 4.3

Procedures, Argument Passing, and Local Variables

The second argument is the result that the procedure passes back to the calling program. We precede this variable with a colon, which means that the value of this argument will be copied back at the end of the procedure. The colon is only used when the argument is declared in the BEGIN-PROCEDURE command. Look at the following code. It’s not a complete program. It’s the spell_number procedure, which is stored in the file spell.inc. The checkprinting program will include this code using an #INCLUDE command. File spell.inc
begin-procedure spell_number(#num,:$str) let $str = ’’ ! break the number to it’s 3-digit parts let #trillions = floor(#num / 1000000000000) let #billions = mod(floor(#num / 1000000000),1000) let #millions = mod(floor(#num / 1000000),1000) let #thousands = mod(floor(#num / 1000),1000) let #ones = mod(floor(#num),1000) ! spell each 3-digit part do spell_3digit(#trillions,’trillion’,$str) do spell_3digit(#billions,’billion’,$str) do spell_3digit(#millions,’million’,$str) do spell_3digit(#thousands,’thousand’,$str) do spell_3digit(#ones,’’,$str) end-procedure ! spell_number begin-procedure spell_3digit(#num,$part_name,:$str) let #hundreds = floor(#num / 100) let #rest = mod(#num,100) if #hundreds do spell_digit(#hundreds,$str) concat ’hundred ’ with $str end-if if #rest do spell_2digit(#rest,$str) end-if if #hundreds or #rest if $part_name != ’’ concat $part_name with $str concat ’ ’ with $str end-if end-if end-procedure ! spell_3digit

Program continues on the following page.

SQR User’s Guide

125

Procedures, Argument Passing, and Local Variables

SQR 4.3

File spell.inc (continued)
begin-procedure spell_2digit(#num,:$str) let #tens = floor(#num / 10) let #ones = mod(#num,10) if #num < 20 and #num > 9 evaluate #num when = 10 concat ’ten ’ with $str break when = 11 concat ’eleven ’ with $str break when = 12 concat ’twelve ’ with $str break when = 13 concat ’thirteen ’ with $str break when = 14 concat ’fourteen ’ with $str break when = 15 concat ’fifteen ’ with $str break when = 16 concat ’sixteen ’ with $str break when = 17 concat ’seventeen ’ with $str break when = 18 concat ’eighteen ’ with $str break when = 19 concat ’nineteen ’ with $str break end-evaluate else evaluate #tens when = 2 concat ’twenty’ with $str break when = 3 concat ’thirty’ with $str break when = 4 concat ’forty’ with $str break

Program continues on the following page.

126

SQR User’s Guide

:$str) evaluate #num when = 1 concat ’one ’ with $str break when = 2 concat ’two ’ with $str break when = 3 concat ’three ’ with $str break when = 4 concat ’four ’ with $str break when = 5 concat ’five ’ with $str break when = 6 concat ’six ’ with $str break Program continues on the following page.SQR 4.$str) end-if end-if end-procedure ! spell_2digit begin-procedure spell_digit(#num.inc (continued) when = 5 concat ’fifty’ with $str break when = 6 concat ’sixty’ with $str break when = 7 concat ’seventy’ with $str break when = 8 concat ’eighty’ with $str break when = 9 concat ’ninety’ with $str break end-evaluate if #num > 20 if #ones concat ’-’ with $str else concat ’ ’ with $str end-if end-if if #ones do spell_digit(#ones.3 Procedures. and Local Variables File spell. Argument Passing. SQR User’s Guide 127 .

millions. and Local Variables SQR 4. billions.inc (continued) when = 7 concat break when = 8 concat break when = 9 concat break end-evaluate end-procedure ! ’seven ’ with $str ’eight ’ with $str ’nine ’ with $str spell_digit The result argument is reset in the procedure. The program only supports numbers up to 999 trillion. and ones. These functions are listed and described under the LET command in the SQR Language Reference. This is the full program that prints the checks. Note the use of math functions such as floor and mod. thousands.3 File spell." Note that the word and is inserted only between dollars and cents. SQR has a rich set of functions that can be used in expressions. Another procedure spells out the three-digit numbers such as "one hundred twelve. The series of EVALUATE commands in the number-spelling procedures are used to correlate the numbers stored in the variables with the strings used to spell them out.inc’ begin-setup declare-layout default end-declare end-setup Program continues on the following page. but not between three-digit parts. 128 SQR User’s Guide .sqr #include ’spell.Procedures. This format is common for check printing in dollars. The number is broken into its three-digit parts: trillions. Argument Passing. Program ex17a. because the program begins with an empty string and keeps concatenating the parts of the number to it.

3 Procedures.45) edit ’DD-Mon-YYYY’ print &_name (8. 0) let $cents_amount = ’and ’ || edit(#cents.12) print ’Rebate’ (16.12) move #amount to $display_amt 9.#len .’00’) || ’ cents’ concat $cents_amount with $spelled_amount print $spelled_amount (12.00 let $spelled_amount = ’Zero dollars ’ else do spell_number(#amount.’ ’) || ’**’ print $display_amt (8.2.12) print ’ ’ (20) next-listing need=20 end-procedure ! print_check The main procedure starts by setting the font to 15-point Times Roman.order_num and c.sqr (continued) begin-program do main end-program begin-procedure main alter-printer font=5 point-size=15 begin-select name &name sum(d. Argument Passing. SQR User’s Guide 129 .1)) || substr($spelled_amount.price * c. ordlines c.SQR 4. The SELECT paragraph is a join of several tables.999.58) if #amount < 1.1) concat ’dollars ’ with $spelled_amount end-if let #cents = round(mod(#amount.10 >= 0. products d where a.99 ! enclose number with asterisks for security let $display_amt = ’**’ || ltrim($display_amt.product_code = d.1.01 end-select end-procedure ! main begin-procedure print_check(#amount) print $_current-date (3.1) * 100. It also joins with the products table for the price.quantity) * 0. (A join is created when you select data from more than one database table in the same SELECT paragraph.10 &refund do print_check(&refund) from customers a.quantity) * 0. The program joins it with the orders and ordlines tables to get the customer’s order details.cust_num and b. orders b.990.price * c.product_code group by name having sum(d.$spelled_amount) let #len = length($spelled_amount) ! Change the first letter to uppercase let $spelled_amount = upper(substr($spelled_amount.) The customers table has the customer’s name. and Local Variables Program ex17a.order_num = c.cust_num = b.

• To pass an argument back to its calling procedure. Summary • Variables in global procedures are visible throughout the program. Argument Passing. • Variables in local procedures are visible only within the procedure. place an underscore between the prefix character #.3 The following expression adds up all of the customer’s purchases and calculates a 10 percent rebate: sum(d. respectively.01 The HAVING clause eliminates checks for less than 1 cent. The next chapter shows how to create multiple reports simultaneously from one program.quantity) * 0. This is done with the clause: group by name having sum(d.10 The statement groups the records by the customer name.quantity) * 0. or & and the variable name. Note the way it references the date and customer name with &_current-date and &_name. $.10 >= 0. 130 SQR User’s Guide . and Local Variables SQR 4.Procedures. one check per customer. preface it with a colon.price * c. • To reference a global variable from a local procedure.price * c. The procedure print_check is a local procedure.

The sample program will print three reports—the labels from Chapter 9. selecting the database records only once and creating different reports simultaneously.18 Multiple Reports This chapter shows you how to create multiple reports from one program. Program ex18a. In the following example.sqr #define MAX_LABEL_LINES #define LINES_BETWEEN_LABELS 10 3 begin-setup declare-layout labels paper-size=(10. Repeated queries are costly because database operations are often the most resource-consuming or time-consuming part of creating a report. You can create multiple reports based on common data. SQR User’s Guide 131 .11) left-margin=0. All three reports are based on exactly the same data. and the listing report from Chapter 3. This powerful feature can save a significant amount of processing time. the form letter from Chapter 10.33 end-declare declare-layout form_letter end-declare declare-layout listing end-declare declare-report labels layout=labels end-declare declare-report form_letter layout=form_letter end-declare declare-report listing layout=listing end-declare end-setup Program continues on the following page. you will see how SQR allows you to write multiple reports with different layouts and different heading and footing sections. The alternative—writing separate programs for the different reports— would require you to perform a separate database query for each report.

30) let $last_line = &city || ’.1.30) print &addr1 (2.1.3 Program ex18a.1.Multiple Reports SQR 4. ’ || &state || ’ ’ || $zip print $last_line (3.sqr (continued) begin-program do main end-program begin-procedure main do init_mailing_labels begin-select name addr1 addr2 city state zip move &zip to $zip xxxxx-xxxx phone do print_label do print_letter do print_listing from customers end-select do end_mailing_labels end-procedure ! main begin-procedure init_mailing_labels let #label_count = 0 let #label_lines = 0 use-report labels columns 1 29 57 ! enable columns alter-printer font=5 point-size=10 end-procedure ! init_mailing_labels begin-procedure print_label use-report labels print &name (1. 132 SQR User’s Guide .30) next-column at-end=newline add 1 to #label_count if #current-column = 1 add 1 to #label_lines if #label_lines = {MAX_LABEL_LINES} new-page let #label_lines = 0 else next-listing no-advance skiplines={LINES_BETWEEN_LABELS} end-if end-if end-procedure ! print_label Program continues on the following page.

end-document position () @city_state_zip print &city () print ’.b . our entire inventory is marked down by 25%.999. We would like to tell you about our limited time offer.SQR 4.b $current-date Dear Sir or Madam: . .999 end-procedure ! end_mailing_labels begin-procedure print_letter use-report form_letter begin-document (1. Clark Axelotle ACME Inc.1) print $current-date () print ’Total labels printed = ’ (+1.b Sincerely.sqr (continued) begin-procedure end_mailing_labels use-report labels use-column 0 ! disable columns new-page print ’Labels printed on ’ (.1) print #label_count () edit 9.b Thank you for your recent purchases from ACME Inc. To place an order simply dial 800-555-ACME. SQR User’s Guide 133 .1) &name &addr1 &addr2 @city_state_zip . so don’t wait. ’ () print &state () print ’ ’ () move &zip to $zip xxxxx-xxxx print $zip () new-page end-procedure ! print_letter Program continues on the following page. Delivery is free too. During this month.b . you can buy your favorite merchandise and save too.3 Multiple Reports Program ex18a. Yes.

32) print &state (.55) end-heading begin-footing 1 for-reports=(listing) ! Print "Page n of m" in the footing page-number (1. Each procedure begins by setting the SQR printing context to its corresponding report. and print_listing prints one line into the listing report. The labels report requires a layout that is different from the default. Each procedure processes one record for its corresponding report. 134 SQR User’s Guide . For each record selected.3 Program ex18a.sqr (continued) begin-heading 4 for-reports=(listing) print ’Customer Listing’ (1) center print ’Name’ (3. The other columns are used in more than one report. The main procedure performs the SELECT. It would be possible to save the last layout declaration and use the form-letter layout for the listing.49) print &phone (. However.1) print ’City’ (.Multiple Reports SQR 4. print_letter prints one letter. The phone column is only used in the listing report and the addr2 column is only used in the form-letter report. The name of the layout indicates which report uses it. unless there is a logical reason why the two layouts should be the same. The other two reports use a layout that is identical to the default layout. SQR sets the printing context with the USE-REPORT command.55) position (+1) end-procedure ! print_listing The SETUP section defines three layouts and three different reports that use these layouts. The print_label procedure prints one label.1) ’Page ’ last-page () ’ of ’ end-footing begin-procedure print_listing use-report listing print &name (. three procedures are executed.1) print &city (.49) print ’Phone’ (. it is better to keep separate layouts. Note that it is only performed once and includes all the columns for all the reports.32) print ’State’ (.

If you specify -KEEP. you may omit -KEEP.SQR 4. • The FOR-REPORTS option of BEGIN-HEADING and BEGIN-FOOTING defines headings and footings for individual reports. the Viewer window will open automatically after you run the programs.spf. respectively. These output files will have the names ex18a. will be displayed.sqr.lis (labels).sqr. ex10a. Summary • Writing multiple reports simultaneously with one program reduces database queries. but only the first output file. The parentheses are required. and ex18a.sqr.sqr is taken from ex9a. ex18a. and ex18a. the output files will be named ex18a. respectively.spf.sqr. (If you are running the report with VisualSQRIBE. ex18a. SQR User’s Guide 135 . • USE-REPORT sets the printing context for each report.l02 (customer listing). you get three output files that match the output files for ex9a. Because this program creates output with proportional fonts.) When you run ex18a. The report is implied by the FOR-REPORTS option. and ex3a. Most of the code for ex18a. because the other two reports do not use them. This example only defines the heading and footing for the listing report. ex10a. See Chapter 9 for more information on running reports with proportional fonts. you must run it with the -KEEP or -PRINTER:xx command-line flags.l01 (form letter). You can view the other output files by selecting File→Open. The next chapter explains how to integrate SQL statements other than SELECT with SQR.s02. and ex3a. Note that the USE-REPORT command is not needed in the heading or the footing. The FOR-REPORTS option of the BEGIN-HEADING and BEGIN-FOOTING commands specifies the report name.s01. • You can define separate reports in the SETUP section. ex18a.3 Multiple Reports SQR allows you to define HEADING and FOOTING sections for each report. If you are running VisualSQRIBE.

.

These are only a few examples. or invoices. you can create two SQL paragraphs in your SQR program (CREATE TABLE and DROP TABLE) to create this table at the beginning of the program and drop the table at the end. This program loads the tab-delimited file created by the program ex11a. tickets. Using BEGIN-SQL To perform a SQL statement other than a SELECT statement you must use the BEGIN-SQL paragraph. It demonstrates two important features of SQR—handling external files and performing database inserts. you can also perform other SQL commands in SQR. Here are a few examples: • If the program prints important documents such as checks. SQR can read and write external files and construct records. and this feature is used often. The following example loads data from an external file into the database. • If you need to hold intermediate results in a temporary database table. you may need to update the database to indicate that the document was printed. SQR can perform any SQL statement.sqr. • You can use SQR to load data into the database. This is easily performed in SQR with a SQL UPDATE statement. SQR User’s Guide 137 . SQR can also insert these records into the database using a SQL INSERT statement.19 Using DML and DDL SQL Statements Although SELECT may be the most common SQL statement.

phone varchar (10). name varchar (30). $city. state. addr2. state varchar (2). $state. zip varchar (10). 138 SQR User’s Guide . addr1.3 Program ex19a. $zip. name. phone. tot) values (#cust_num.Using DML and DDL SQL Statements SQR 4. city. zip.lis’ as 1 for-reading record=160:vary read 1 into $rec:160 ! skip the first record. city varchar (16). $addr2. tot int ) end-sql end-setup begin-program do main end-program begin-procedure main #if {sqr-database} = ’Sybase’ begin-sql begin transaction end-sql #endif encode ’<009>’ into $sep open ’ex11a.sqr begin-setup begin-sql on-error=skip ! table may already exist create table customers_ext ( cust_num int not null. addr1 varchar (30). addr2 varchar (30). #tot) end-sql end-while Program continues on the following page. column headings while 1 read 1 into $rec:160 if #end-file break end-if unstring $rec by $sep into $cust_num $name $addr1 $addr2 $city $state $zip $phone $tot move $cust_num to #cust_num move $tot to #tot begin-sql insert into customers_ext (cust_num. $phone. $name. $addr1.

see the SQR Language Reference. For Oracle databases. To ignore this error message. Note that #end-file is an SQR reserved variable. The changes are committed with a SQL COMMIT statement inside a BEGIN-SQL paragraph. If the table already exists you will get an error message. For a complete listing of reserved variables. for example. with each field separated by the separator character.sqr (continued) #if {sqr-database} = ’Sybase’ begin-sql commit transaction end-sql #else #if {sqr-database} <> ’Informix’ begin-sql commit end-sql #endif #endif close 1 end-procedure ! main The program starts by creating the table customers_ext. When the end of the file is encountered (if #end-file). much like the SYBASE example of BEGIN TRANSACTION and COMMIT TRANSACTION. The program reads the records from the file and inserts each record into the database by using an INSERT statement inside a BEGIN-SQL paragraph. Alternatively. Dynamic SQL and Error Checking. SQR User’s Guide 139 . use the ON-ERROR=SKIP option. The input file format is one record per line.SQR 4. and your database was created with transaction logging. the program branches out of the loop. you must add a BEGIN WORK and a COMMIT WORK. If you are using Informix." for more information on error handling. you can use the SQR COMMIT command. we recommend you use the SQR COMMIT. Note that the code may be database-specific. See Chapter 16. The last step is to commit the changes to the database and close the file.3 Using DML and DDL SQL Statements Program ex19a.

use the SQR COMMIT. For Oracle databases.Using DML and DDL SQL Statements SQR 4. 140 SQR User’s Guide . The next chapter explains how to work with dates in SQR.3 Summary • A BEGIN-SQL paragraph can be used to perform SQL statements other than SELECT. • To insert database records. use SQL commands such as INSERT and COMMIT inside the BEGIN-SQL paragraph.

SQR User’s Guide 141 . We strongly recommend that you always keep dates with four-digit year values (and not truncate to two digits) to avoid date problems at the turn of the century. 9999 A. • By referencing or printing the reserved variable $current-date. or strdodate. Date variables will be discussed later in this chapter. Date Arithmetic Many applications require date calculations. • As a result of an SQR date function: dateadd. or compare dates to find if one date is later. SQR has powerful capabilities in date arithmetic. A date can be represented as a character string or in an internal format using the SQR date datatype. it is not necessary to declare date variables. earlier. For most applications. datenow. • By declaring a date variable using the DECLARE-VARIABLE command. or the same as another date.20 Working with Dates This chapter explains how to handle dates with SQR. editing. and manipulation. datediff. SQR allows you to easily perform these calculations in your program.D. You will learn the best way to handle dates in a program. Date values can be obtained in one of five ways: • By selecting a date column from the database. subtract one date from another to find a time difference. You may need to add or subtract a number of days from a given date. The date datatype allows you to store dates in the range of January 1. It also stores the time of day with the precision of a microsecond. to December 31.C. • By using INPUT to get a date from the user. 4712 B. The internal date representation always keeps the year as a four-digit value.

$current-date.Working with Dates SQR 4. minutes. subtract. or seconds. Fractions are allowed—you can add 2. because the syntax varies between databases. quarters. You can compare dates by using the usual operators (< . The datetostr function converts a date to a string. The datediff function returns the difference between two specified dates in the time units you specify—years." If the invoice is 30 days old or less. or compare dates using days and state the difference using weeks. SQR provides a reserved date variable. If the invoice is older than 30 days. months. the program prints the string "Current Order. The datenow function returns the current local date and time." 142 SQR User’s Guide . The resulting date is then compared with the current date.30) < datenow() print ’Past Due Order’ (. hours. perform those calculations in SQR—your programs will be portable.5 days to a given date. days.1) invoice_date if dateadd(&invoice_date.12) else print ’Current Order’ (.’day’. which is returned by datenow. the functions dateadd and datenow are used to compare dates. The function dateadd adds 30 days to the invoice date (&invoice_date). The following code uses functions to add 30 days to the invoice date and compare it to the current date: begin-select order_num (. weeks. Conversion between time units is also allowed—you can add. because they won't rely on a particular SQL syntax. which is automatically initialized with the local date and time at the beginning of the program. =. but that can be awkward if you are trying to write portable code. The strtodate function converts a string to a date.3 Many databases allow you to perform date calculations in SQL. The dateadd function adds or subtracts a number of specified time units from a given date. In addition. the program prints the string "Past Due Order.12) end-if position (+1) end-select In this example. Instead. or >) in an expression.

3 Working with Dates To subtract a given number of days from a date. In the next example. Note that the comparison is now a simple numeric comparison.’dd/mm/yyyy’). If the date includes the time of day. and year. which is compared with the column &order_date. When the order date is later than January 3. the date is truncated to remove the time-of-day portion of a date: if strtodate(datetostr(&order_date. the condition is satisfied. Now when it is compared with January 3. The condition is equivalent to that of the previous example. and they demonstrate the flexibility provided by these functions. The strtodate function then converts this value back into a date. SQR User’s Guide 143 .’day’) > 30 All three IF statements are equivalent. the comparison will be satisfied for orders of January 3. use the dateadd function with a negative argument. only dates that are of January 4 or later will satisfy the condition. the timeof-day portion of the order date is omitted. With these two conversions. Here is another technique for comparing dates: begin-select order_date if &order_date > strtodate(’3/1/1996’. if &invoice_date < dateadd(datenow().-30) This condition can also be written as follows using the datediff function. 1996.’dd/mm/yyyy’) In this example. The strtodate function returns a date type.’day’. 1996 with a time of day greater than 00:00. not a date comparison: if datediff(datenow().&invoice_date. the IF condition compares the invoice date with the date of 30 days before today.’dd/mm/yyyy’) > strtodate(’3/1/1996’. month. This technique is demonstrated in the next example.’dd/mm/yyyy’) print ’Current Order’ () else print ’Past Due Order’ () end-if from orders end-select The IF statement has a date column on the left side and the strtodate function on the right side. the datetostr function converts the order date to a string that only stores the day. In this example. 1996.SQR 4.

The time portion defaults to 00:00.INI file. The respective outputs (when printed with the edit mask ’DD-MON-YYYY HH:MI AM’) will be: 09-APR-1996 12:00 AM 09-APR-1996 03:20 PM You can also specify a date format with the environment variable SQR_DB_DATE_FORMAT. You may omit one or more time elements from the right part of the format. The second LET statement assigns 3:20 in the afternoon of April 9. The following digits represent year. A default is assumed for the missing elements. and microseconds. day. 1996 to the variable $a. À Note The literal date format assumes a 24-hour clock.C.INI file.Working with Dates SQR 4. see the chapter "SQR. This is called the literal date format. the string represents a date B. you can use a value in this format in the strtodate function without the use of an edit mask. For more information on the SQR. Here are some examples: let $a = strtodate(’19960409’) let $a = strtodate(’19960409152000’) The first LET statement assigns the date of April 9.INI" in the SQR Language Reference. month. The first S in this format represents an optional minus sign. minutes. This format can be specified as an environment variable or specified in the SQR. For example. The literal date format is SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]. hours. This format has the advantage of being independent of any specific database or language preference.3 Date Formats SQR allows you to specify date constants and date values in a special format that is recognized without the use of an edit mask. seconds. 1996 to $a. 144 SQR User’s Guide . If preceded with a minus sign.

SQR will apply a date format. This implicit conversion will take place with the following commands: • MOVE • The datetostr function • The commands DISPLAY. The literal date format SYYYYMMDD[HH24[MI[SS[NNNNNN]]]]. Date to String Conversions If you convert a date variable to a string without specifying an edit mask. when used to output a string variable as a date. SQR will apply a date format.SQR 4. when used to output a date variable SQR will attempt to apply date formats in the following order: 1. This implicit conversion will take place with the following commands: • MOVE • The strtodate function • The commands DISPLAY. SQR will attempt to apply date formats in the following order: 1. The format specified in SQR_DB_DATE_FORMAT 2. or SHOW. or SHOW. The format specified in SQR_DB_DATE_FORMAT 2. PRINT. The database-dependent format Database-dependent formats are listed in the table "Default Database Formats" in the SQR Language Reference. SQR User’s Guide 145 . PRINT.3 Working with Dates String to Date Conversions If you convert a string variable or constant to a date variable without specifying an edit mask that identifies the format of the string. The database-dependent format 3.

MONTH-YYYY HH:MI ’HH:MI AM’ MARCH-1996 09:35 09:35 AM Table 3. For example: print &order_date () edit ’Month dd. YYYY. The user then types in the value. the edit masks produce the following results: Edit Mask dd/mm/yyyy DD-MON-YYYY ’Month dd.Working with Dates SQR 4. use the TYPE=DATE qualifier. Please refer to the table "Date Edit Format Codes" in the SQR Language Reference for a complete listing. If the value of the date value being edited is March 14. Description Edit mask containing blank space must be enclosed in single quotes. For string variables.’ Result 14/03/1996 14-MAR-1996 March 14. you can format them with an edit mask. 1996 at 9:35 in the morning. Date Edit Masks When you print dates. A format for the date should be specified. The name of the order date month will be printed followed by the day of the month. Edit mask containing blank space must be enclosed in single quotes. Sample Date Edit Masks 146 SQR User’s Guide .3 Using Dates with the INPUT Command The INPUT command also supports dates. A date can be loaded into a date or string variable. 1996. which is validated as a date using the "dd/mm/yyyy" format. a comma. Name of the month in uppercase followed by four-digit year Meridian indicators. The value is loaded into the variable $start_date. SQR provides a rich set of date edit masks. Here is an example: input $start_date ’Enter starting date’ format=’dd/mm/yyyy’ type=date In this example. and four-digit year. the user is prompted with "Enter starting date:" (the colon is automatically added). YYYY’ This command will print the order date in the specified format.

YY Mon Day DY Q WW W DDD DD D Result 19960314 14. Without the backslashes the output string would be "The march is march". they are simply printed. One example is the mask ’DDDD’.MM. and ’D’ (day of week). SQR User’s Guide 147 . combining date edit mask elements may result in ambiguity. In some cases.96 Mar Thursday THU 1 11 2 74 14 5 Description Abbreviated name of the month Day of the week Abbreviated name of day of the week Quarter Week of the year Week of the month Day of the year Day of the month (1-31) Day of the week (Sunday = 1) Table 3. it is also printed. Since the words "As of" are not recognized as date mask elements. a mask of "The \mo\nth is month" results in the output string of "The month is march". 1996. To resolve such ambiguity. ’DDD’ followed by ’D’ can be written as ’DDD|D’. For example.SQR 4. For example: print &order_date () edit ’As of Month dd.03. A backslash forces the character that follows into the output. which could be interpreted as various combinations of ’DDD’ (day of year). ’DD’ (day of month). This technique is useful when you want to print text that would otherwise be recognized as a date mask element. Sample Date Edit Masks (continued) If the edit mask contains other text.3 Working with Dates Edit Mask YYYYMMDD DD. The second backslash is needed because "n" is a valid date edit mask element. For example. use a vertical bar as a delimiter between format elements. 1996" if the order date is March 14. YYYY’ This command will print the string "As of March 14.

Date variables are useful for holding results of date calculations. Date variables can be initialized with date literals as shown in the following example: begin-setup declare-variable date $c end-declare end-setup .3 The masks MON. $c is declared as a date variable.’Month dd.Working with Dates SQR 4. 1996 to $c. and RM are casesensitive and follow the case of the mask entered. MONTH. date variables are prefixed with a dollar sign ($). MONTH. For example. use date variables. DAY.. All other masks are case-insensitive and can be entered in either uppercase or lowercase. You must explicitly declare date variables using the DECLARE-VARIABLE command. it is assigned the value of noon on March 1. 1996 12:00’. BC.. Later. See the ALTER-LOCALE command or the chapter "SQR. if the month is January. AM. AD. In addition. The variable $c is then printed with the edit mask ’dd/mm/yyyy’. For example: begin-setup declare-variable date $c end-declare end-setup . national language support is provided for the following masks: MON. PM. 148 SQR User’s Guide . which yields 01/03/1996.. let $c = ’19960409152000’ The LET statement assigns 3:20 in the afternoon of April 9.. DY. let $c = strtodate(’March 1. AM. and AD. yyyy hh:mi’) print $c () edit ’dd/mm/yyyy’ In this example. DAY. the mask Mon yields "Jan" and MON yields "JAN". DY. Like string variables. PM.INI" in the SQR Language Reference for additional information. BC. 1996. Declaring Date Variables To hold date values in your program.

printing or referencing the reserved variable $current-date. For this format. a 24-hour clock is assumed. SQR User’s Guide 149 . The next chapter describes the SQR features for national language support. • Perform date arithmetic and date comparison by using the date functions. datediff. This format can be specified as an environment variable or specified in the SQR. • The SQR literal date format is SYYYYMMDD[HH24[MI[SS[NNNNNN]]]].3 Working with Dates Summary • Obtain date values by selecting a date column from the database. or strtodate. • You can also specify a date format with the environment variable SQR_DB_DATE_FORMAT. datenow.INI file. • Declare date variables with the DECLARE-VARIABLE command.SQR 4. or using an SQR date function such as dateadd.

.

SQR User’s Guide 151 . and DATE. BC. It also contains settings for how to handle lower/upper case editing of these names. DISPLAY. and time separator. A locale is a set of local preferences for language. and AD in the language of the locale. You can easily define additional locales or modify existing locales by editing the SQR. These keywords can be specified in the INPUT. and a period for the decimal place. numbers with commas separating the thousands. and date. Their use is discussed and demonstrated below. AM. This support is provided through the concept of locales. money. respectively. German. This chapter describes SQR locales and explains how to use them to write programs that automatically adapt to local preferences. A locale contains settings for N/A. thousands separator. These settings are described in detail in the reference section for the ALTER-LOCALE command in the SQR Language Reference. currency. and PRINT commands. A locale contains a setting for names of the days of the week and names of the months in the language of the locale. A locale also contains settings for currency symbol. UK-English.21 Locales National Language Support This chapter describes SQR features for national language support (NLS). dates in "dd/mm/yy" format.INI file. refer to the chapter. For example. For more information about the SQR." in the SQR Language Reference. These edit masks are used when you specify the keywords NUMBER. decimal separator. MONEY. one locale may use English. and Spanish. French. dollar currency. Available Locales SQR provides predefined locales such as US-English. MOVE. PM.INI.INI file. and the presentation of dates and numbers. "SQR. date separator. A locale contains default edit masks for number. SHOW.

" System is not a real locale. When you install SQR. Most or all of your programs may use the same locale. The date preferences are dependent on the database you are using. before national language support was added. Therefore. you can choose a locale—at the beginning of your program or anywhere else. and specifying the default locale in the SQR.INI file will control the format. an office in Paris may use the "French" locale.00. 'System' settings can be altered at run time using ALTER-LOCALE. date format preferences in the system locale are different for every database you use with SQR. You can select a locale with this command: alter-locale locale = ’German’ The Default Locale The SQR. Different sites may have a different locale as the default. Your program will then automatically respect the local preferences. however. It defines the behavior of older versions of SQR. 152 SQR User’s Guide .National Language Support SQR 4. The delimiters for thousands and the decimal—the comma and the period— will be switched automatically according to the preferences of the locale. the default locale is set to the reserved locale called "System. which are specified in the SQR.120.999. You can even have different parts of your program use different locales. The preferences in the system locale are hard-coded in the product and cannot be set or defined in the SQR. and in Paris it may be 5.INI.99’ The setting of the default locale in the SQR.999.INI file will make it unnecessary to specify the locale in every program.00. In London.INI file of the machine on which it is run. you may print the number 5120 using the following command: print #invoice_total () edit ’9.120.3 With the ALTER-LOCALE command. the result may be 5.INI file defines a default locale. use the default locale. and an office in London may use the "UK-English" locale. For example. To adapt your program to any location. For example.

For example. For example.SQR 4. This technique is useful for writing reports that use multiple currencies. The value of $old_locale is then used in the ALTER-LOCALE command at the end of the procedure." programs that used to print dates in English may now print them in French. to switch to the Spanish locale: alter-locale locale = ’Spanish’ From this point in the program. use the ALTER-LOCALE command. if you change the default locale to "French. To switch to another locale. SQR User’s Guide 153 . Consider this example: begin-procedure print_data_in_spanish ! Save the current locale let $old_locale = $sqr-locale ! Change the locale to "Spanish" alter-locale locale = ’Spanish’ ! Print the data do print_data ! restore the locale to the previous setting alter-locale locale = $old_locale end-procedure In this example. or reports that have different sections for different locales. Switching Locales You can switch from one locale to another any number of times during program execution. the locale setting before it is changed is read in the reserved variable $sqr-locale and stored in $old_locale. the locale is switched to Spanish and later restored to the previous locale before it was switched. Be sure that you review and test existing programs when making a change to the default locale. To do that.3 National Language Support À Tip Changing the settings of the default locale may change the behavior of existing programs. the locale will be Spanish.

you can reselect the modified locale. By using the keywords NUMBER. In this case. The first case is when you want to write programs that automatically adapt to the default locale. Whether you set the locale in the SQR. The following code will reset the changed date and money edit masks: alter-locale locale = ’US-English’ Keywords—NUMBER. MONEY. money. Here is an example of how you can modify default preferences in a locale: alter-locale date-edit-mask = ’Mon-DD-YYYY’ money-edit-mask = ’$$. you define these formats with an ALTER-LOCALE command at the top of your program. The second case is when you want to specify your number. It does not modify the SQR. and date formats once at the top of your program and use these formats throughout your report. In the following example. PRINT. these keywords will have the same effect. and SHOW allow you to specify the keywords NUMBER.3 Modifying Locale Preferences With the ALTER-LOCALE command.INI file. you tell SQR to take these edit masks from the default locale settings. For example. and DATE later in your program.$$9. they format number. you can modify any individual preference in a locale. and DATE. and DATE The commands DISPLAY. MOVE. MONEY. suppose that the locale was "USEnglish" and the date and money edit masks were modified using the above code. these keywords are used with the PRINT command to produce output for the US-English and French locales: 154 SQR User’s Guide .INI file or in your program.National Language Support SQR 4. These keywords can be useful in two cases. and date outputs with the masks defined in the ALTER-LOCALE command. and DATE in place of an explicit number or date edit mask. money. Then when you use the keywords NUMBER. The ALTER-LOCALE command only affects the current program.$$$.99’ To restore modified locale preferences to their defaults. MONEY. MONEY.

22) MONEY print ’With DATE keyword ’ (+1.1) print $date_var (.1) print $date_var (.00 $ 123. 1996 123.22) NUMBER print ’With MONEY keyword ’ (+1.1) print ’With NUMBER keyword ’ (+1.1) print #num_var (.00 May 20.1) print #num_var (.456.22) DATE The output will be as follows: US-English locale With NUMBER keyword With MONEY keyword With DATE keyword French locale With NUMBER keyword With MONEY keyword With DATE keyword 123.1) print #money_var (.456.456.3 National Language Support let #num_var = 123456 let #money_var = 123456 let $date_var = strtodate(’19960520152000’) ! set locale to US-English alter-locale locale = ’US-English’ print ’US-English locale’ (1.22) NUMBER print ’With MONEY keyword ’ (+1.1) print #money_var (.SQR 4.00 F 20 mai 1996 SQR User’s Guide 155 .22) MONEY print ’With DATE keyword ’ (+1.22) DATE ! set locale to French ALTER-LOCALE locale = ’French’ print ’French locale’ (+2.1) print ’With NUMBER keyword ’ (+1.456.00 123.

• You can edit the SQR.3 Summary • Local preferences for language. and the presentation of dates and numbers can be specified in a locale. The next chapter explains how SQR can interoperate with other applications and how SQR can be extended with functions supplied by you or contained in a third-party library. and DATE. • You can switch among locales by using the command ALTER-LOCALE. MONEY.National Language Support SQR 4. 156 SQR User’s Guide . • Predefined locales are specified in the SQR.INI file to alter predefined locales or to create new ones.INI file. • You can also specify formats with the keywords NUMBER. You can also specify individual preferences for a locale by using ALTER-LOCALE. currency.

the chapter will explain how to invoke an external application’s API by using the UFUNC. This API is provided through a DLL on Windows and through an object library on other platforms.22 Interoperability This chapter describes how SQR can interoperate with other applications or be extended with additional functions. Next.C interface. Applications can run SQR programs using the SQR API (application program interface). An SQR program can also call an external application’s API.C SQR Calling an External Application’s API Using UFUNC.C This chapter will first describe how to invoke an SQR program from another application using the SQR API. SQR User’s Guide 157 . This interoperability is depicted in the two diagrams below: External Application SQR Execute SQR API External Application Invoking an SQR Program Using the SQR API SQR Execute External Application UFUNC.

The aforementioned DLL files are located in the BINW directory. LIBSTI32. is provided.Interoperability SQR 4. For C and C++ applications. See the SQR Server Installation Guide for more information about linking with SQR. the SQR API is provided as a static library (sqr. SQR requires the following DLLs to run: For Windows 95 & NT they are SQRW. SQRAPI. For C and C++ applications.a and libsti.H (or sqrapi.a or SQR. Using the SQR API The SQR API is provided on Windows through a DLL (Dynamic Link Library). Two additional libraries are required: bcl. BCLW32. and an import library (SQRWIN. "Using the SQR Command Line. 158 SQR User’s Guide . You can use the SQR API from any application that is capable of calling DLL functions. The SQR command line is covered in Chapter 27. • Using SQR for PowerBuilder—your PowerBuilder application can call to the local or remote SQR user objects.DLL.LIB) are provided.3 Calling SQR from Another Application The following techniques can be used to invoke an SQR program from another application: • Using the SQR command line—the application initiates a process for running SQR.H. a header file.h).DLL. The SQR for PowerBuilder extensions are covered in the SQR for PowerBuilder User’s Guide." • Using the SQR API—the application makes a call to the SQR API.LIB).DLL.a. a header file. Be sure to include the SQR API library and your database library when you link your C or C++ application. The SQR command includes all the necessary parameters.DLL. This method is covered in the next section. On platforms other than Windows. SQRAPI. and STIMAGES.

This feature provides a significant improvement in processing time. the APIs are declared in the file SQRAPI. sqrcancel is called using another thread or some similar asynchronous method. connectivity information. and arguments. Include this header file in your source code: #include ’sqrapi. the most recently run SQR program is saved in memory. Call this function after the last program execution. void sqrcancel(void) int sqrend(void) Releases memory and closes cursors. It returns when the SQR program has completed. Cursors may be left open to speed up repeated execution of the same SQR program. Passes the address of a null terminated string containing an SQR command line. call sqrend() at any time.SQR 4.H. or optionally between SQR program executions. including program name. the program is not scanned again and the SQL statements are not parsed again. Cancels a running SQR program. Since the sqr function does not return until the SQR program has completed.h’ When you call SQR from a program. Table 4.3 Interoperability The following API functions are defined for calling SQR: Function int sqr(char *) Description Runs an SQR program. This function returns zero (0) if it is successful. The SQR API For the benefit of C/C++ programmers. The program may not stop immediately because SQR waits for any currently pending database operations to complete. flags. This function always returns zero (0). SQR User’s Guide 159 . If the same SQR program is run again with either the same or different arguments. To force SQR to release its memory and database cursors. This is a synchronous call.

Interoperability SQR 4.a\ $SQRDIR/.error occurred. Check the make files or link scripts that are supplied with SQR for details. For example.. if (status != 0) .3 Although memory is automatically released when the program exits./libsti... You may want to copy and modify those to link in your program.. you must call sqrend before the calling program exits to ensure that SQR properly cleans up any database resources such as database cursors and temporary stored procedures../lib/bcl.a (DB Libname). in C: status = sqr("myprog sammy/baker arg1 arg2 arg3")... To call SQR. Following is an example of a command that links a C application with the SQR API on a UNIX machine: cc -o {your_prog} {your_prog}. call sqr() and pass a command line.o $SQRDIR/sqr. 160 SQR User’s Guide ..a $SQRDIR/.

Error codes 9 and 12 are only applicable to the Windows release.STR file (open/read) Cannot call SQR recursively Problem with Windows Internal error occurred Problem with SQRWIN.3 Interoperability The following table describes error values returned by SQR. suppose you had a library for communication over a serial line.SQR/. Error Values Returned by the SQR API The VMS codes are given in hexadecimal notation. SQR would allow you to call these functions from SQR programs.LOG file (create/write) Problem with POSTSCRI.SQT file Program did not compile Problem with . For example.DAT Command-line flag in error Problem creating .DLL Problem with -ZCF file Table 5. SQR uses the 0x2600 group for its error messages to avoid conflict with VMS error messages. This feature allows you to integrate your own code and third-party libraries into SQR.ERR file (create/write) Problem with . SQR User’s Guide 161 .LIS file (create/write) Problem with .SQT file (open/read) Problem with .C The SQR language can be extended by adding user functions written in standard languages such as C.SQR 4. both standalone and callable: Non-VMS 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 VMS 1 0 0x2622 0x2632 0x2642 0x2652 0x2662 0x2672 0x2682 0x2692 0x26A2 0x26B2 0x26C2 0x26D2 0x26E2 0x26F2 Reason Normal exit Error exit Cannot process SQRERR. Extending SQR—UFUNC. with functions for initiating the connection and sending and receiving data.

split CC_ARGS((int. One example of such an extension would be an initcap function." Adding a User Function The following example demonstrates how to extend SQR with an initcap function. The key to the process is an SQR source file called UFUNC. initcap CC_ARGS((int.C.3 To extend SQR in this way. char *[]. double *)). and then link the objects (and libraries) with the SQR objects and libraries to form a new SQR executable. double *)). This code defines a prototype for a C function called initcap. char *[]. The first three lines are part of the original UFUNC. "tell" SQR about them. char*[]. you must prepare the functions. For example: let $a = initcap(’MR. The prototype is required by the C compiler. The new SQR executable will then recognize the new functions as if they were standard SQR functions. Oracle users are familiar with this function. double *[]. char *. static static static static void void void void max CC_ARGS((int. To add initcap to SQR. 162 SQR User’s Guide .C. The SQR name for the function is defined in the next step.Interoperability SQR 4.C. int)).C is provided in the LIB subdirectory (LIBW in Windows). Add Function Prototype Begin by adding a function prototype to the function declaration list. Step 1. double *)). It also contains comments with a description of the process of adding a function to SQR. you need to add it to a global array called userfuncs in UFUNC. Note that the name of the C function does not have to be the same as the name of the SQR function. Joseph Jefferson. You can find the modified version of UFUNC. JOSEPH JEFFERSON’) The result value in the variable $a would be "Mr. printarray CC_ARGS((int.C. The function initcap changes the first letter of every word to uppercase and changes the rest of the letters to lowercase. This file contains the list of user-defined functions.C in the TUTORIAL directory. The code segment above is taken from the file UFUNC. UFUNC. The line that adds the initcap function is shown in bold.

The length of this string is the size of the result buffer.3 Interoperability The CC_ARGS macro makes your code portable between compilers that expect full ANSI prototyping and compilers where the argument prototype is omitted. ’c’. You cannot return a value that is longer than the maximum length. In this case. This array is the argument list. Here is the modified code: } userfuncs[] = { /* (2) Define functions in userfuncs table: Number of Name Return_type Arguments Arg_Types -------------. ’n’. ’n’. "split". since initcap only takes one argument. ’n’. "cnnc". remove the STATIC keyword. 0.*/ PVR max. Function -------. which you must not overflow. "n". 0.C.C file. If you have the code in a separate file. The last argument sets the maximum length of the result string. "".--------"max". The maximum length is typically around 2000 bytes. The userfuncs table is an array of structures. You could also write: static void initcap(). The line contains five arguments. this table exists in the UFUNC. this argument count should be 1 because initcap takes exactly one argument. "printarray". "c". /* Last entry must be NULL—do not change */ "". PVR split. 0 }. SQR User’s Guide 163 . Note also that the keyword STATIC means that the code for initcap will be added in the file UFUNC. which correspond to the five fields of the structure. 4. '\0'. The first argument of the C function is the argument count of the corresponding SQR function. Add Entry to USERFUNCS Table The next step is to tell SQR about our initcap function. only the first pointer is actually used. In the case of initcap. PVR printarray.SQR 4. Step 2. 1. As stated before. "C". Since initcap returns a string.--------. The third argument of the C function is a pointer to the result buffer. 0. The line added is shown in bold. "initcap". PVR initcap. The second argument of the C function is an array of pointers. depending on platform. we will define it as "char *". and it initializes one structure in the array.

which is inserted at the end of UFUNC. result) /* Where to store result */ CC_LARG(int. } p++. Add Implementation Code The next step is to add the implementation code for initcap. The last argument is a pointer to a C function that implements the SQR function we are adding. the string contains one character enclosed in double quotation marks.argv. char *ptr. else *p = isupper(*ptr)?tolower(*ptr):*ptr. ptr = argv[0]. *p = *ptr.3 The first argument is the name of the SQR function being added. The fourth argument is a string representing the types of the arguments. ptr++. The third argument is the number of arguments that initcap will take. Note the PVR macro that provides proper cast for the pointer. argc) /* Number of actual arguments */ CC_ARG(char*. maxlen) /* Result’s maximum length */ { int flag = 1. "c". flag = 0. This character indicates that the argument for initcap is a string. } 164 SQR User’s Guide . This is the name that you will use in the LET. Set it to 1. You can insert it right into the file UFUNC. you will have to remove the STATIC keyword from the prototype.Interoperability SQR 4. Step 3. /* don’t exceed maxlen */ if (isalnum(*ptr)) { if (flag) *p = islower(*ptr)?toupper(*ptr):*ptr. Here is the code. IF and WHILE commands. while (*ptr) { if (ptr .H. argv[]) /* Pointers to arguments: */ CC_ARG(char*. return. The second argument is the return type. Since initcap has only one argument.argv[0] >= maxlen) break. } *p = ’\0’. This argument is the initcap function for which we have provided a prototype in the previous step. Remember that if you want to put the code in a separate file. char *p.C: static void initcap CC_ARGL((argc.result.C.maxlen)) CC_ARG(int. which ’c’ (enclosed in single quotation marks) indicates is a character string. You may also need to include standard C header files such as CTYPE. p = result. } else { flag = 1.

C. /* Number of actual arguments */ char* argv[]. you are ready to test. they look for SQREXT.DLL find SQREXT.argv. Use the make file that is provided in the LIB (or LIBW) subdirectory of SQR. /* Result’s maximum length */ Step 4. FARPROC lpfnError ). /* Pointers to arguments: */ char* result.INI file. When SQRW. You may rebuild SQREXT. they make the following calls in all the DLLs. JOSEPH JEFFERSON’) print $a () end-program The result in the output file should be: Mr. static void initcap(argc.maxlen) int argc. If SQRW.SQR 4. see the comments in the UFUNC. SQR is linked with the database libraries. You may have to modify the make file for your system. passing the instance handle (of the calling module) and three function pointers: void InitSQRExtension ( HINSTANCE hInstance. /* Where to store result */ int maxlen.DLL and the DLLs specified in the SQR. Joseph Jefferson For further information on argument types in user-defined functions. Once SQR is relinked.DLL and SQRWT. as long as the appropriate calling protocol is maintained.DLL and SQRWT. ufunc now resides in SQREXT.DLL are loaded. Try the following program: begin-program let $a = initcap(’MR. This step is highly specific to operating systems and databases.INI.DLL in the same directory and for any DLLs specified in the [SQR Extension] section in SQR.DLL using any language or tool.result.DLL. You can also write the code as follows (only the first five lines are shown). CC_ARG.C file. SQR User’s Guide 165 . The source code for SQREXT. ufunc on Windows 95 & NT On Windows 95 & NT.C). you must relink SQR. whose names and locations tend to vary.3 Interoperability Note the use of the CC_ARGL. Relink SQR Once you have modified UFUNC. FARPROC lpfnConsole.DLL is included in the shipped package (EXTUFUNC. FARPROC lpfnUFuncRegister. and CC_LARG macros.

All the extension DLLs must have the InitSQRExtension() function exported.INI in the system directory.MAK. you should rebuild the DLL using the supplied make file.C file. If you choose to implement user functions in SQREXT. • An SQR program can call also an external application’s API.DLL or any other extension DLL. you must register it by making the following call in InitSQRExtension(). they must be listed in the [SQR Extension] section in SQR. add functions to the userfuncs global array in the UFUNC.C for the definition of struct ufnns and the sample user functions. If new extension DLLs containing new user functions are to be used.Interoperability SQR 4. SQREXT. 166 SQR User’s Guide . • To extend SQR. The function pointer lpfnUFuncRegister is passed in from the calling module. The next chapter describes techniques for testing and debugging SQR programs. • You can extend SQR with third-party libraries and functions written in standard languages such as C. Summary • Applications can run SQR programs using the SQR API (application program interface).3 Implementing New User Functions on Windows 95 & NT You may implement new user functions in SQREXT.DLL. lpfnUFuncRegister(struct ufnns* ufunc). Refer to EXTUFUNC. For any ufunc.

-T6 will cause the program to stop after 6 pages of output have been created. The database will not sort the data and the first set of records will be selected sooner. you are only interested in the first few pages of the report.23 Testing and Debugging This chapter describes the SQR functionality designed to help with the testing and debugging of SQR programs.lis. The -T flag lets reports finish more quickly because all BEGIN-SELECT ORDER BY clauses are ignored. This chapter will focus on facilities in the SQR language and command-line options. enter the following command: sqr customer username/password -T3 The -T3 flag specifies that the program will stop running after 3 pages have been produced. you frequently test it by running it and examining its output. If you are using VisualSQRIBE. the breaks may occur in unexpected locations because the ORDER BY clause is ignored.sqr. To speed the cycle of running and viewing a few pages. if your report is named customer. À Note If your program contains break logic. Enter the desired number of test pages after the -T flag. check it by displaying the output file on your screen or printing it. Using the Test Feature During the development of an SQR program. the output file will be named customer. use the -T command-line flag. When the test completes successfully.sqr. For example. SQR User’s Guide 167 . select Limit to nn pages in the Run dialog.LIS. For example. The default name of the output file is the same as the program file with the extension . In many cases. To test a report file called customer.

Indicate which command is to be debugged on the -DEBUG flag. commands preceded by #DEBUG. You can achieve debug multiple commands by using up to 10 letters or digits to differentiate between them. • Temporarily cause additional behavior in questionable areas of the program. 168 SQR User’s Guide . Precede the command with #DEBUG. as shown in the following example: sqr myreport username/password -DEBUGabc In this example. For example. • Isolate problem areas by temporarily skipping the parts of the program that work correctly. Your program will process all ORDER BY clauses and run to completion. If the program creates more than one report. Commands preceded with #DEBUGd are not compiled because "d" was not specified in the -DEBUG command-line flag. #DEBUGb. that command is processed only if the -DEBUG flag is specified on the SQR command line. as shown in the following example: #debug display $s When #DEBUG precedes a command. run it without the -T flag. or #DEBUGc are compiled when the program is executed.Testing and Debugging SQR 4. SQR provides the #DEBUG command to help you make temporary changes to your code. the value of $s will be displayed only when you run the program with -DEBUG. #DEBUGa. the -T flag restriction will apply only to the first report. In this example. You can use the #DEBUG command to conditionally process portions of your program. Using the #DEBUG Command When debugging a program it is often useful to: • Display data or show when a procedure or query executes by using temporary SHOW or DISPLAY commands in key places in the program.3 When the development of your program is complete. display or modify variables that you suspect are causing a problem.

the dump_array procedure is included in the program. Later. Because SQR does not require variables to be declared.3 Testing and Debugging Using Compiler Directives for Debugging You can conditionally compile entire sections of your program using the five compiler directives: • #IF • #ELSE • #END-IF or #ENDIF • #IFDEF • #IFNDEF You can use the value of a substitution variable.1) print $city (. as shown in the following example: #define DEBUG_SESSION Y #if DEBUG_SESSION = ’Y’ begin-procedure dump_array let #i = 0 while #i < #counter ! Get data from the array get $state $city $name $phone from customer_array(#i) print $state (. SQR User’s Guide 169 .55) position (+1) add 1 to #i end-while end-procedure ! dump_array #end-if The dump_array procedure is only used for debugging. declared by a #DEFINE command. SQR considers the mistyped variable as if it is another variable.SQR 4. to turn on or off a set of statements. you can change DEBUG_SESSION to N and exclude the dump_array procedure from the program. By defining DEBUG_SESSION as Y. Instead. Common Programming Errors The most common programming error using SQR is mistyping variable names.24) print $phone (. it will not issue an error message when variables names are mistyped.7) print $name (. The #IF command in this example is case-insensitive.

#IFDEF. SQR will not issue an error message. Instead. 170 SQR User’s Guide .3 For example: let #customer_access_code = 55 print #customer_acess_code () This example will not print 55 because we mistyped the variable name. use $_area. #ELSE. and #IFNDEF. Can you see the typo? The "c" in "acess" on the PRINT command is missing. it is taken as a new local variable name. #END-IF. For example: begin-procedure main let $area = ’North’ do proc end-procedure ! main begin-procedure proc local print $area () ! Should be $_area end-procedure In this example. Summary • You can speed up the testing cycle by using the -T command-line flag. • The most common programming error is the mistyping of variable names.Testing and Debugging SQR 4. A related problem has to do with global versus local variables. It will print nothing because the local $area variable did not receive a value. the local procedure proc prints the value of the local variable $area and not the global variable $area. If you refer to a global variable in a local procedure without preceding it with an underscore. • You can conditionally process sections of a program by using the #DEBUG command and the -DEBUG command-line flag. To refer to the global variable. • You can conditionally compile entire sections of your program using the five compiler directives #IF. Such small errors are hard to detect because SQR considers #customer_acess_code as simply another variable with a value of zero.

Processing SQL statements typically consumes significant computing resources. SQR Performance and SQL Statements Whenever your program contains a BEGIN-SELECT. This chapter focuses on SQR tools for simplifying SQL statements and reducing the number of SQL executions. • Writing programs that create multiple reports • Tuning SQR numerics • Running compiled programs with SQR Execute • Adjusting processing limits • Buffering fetched rows • Running programs on the server SQR User’s Guide 171 .24 Performance and Tuning Performance considerations are an important aspect of application development. There are several techniques. it performs a SQL statement. This chapter examines some of the issues that affect the performance of SQR programs. General tuning of SQL is outside the scope of this book. including: • Simplifying a complex SELECT • Using LOAD-LOOKUP to simplify joins • Using dynamic SQL • Examining cursor status • Using an array or flat file instead of a temporary database table. BEGIN-SQL. Tuning SQL statements typically yields higher performance gains than tuning any other part of your program. Tuning SQL is often specific to the type of database that you are using—tuning SQL statements for an ORACLE database may be different than tuning SQL statements for DB2. or EXECUTE command. This chapter also describes certain SQR capabilities that can help you write high-performance programs.

Performance and Tuning

SQR 4.3

Simplifying a Complex SELECT
With relational database design, information is often "normalized" by storing data entities in separate tables. To display the normalized information, you must write a SELECT statement that joins these tables together. With many database systems, performance suffers when you join more than three or four tables in one SELECT. With SQR, you can perform multiple SELECT statements and nest them as we saw in Chapter 7, "Master/Detail Reports." In this way, you can break a large join into several simpler SELECTS. For example, a SELECT statement that joins orders and products tables can be broken into two SELECTS. The first SELECT will retrieve the orders in which we are interested. For each order retrieved, a second SELECT will retrieve the products that were ordered. The second SELECT is correlated to the first SELECT by having a condition such as: where order_num = &order_num This condition specifies that the second SELECT will only retrieve products for the current order. Similarly, if your report is based on products ordered, you can make the first SELECT retrieve the products, and make the second SELECT retrieve the orders for each product. This method will improve performance in many cases, but not all. To achieve the best performance, you may need to experiment with the different alternatives.

Using LOAD-LOOKUP to Simplify Joins
Database tables often contain key columns such as a product code or customer number. To retrieve a certain piece of information, you join two or more tables that contain the same column. For example, to obtain a product description, you may join the orders table with the products table, using the product_code column as the key. With LOAD-LOOKUP, you can reduce the number of tables that are joined in one SELECT. This command is used in conjunction with one or more LOOKUP commands.

172

SQR User’s Guide

SQR 4.3

Performance and Tuning

The LOAD-LOOKUP command defines an array containing a set of keys and values and loads it into memory. The LOOKUP command looks up a key in the array and returns the associated value. In some programs, this technique will perform better than a conventional table join. LOAD-LOOKUP can be used in the SETUP section or in a procedure. If used in the SETUP section, it is processed only once. If used in a procedure, it is processed each time it is encountered. LOAD-LOOKUP retrieves two fields from the database, the KEY field and the RETURN_VALUE field. Rows are ordered by KEY and stored in an array. The KEY field must be unique and contain no NULL values. When the LOOKUP command is used, the array is searched (using a "binary" search) to find the RETURN_VALUE field corresponding to the KEY referenced in the lookup. The following example illustrates LOAD-LOOKUP and LOOKUP:
begin-setup load-lookup name=prods table=products key=product_code return_value=description end-setup ... begin-select order_num (+1,1) product_code lookup prods &product_code $desc print $desc (,15) from orderlines end-select

In this example, the LOAD-LOOKUP command loads an array with the product_code and description columns from the products table. The lookup array is named prods. The product_code column is the key and the description column is the return value. In the SELECT paragraph, a LOOKUP on the prods array retrieves the description for each product_code. This technique eliminates the need to join the products table in the SELECT. If the ordlines and products tables were simply joined in the SELECT (without LOAD-LOOKUP), the code would look like this:

SQR User’s Guide

173

Performance and Tuning

SQR 4.3

begin-select order_num (+1,1) ordlines.product_code description (,15) from ordlines, products where ordlines.product_code = products.product_code end-select

Which is faster, a database join or LOAD-LOOKUP? It depends on your program. LOAD-LOOKUP improves performance in the following situations:

• When it is used with multiple SELECTS. • When it keeps the number of tables being joined from exceeding three or four. • When the number of entries in the LOAD-LOOKUP table is small compared to the number of rows in the SELECT, and they are used often. • When most entries in the LOAD-LOOKUP table are used.

À Tip

You can concatenate columns if you want RETURN_VALUE to return more than one column. The concatenation symbol is database-specific.

Improving SQL Performance with Dynamic SQL
Chapter 16, "Dynamic SQL and Error Checking," explained how to use dynamic SQL variables. Dynamic SQL can also be used in some situations to simplify a SQL statement and gain performance.
begin-select order_num from orders, customers where order.customer_num = customers.customer_num and ($state = ’CA’ and order_date > $start_date or $state != ’CA’ and ship_date > $start_date) end-select

In this example, a given value of $state, order_date or ship_date is compared to $start_date. The OR operator in the condition makes such multiple comparisons possible. With most databases, an OR operator slows processing. It may cause the database to perform more work than necessary.

174

SQR User’s Guide

SQR 4.3

Performance and Tuning

However, the same work can be done with a simpler SELECT. For example, if $state is ’CA,’ the following SELECT would work:
begin-select order_num from orders, customers where order.customer_num = customers.customer_num and order_date > $start_date end-select

Dynamic SQL allows you to check the value of $state and create the simpler condition:
if $state = ’CA’ let $datecol = ’order_date’ else let $datecol = ’ship_date’ end-if begin-select order_num from orders, customers where order.customer_num = customers.customer_num and [$datecol] > $start_date end-select

The substitution variable [$datecol] substitutes the name of the column to be compared with $state_date. The SELECT is simpler and no longer uses an OR. In most cases, this use of dynamic SQL will improve performance.

Examining SQL Cursor Status
Since SQR programs select and manipulate data from a SQL database, it is helpful to understand how SQR handles SQL statements and queries. SQR programs may perform multiple SQL statements. Moreover, the same SQL statement may be executed many times. When your program executes, a pool of SQL statement handles—called cursors—is maintained. A cursor is a storage location for one SQL statement, for example, SELECT, INSERT, or UPDATE. Every SQL statement uses a cursor for processing. A cursor holds the context for the execution of a SQL statement. The cursor pool consists of 30 cursors, and its size cannot be changed. When a SQL statement is re-executed, its cursor can be immediately reused if it is still in the cursor pool. When your SQR program executes more than 30 different SQL statement, cursors in the pool are reassigned.

SQR User’s Guide

175

Performance and Tuning

SQR 4.3

To examine how cursors are managed, use the -S command-line flag. This flag will cause cursor status information to be displayed at the end of a run. The following information will be displayed for each cursor:
Cursor #nn: SQL = <SQL statement> Compiles = nn Executes = nn Rows = nn

The listing will also include the number of "compiles," which will vary according to the database and the complexity of the query. With Oracle, for example, a simple query is compiled only once. With SYBASE, a SQL statement is compiled before it is first executed and recompiled for the purpose of validation during the SQR compile phase. Therefore, you may see two compiles for a SQL statement. Later when the SQL is re-executed, if its cursor is found in the cursor pool, it can proceed without recompiling.

Avoiding Temporary Database Tables
Programs often use temporary database tables to hold intermediate results. Creating, updating, and deleting database temporary tables is a very resource-consuming task, however, and can hurt your program’s performance. SQR provides two alternatives to using temporary database tables. The first alternative is to store intermediate results in an SQR array. The second is to store intermediate results in a local flat file. Both techniques can bring about a significant performance gain. You can use the SQR language to manipulate data stored in an array or a flat file. These two methods are explained and demonstrated in the following sections. Methods for sorting data in SQR arrays or flat files are also explained.

Using and Sorting Arrays
Chapter 8, "Cross-Tabular Reports and the Use of Arrays," introduced the array as a means of holding data records during program execution.

176

SQR User’s Guide

Subsequent passes on the data can be made without additional database access.000 rows.55) position (+1) put &state &city &name &phone into customer_array(#counter) add 1 to #counter from customers end-select This example creates an array named customer_array. At the end of the SELECT. when records are retrieved from the database. you can store them in the array. prints them. it would be necessary to create a larger array. and it can hold up to 1.24) print $phone (. but with fewer lines of code. the value of #counter is the number of records in the array. During the first pass.7) print $name (.000 rows. The PUT command is then used to store the data in the array. create-array name=customer_array size=1000 field=state:char field=city:char field=name:char field=phone:char let #counter = 0 begin-select state (.1) print $city (. you can assign all four fields in one command. The #counter variable serves as the array subscript. It starts with zero and maintains the subscript of the next available entry. The next piece of code retrieves the data from customer_array and prints it: let #i = 0 while #i < #counter get $state $city $name $phone from customer_array(#i) print $state (. If the customers table had more than 1. Chapter 8 showed how to use the LET command to assign values to array fields. The array has four fields that correspond to the four columns selected from the customers table. With PUT. The SELECT prints the data. and saves them into an array named customer_array.55) position (+1) add 1 to #i end-while SQR User’s Guide 177 .1) city (. The following code retrieves records.24) phone (.7) name (.SQR 4. The PUT command performs the same work.3 Performance and Tuning An SQR array can hold as many records as can fit in memory.

For further information on QuickSort. 1982. and use it to sort your array.sqr #define MAX_ROWS 1000 begin-setup create-array name=customer_array size={MAX_ROWS} field=state:char field=city:char field=name:char field=phone:char ! ! Create a helper array that is used in the sort ! create-array name=QSort size={MAX_ROWS} field=n:number field=j:number end-setup begin-program do main end-program Program continues on the following page. #i goes from 0 to #counter-1.3 In this piece of code. Sorting In many cases. and $phone. 178 SQR User’s Guide . $city. You can copy this code into your program. The following program shows how to sort customer_array by name. see the book Fundamentals of Data Structures by Horowitz and Sahni. The fields from each record are moved into the corresponding variables $name. These values are then printed. The program uses a well-known sorting algorithm called QuickSort. $state. intermediate results must be sorted by a different field. make appropriate changes.Performance and Tuning SQR 4. Program ex24a.

sqr (continued) begin-procedure main let #counter = 0 ! ! Print customers sorted by state ! begin-select state (.7) print $name (.24) print $phone (.SQR 4.3 Performance and Tuning Program ex24a.1) city (.55) position (+1) add 1 to #i end-while end-procedure ! main Program continues on the following page. #last_row) ! ! Print customers (which are now sorted by name) ! let #i = 0 while #i < #counter ! Get data from the array get $state $city $name $phone from customer_array(#i) print $state (.1) print $city (.7) name (. SQR User’s Guide 179 .1 do QuickSort(0.24) phone (.55) position (+1) ! Put data in the array put &state &city &name &phone into customer_array(#counter) add 1 to #counter from customers order by state end-select position (+2) ! ! Sort customer_array by name ! let #last_row = #counter . 0.

#j) ! restore #j and #n let #j = QSort.1) add 1 to #j do QuickSort(#level.1) = #n subtract 1 from #j do QuickSort(#level.3 Program ex24a.name(#m) while 1 add 1 to #i while #i <= #j and customer_array.n(#level .Performance and Tuning SQR 4. #m. #j) add 1 to #level ! Save #j and #n let QSort.n(#level . #n) subtract 1 from #level end-if end-procedure ! QuickSort Program continues on the following page. #m.j(#level .The "m" argument of the classical QuickSort ! #n . Since SQR does not allocate ! local variables on a stack (they are all static).1) let #n = QSort. this ! procedure uses a helper array. #j.j(#level .1) = #j let QSort. ! This is a recursive function. #n) if #m < #n let #i = #m let #j = #n + 1 ! Sort key is "name" let $key = customer_array.The "n" argument of the classical QuickSort ! begin-procedure QuickSort(#level.name(#j) > $key subtract 1 from #j end-while if #i < #j do QSortSwap(#i.Recursion level (used as a subscript to the helper ! array) ! #m . 180 SQR User’s Guide .name(#i) < $key add 1 to #i end-while subtract 1 from #j while #j >= 0 and customer_array.sqr (continued) ! ! QuickSort ! ! Purpose: Sort customer_array by name. ! ! #level . #j) else break end-if end-while do QSortSwap(#m.

For the algorithm to work properly. QuickSort can call itself recursively many times.name(#j) let customer_array. In QuickSort the variables #j and #n are overwritten when QuickSort calls itself. the program must save the values of these two variables before making the recursive call.Array subscript ! #j . which means that it calls itself. Qsort.state(#j) let customer_array. The procedures QuickSort and QSortSwap in ex24a.city(#i) = customer_array.city(#j) let customer_array.sqr (continued) ! ! ! QSortSwap ! ! Purpose: Swaps records #i and #j of customer_array ! ! #i .SQR 4. #j) get $state $city $name $phone from customer_array(#i) let customer_array.3 Performance and Tuning Program ex24a. To do this. add a #level variable that maintains the depth of recursion. The main procedure starts QuickSort by calling it with the full range of rows. Typically. If you plan to use these procedures to sort an array in your applications. so the program may need to save many copies of #j and #n. rows with a lower key value are moved up.phone(#j) put $state $city $name $phone into customer_array(#j) end-procedure ! QSortSwap The QuickSort algorithm uses a recursive procedure.Array subscript ! begin-procedure QSortSwap(#i. SQR maintains only one copy of the procedure’s local variables. you’ll need to change these references to the applicable array and fields. The QuickSort procedure sorts in ascending order.name(#i) = customer_array. is used to hold multiple values of #j and #n. The first is the recursion level (or depth). as described above. In this example. the range gets smaller. The second and third arguments are the beginning and end of the range of rows to be sorted. then restore those values when the call completes.sqr refer to customer_array and its fields. Each time QuickSort calls itself.phone(#i) = customer_array.state(#i) = customer_array. SQR User’s Guide 181 . The QSortSwap procedure swaps two rows in customer_array. The QuickSort procedure takes three arguments. a helper array. which is #level.

The comparisons while #i <= #j and customer_array.Performance and Tuning SQR 4.name(#j)) Using and Sorting Flat Files An alternative to an array is a flat file.name(#i). As is the case with an array. "Extending SQR. This example can be extended to include other operating systems. You can use a flat file when the required array size exceeds available memory.$key) while #j >= 0 and NLS_STRING_COMPARE($key. you may need a sorting utility that supports NLS.name(#i) < $key and while #j >= 0 and customer_array. The QuickSort procedure will then be modified as follows.dat instead of the array.customer_array. Chapter 22. you may need to write a National Language Sensitive character string comparison and add that to SQR. They work well for US ASCII English. The following code is rewritten to use the file cust. The disadvantage of using a file is that the program will perform more I/O.name(#j) > $key are simple string comparisons. while #i <= #j and NLS_STRING_COMPARE(customer_array. The sample code in the previous section can be rewritten to use a file instead of an array. 182 SQR User’s Guide . it may still be faster than performing another SQL statement to retrieve the same data. but they may not sort correctly with other languages. For such languages. However." explains how to add functions to SQR.3 QuickSort and National Language The QuickSort procedure does not support National Language Sensitive character string sort. This program uses the UNIX sort utility to sort the file by name. The advantage of using a file is that the program is not constrained by the amount of memory that is available.

dat’ #status if #status <> 0 display ’Error in sort’ stop end-if ! ! Print customers (which are now sorted by name) ! open ’cust2.dat’ as 1 for-writing record=80:vary begin-select state (.dat > cust2.dat’ as 1 for-writing record=80:vary SQR User’s Guide 183 .55) position (+1) ! Put data in the file write 1 from &name:30 &state:2 &city:16 &phone:10 from customers order by state end-select position (+2) ! ! Close cust.dat’ as 1 for-reading record=80:vary while 1 ! loop until break ! Get data from the file read 1 into $name:30 $state:2 $city:16 $phone:10 if #end-file break ! End of file reached end-if print $state (.SQR 4.24) phone (.dat by name ! call system using ’sort cust.1) print $city (.7) name (.55) position (+1) end-while ! ! close cust2.dat close 1 end-procedure ! main The program starts by opening a file cust.1) city (.dat open ’cust.dat ! open ’cust.7) print $name (.24) print $phone (.dat close 1 ! Sort cust.sqr begin-program do main end-program begin-procedure main ! ! Open cust.3 Performance and Tuning Program ex24b.

3 The OPEN command opens the file for writing and assigns it file number 1.dat for reading. it will be padded with blanks. When the end of the file is encountered. 184 SQR User’s Guide . The program writes fixed-length fields—for example. Next. You can open as many as 12 files in one SQR program. The program checks for #end-file and breaks out of the loop when the end of the file is reached.dat and direct the output to cust2. Since name is at the beginning of each record. it closes the file using the CLOSE command. It writes the name first. The file is sorted with the UNIX sort utility.Performance and Tuning SQR 4. The command read 1 into $name:30 $state:2 $city:16 $phone:10 reads one record from the file and places the first 30 characters in $name. The completion status is saved in #status. you could also use fixed-length records.dat. Finally. which makes it easier to sort the file by name. If the actual name is shorter. It invokes the UNIX sort command to sort cust. call system using ’sort cust. The next two characters are placed in $state and so on. the file will be sorted by name. the reserved variable #end-file is automatically set to 1 (true). the program closes the file using the CLOSE command. The file is set to support records of varying length with a maximum of 80 bytes (characters). For this example. As the program selects records from the database and prints them.dat is sent to the UNIX system. When the program has finished writing data to the file.dat’ #status The command sort cust.dat > cust2. write 1 from &name:30 &state:2 &city:16 &phone:10 The WRITE command writes the four columns into file number 1—the currently open cust.dat. &name:30 specifies that the name column will use exactly 30 characters. we open cust2.dat > cust2. it writes them to cust.dat. a status of 0 indicates success.

In this method. a single program creates multiple reports. one program can create multiple reports simultaneously. if each program is executed separately. you can create multiple programs and even reuse code. This is the most accurate method. with only a difference in layout or summary. To overcome this loss of accuracy. these reports are similar. With SQR. "Multiple Reports. making just one pass on the data. but also the slowest. MULTIPLY. The amount of database processing is thus greatly reduced. In many cases." Tuning SQR Numerics SQR provides three types of numeric values: • Machine floating point numbers • Decimal numbers • Integers Machine floating point numbers are the default. Decimal numbers provide exact math and precision of up to 38 digits. SUBTRACT. Some accuracy may be lost when converting decimal fractions to binary floating point numbers. It uses binary floating point and normally holds up to 15 digits of precision.3 Performance and Tuning Creating Multiple Reports in One Pass Sometimes you must create multiple reports that are based on the same data. you can sometimes use the ROUND option of commands such as ADD. Such repeated processing is often unnecessary. SQR User’s Guide 185 . the database has to repeat the query. However. Math is performed in software. You can also use the round function of LET or numeric edit masks that round the results to the desired precision. The multiple report feature of SQR is described in Chapter 18. This method is very fast.SQR 4. and DIVIDE. They use the floating point arithmetic provided by the hardware. Typically.

This method is explained in Chapter 25. Selecting the numeric type for variables allows you to fine-tune the precision of numbers in your program. Many of these settings have a direct impact on memory requirements. however. Integer math is also the fastest. You can then run it with SQR Execute.3 Integers can be used for numbers that are known to be integers. When you choose decimal numbers. or the DEFAULT-NUMERIC entry in the [Default-Settings] section of the SQR. you can choose the type of numbers that SQR uses. Moreover. An -M command-line flag can be used to specify a startup file whose entries will override those set in SQR.SQT) file.INI are used to define the sizes and limitations of some of the internal structures used by SQR. 186 SQR User’s Guide . you can also specify the desired precision. the -DNT command-line flag. then corresponding sections of the file will not be processed. The default is machine floating point to provide compatibility with older releases of the product.Performance and Tuning SQR 4. and they adhere to integer rules when dividing numbers. typically faster than floating point numbers. this type of tuning will not yield a significant performance improvements and we recommend selecting decimal.INI. If the -M command-line flag is used. There are several benefits for using integers: They enforce the integer type by not allowing fractions. For most applications. If you use the DECLARE-VARIABLE command.INI file. you can select the type for individual variables in the program with the DECLARE-VARIABLE command. The compiled program is stored in a run-time (. Compiling SQR Programs and Using SQR Execute Performance can be improved if you compile your SQR program. Your program will run faster because it will skip the compile phase. Processing Limits A startup file and the [Processing-Limits] section of SQR.

1.3 Performance and Tuning Tuning of memory requirements used to be significant with older 16-bit operating systems such as Windows 3.SQR 4. In such cases you must increase the corresponding settings. A database fetch operation is therefore performed after every 10 records. Today. records are fetched from the database server. Executing Programs on the Database Server You can reduce network traffic and greatly improve performance by running SQR programs directly on the database server machine. This is a substantial performance gain. The records are buffered. For example -B100 specifies that records will be fetched in groups of 100. most operating systems use virtual memory and tuning memory requirements would normally not affect performance in any significant way. they are fetched in groups rather than one at a time. In both cases. Buffering Fetched Rows When a BEGIN-SELECT command is executed. you specify the number of records to be fetched together. The default is groups of 10 records. then network traffic is also significantly reduced. instead of after every single record. To improve performance. The number of records to fetch together can be modified using the -B command-line flag or for an individual BEGIN-SELECT command using its -B option. If the database server is on another computer. The only case where you may need to be concerned with [Processing-Limits] settings is with large SQR programs that exceed default [Processing-Limits] settings. and your program processes these records one at a time. SQR User’s Guide 187 . This feature is currently available only when you use SQR for the Oracle or SYBASE databases. The SQR server product is available on many server platforms including Windows NT and UNIX. This means that the number of database fetch operations is further reduced.

• Save compiled SQR programs and rerun them with SQR Execute. decimal. • Use the most efficient numeric type for numeric variables (machine floating point. • Write programs that create multiple reports with one pass on the data. The next chapter will explain how to use compiled versions of SQR programs. • Use LOAD-LOOKUP to simplify joins. Two alternatives to temporary database tables are SQR arrays and flat files.3 Summary The following techniques can be used to improve the performance of your SQR programs: • Simplify complex SELECT statements. or integer).Performance and Tuning SQR 4. • Execute programs on the database server machine. • Adjust settings in the [Processing-Limits] section of SQR. • Use dynamic SQL instead of a condition in a SELECT statement. 188 SQR User’s Guide . • Increase buffering of rows in SELECT statements with the -B flag.INI or in a startup file. • Avoid using temporary database tables.

SQT file. #INCLUDE. For SQR. there are two steps—compiling the program and executing it. This file is portable between different hardware platforms and between some databases. SQR creates a ready-to-execute version of your program that is already compiled and validated. The steps are simple. • Performs the SETUP section. SQR will create a file with a file name extension of . You should enter something similar to the following: sqrw ex1a. running an SQR program is a one-step process. interprets. you perform the compile step only once and skip it in subsequent runs.SQT. SQR allows you to save the compiled version of a program and use it when you rerun a report. When compiling a program. however. An example of this is as follows: sqrw ex1a. Run the SQR executable ("sqr" for Unix systems or "sqrw" for Windows systems) against your SQR program file and include the -RS command-line flag to save the run-time file. and validates the program. • "Preprocesses" substitution variables and certain commands—ASK.25 Compiling Programs and Using SQR Execute This chapter explains how to save and run compiled versions of your SQR programs.sqt sammy/baker@rome -RT SQR User’s Guide 189 . • Validates SQL statements. and #IFDEF. Execution will be faster because the program is already compiled.sqr sammy/baker@rome -RS Run the SQR executable ("sqr" or "sqrw") with the -RT command-line flag to execute the . SQR: • Reads. For the user. #DEFINE. That way. #IF. Note that SQR does not compile the program into machine language.

A list of SQR features that apply at compile time and their possible runtime equivalents follows. Think of compile-time steps as defining what the report is. SQR will no longer perform any compile-time steps such as executing #IF. (This program is equivalent to running SQR with -RT. We demonstrated this solution in Chapter 15. SQR Execute is capable of running .SQT file by invoking SQR Execute from the command line with "sqrt" (on UNIX systems) or "sqrwt" (on Windows systems). For example. In some cases. you may have to use substitution variables with commands that require a constant and do not allow a variable. An example of running SQR Execute from the command line is as follows: sqrwt ex1a.3 The SQR product distribution includes SQR Execute (the SQRT program)." where we worked around the limitation of the USE-PRINTER-TYPE command. you should use commands such as IF and INPUT. #INCLUDE.sqt sammy/baker@rome It is important to realize that once you save the run-time (. 190 SQR User’s Guide .) You may run the . or ASK commands or performing the SETUP section.SQT files but does not include the code that compiles an SQR program. "Writing Printer-Independent Reports.SQT) file. For run-time customization. These were already performed at the time that the program was compiled and the run-time file was saved. Commands such as #IF or ASK allow you to customize your report at compile time. You must make a clear distinction between what is performed at compile time and what is performed at run time. no equivalent exists and you will have to work your way around the limitation.Compiling Programs and Using SQR Execute SQR 4. which does not accept a variable as an argument.

If you are substituting parts of a SQL statement. Compile-Time Commands and Run-Time Equivalents Summary • To save a compiled version of an SQR program. use dynamic SQL instead. use the -RT command-line flag or SQR Execute.SQR 4.3 Compiling Programs and Using SQR Execute Compile Time Substitution variables. SQR User’s Guide 191 . margins Number of heading or footing lines DECLARE-CHART DECLARE-IMAGE DECLARE-PROCEDURE DECLARE-PRINTER USE (SYBASE only) Table 6. See Chapter 16. INPUT LET IF No equivalent No equivalent No equivalent PRINT-CHART PRINT-IMAGE USE-PROCEDURE ALTER-PRINTER (where possible) -DB command-line flag ASK #DEFINE #IF INCLUDE DECLARE-LAYOUT. use the -RS commandline flag. • To run a precompiled program. The next chapter explains how to create different types of output files. Run Time Use regular SQR variables.

.

we will examine the SQR command-line flags that specify output file type and the printer for which it is produced.SPF or . SQR creates an output file that contains the report. SQR portable files have a default extension of .LIS .Snn (for multiple reports). You may recall from Chapter 18. Specifically. You can set your default printer using the Windows Control Panel. CommandLine Flag -PRINTER:EH -PRINTER:HP -PRINTER:HT -PRINTER:LP -PRINTER:PS -PRINTER:WP Output File Extension . but it does not print it directly.26 Printing Issues In this chapter. SQR does not actually print the report. We will cover the DECLARE-PRINTER command and expand on printing issues that pertain to multiple reports.htm .LIS Output goes directly to the default printer without being saved to a file. Except for the Microsoft Windows platform. The following table summarizes SQR command-line flags and the types of output they produce. The output file may be a printer-specific file or an SQR portable file (SPF).htm . File Format Enhanced HTML PCL HTML ASCII PostScript Suitable for Intranet/Internet HP LaserJet printer Intranet/Internet Line printer PostScript printer Windows Table 7." that a program can produce more than one report. we will cover technical issues relevant to printing. "Multiple Reports. Command-Line Flags and Output Types SQR User’s Guide 193 .LIS .

SQR Print and SQR Viewer can print this . or PostScript. bar codes.SPF file. SQR will produce a line printer output unless otherwise set in the SQR program with DECLARE-PRINTER. For example -PRINTER:PS will cause SQR to produce a PostScript output. or the PRINTER-TYPE option of DECLAREREPORT. boxes. HP LaserJet. 194 SQR User’s Guide .LIS file that is normally created) file .SPF output also allows you to decide later where to print it. the -PRINTER:xx flag will affect all the reports. -KEEP SQR Portable Format and the addition to the format of the .LIS ASCII. The DECLARE-PRINTER command is used to specify printer-specific settings for the printers that SQR supports: line printer. SQR Portable File (SPF) is a printer-independent file format that allows for all the SQR graphical features. Line printer.Snn (in No flag . SPF files can be distributed electronically and read with the SQR Viewer.3 CommandLine Flag -NOLIS Output File Extension . USE-PRINTER-TYPE.Printing Issues SQR 4. The DECLARE-PRINTER command itself does not cause the report to be produced for a specific printer.SPF or .SPF file to different printers. and HTML. or PostScript Table 7. PostScript. respectively. you may do so with the SQR Viewer or SQR Print. and images. such as the program ex18a.sqr from Chapter 18. PCL. This file format is very useful for saving the output of a report. Producing .LIS . HP LaserJet. charts. lines. shaded areas. If your program creates multiple reports. Command-Line Flags and Output Types (continued) À Note When no flags are specified. When you are ready to print an . To specify a specific format. use one of the following three methods: • Use the -PRINTER:xx command-line flag. including fonts.Snn File Format SQR Portable Format Suitable for SQR Print and SQR Viewer can print this file to different printers.SPF or .

The DECLARE-REPORT command is normally used when your program generates more than one report. When your program generates multiple reports. or HP LaserJet printers. The DECLARE-PRINTER command defines settings for line printers. How is the output file named? The output file will normally have the same name as your program. The type of printer is specified using the TYPE option of the DECLARE-PRINTER command or by specifying one of the predefined printers DEFAULT-LP.lis SQR User’s Guide 195 . If you would like SQR to use another name for the output file (including a user-defined file extension). The default file extension is . for example. if you want to use chapter1. use the FOR-REPORTS option. DEFAULT-HP. The settings for a particular printer will only take effect when output is produced for that printer. For example.3 Printing Issues • Use the USE-PRINTER-TYPE command in your report. DEFAULT-PS.out as the output of the program ex1a. you can name the output file by using multiple -F flags as follows: sqr ex20a username/password -flabel. or Line Printer (LP).SQR 4. PostScript. • Use the PRINTER-TYPE option of the DECLARE-REPORT command. USE-PRINTER-TYPE PS. will cause SQR to produce PostScript output.sqr.out When your program creates more than one report. Your program may have more than one DECLARE-PRINTER command if you define settings for each of the printer types. HP Laserjet (HP). If you are generating an SQR Portable File the default extension is .lis -fletter. and DEFAULT-HT. You must use this command before you print anything because SQR cannot switch printer type in the middle of a program. but with a different file extension. as we discussed in Chapter 18. you can define settings for each printer for each report. To make a DECLARE-PRINTER command apply to a specific report.SPF. you can use the -F option on the command line.LIS for PostScript (PS). the command to run SQR will be as follows: sqr ex1a username/password -fchapter1. For example: declare-report labels layout=labels printer-type=ps end-declare will cause SQR to produce PostScript output for the labels report.lis -flisting.

lis lp myreport.spf -printer:ps Note that this is a one-way conversion—an . the following command will invoke SQR Print to create a PostScript file myreport.lis -flisting.LIS files.lis Windows SQR will print directly. Print Commands by Operating System 196 SQR User’s Guide .SPF files instead of . For example: sqr ex20a username/password -flabel. lpt1).3 Note that you cannot directly name . Table 8. On platforms other than Windows. VisualSQRIBE. Consult your operating system documentation for details.. or the SQR Viewer to choose a printer destination.s01.lis -nolis The -NOLIS command-line flag will cause SQR to produce . The actual file names will be label. For example. /QUEUE for printer destination /COPIES for number of copies /AFTER for printing time /PASSALL to resolve printing issues Use the Print Setup dialog in SQR Print.. You can also use the File Manager Copy command to copy the file to the printer destination (for example.SPF file is named .spf.lis PRINT MYREPORT. You can still use the -F command-line flag to name the file.s02. SQR supplies file extensions such as these when your program generates multiple reports.spf: sqrp myreport.s02.lis from the output file myreport.SPF file. Different operating systems require different techniques for printing the output. Use SQR Print to print multiple copies. you first use SQR Print to create the printer-specific file.LIS file. The following table summarizes the commands and command-line options that you may use on different systems to send your report output to the printer.SPF file can be turned into an . and listing. UNIX BSD VMS lpr myreport. letter. if the output is in SPF format.s01 and the third . but you cannot control the file name extension.lis -fletter. You can also use SQR Print or VisualSQRIBE.LIS file cannot be turned into an . O/S UNIX SysV Command lp myreport.Printing Issues SQR 4. Command-Line Options Use -D for printer destination You may use the UNIX "at" command to schedule the printing time. but an .SPF files. Note that the second .lis -d .

• DECLARE-PRINTER is used to specify printer-specific settings. but it does not itself cause the report to be prepared for a specific printer. use the -PRINTER:xx command-line flag. • To prepare a report for a specific printer.SQR 4.SPF extension. • The -NOLIS and -KEEP command-line flags create files in SQR portable format with an . • The -F command-line flag allows you to name output files (including file extensions). the USE-PRINTER-TYPE command or the DECLARE-REPORT command with the printer-type option. in greater detail. we recommend that you check with your systems administrator about other procedures or commands applicable to printing output files at your site.3 Printing Issues In any case. SQR User’s Guide 197 . Summary • Command-line flags create output files appropriate for different platforms and printers. how to pass arguments and flags from the SQR command line. The next chapter will explain.

.

Database[/STAR][/Username] is the name of the database to use and an optional user name.. DB2 connectivity Ssname/SQLid is the subsystem name and SQL authorization ID to use. SQR prompts you for the program name. SQR Command-Line Arguments SQR User’s Guide 199 . if your shell uses the question mark as a wild card character. If entered as "?" or omitted.] where: Argument program Description The name of your program. Informix Ingres ODBC Table 9. This technique is a good way to modify your program at run time. Command-line flags such as -Bnn.27 Using the SQR Command Line This chapter explains how to use the SQR command line to specify flags and pass arguments to your program. your user name. If entered as "?" or omitted.] [args . The syntax of the SQR command line is as follows: SQR [program] [connectivity] [flags .... Database is the name of the database to use. On UNIX-based systems.SQR.. SQR prompts you for it. you must precede it with a backslash (\).] [@file . -KEEP. or -S can be entered on the command line to modify some aspect of program execution or output. Command-line arguments are typically answers to requests (made in the SQR program by ASK or INPUT commands) for user input. The default file type or extension is . and password for the database. Data_Source_Name/[Username]/[Password] is the name you give to the ODBC driver when you set up the driver.. The information needed by SQR to connect to the database.

Rdb Red Brick Data_Source_Name/[Username]/[Password] is the name you give to the Red Brick supplied driver when you setup the driver. File containing program arguments. Table 9. and password for the database.3 Argument Description Oracle [Username]/[Password[@Database]] is your user name and password for the database. @B:ORASERVER). The command-line arguments program. you can specify the connection string for the database (e. and password for the database.g. SQLBase [Database]/[Username]/[Password] is the name of the database to use. Arguments listed in the file are processed one at a time.Using the SQR Command Line SQR 4. Username/[Password] is your user name and password for the database. your user name... You can also specify the connection string for the database (e.. and args can be specified in this file. Any of the flags listed in the SQR Language Reference. one argument per line. SYBASE flags args. Arguments must be entered on the command line in the same sequence they are expected by the program—first all ASK arguments in order and then INPUT arguments in order. Arguments listed here are used by the ASK and INPUT commands rather than prompting the user. SQR Command-Line Arguments (continued) @file. Optionally. your user name... Arguments used by SQR while the program is running. @B:RDBSERVER). 200 SQR User’s Guide . connectivity. [Username]/[Password[@Database]] is your user name and password for the database.g.

You can pass arguments to SQR on the command line. followed by the file file. To reference a file on the command line. SQR User’s Guide 201 . the argument must be entered directly after the flag with no intervening space. On some platforms. precede its name with the at sign (@) as shown in the following example: sqr myreport sammy/baker arg1 arg2 @file. SQR will not prompt the user but will instead return a status meaning "No more arguments.dat In this example. such as those invoked by scripts or menu-driven applications.dat. reference the file name on the command line and put one argument on each line of the file. You thus avoid any limits imposed by the operating system. the operating system will impose a limit on the number of arguments or the total size of the command line. SQR uses this input instead of prompting the user. Each line in file. How SQR Retrieves the Arguments When the ASK and INPUT commands execute. After the available arguments are used. subsequent ASK or INPUT commands prompt the user for input. When you pass arguments in a file." SQR processes all ASK commands before INPUT commands. When a flag has an argument.3 Using the SQR Command Line Command-Line Flags Command-line flags begin with a hyphen.dat has an additional argument. Passing arguments is especially useful in automated reports. in files. See the SQR Language Reference for a complete discussion of SQR command line flags. Specifying Command-Line Arguments You can pass an almost unlimited number of command-line arguments to SQR at run time.SQR 4. or with the environment variable SQRFLAGS. SQR checks to see if you entered any arguments on the command line or if an argument file has been opened. If the INPUT command is used with the BATCH-MODE argument. If so. arg1 and arg2 are passed to SQR.

printer initializations. the following command line passes the value 18 to SQR: sqr myreport sammy/baker 18 An #INCLUDE command in the report file chooses file printer18.SQT file.dat. For example.dat’ ! Contains #DEFINE commands for ! printer and paper width and length declare-layout report paper-size =({paper_width} {paper_length}) end-declare end-setup 202 SQR User’s Guide .Using the SQR Command Line SQR 4. the contents of argfile2. Using an Argument File If you wanted to print the same report on different printers with different characteristics. Arguments stored in files do not require quotes and cannot contain them. and the value "New York".dat. you could save values for the different page sizes. #include ’printer{num}.3 À Note If you compiled your SQR program into an . When a command-line argument is case-sensitive or contains spaces. the actual strings with uppercase characters and any spaces are passed to SQR. the contents of argfile1. Specifying Arguments and Argument Files You can mix argument files with simple arguments. The "OH" argument is in quotes to ensure that SQR uses uppercase OH. in that order. the value "OH". Use INPUT instead.dat "OH" @argfile2. ASK commands will have already been processed.dat based on the command-line argument: begin-setup ask num ! Printer number.dat "New York" This command line passes SQR the number 18. it must be enclosed in quotes. and fonts in separate files and use a command-line argument to specify which file to use. as shown in the following example: sqr rep2 sammy/baker 18 @argfile1.

. user name. #define paper_length 11 #define paper_width 8. For example: sqr myreport ? @argfile.SQR 4.dat In this example.3 Using the SQR Command Line In this example.dat The first two lines of the argument file for this example contain the program name and user name/password: myreport sammy/baker 18 OH . 18 is a compile-time argument. use the question mark (?). the program prompts the user for the user name and password instead of taking them from the first line in the argument file.5 #define bold_font LS12755 #define light_font LS13377 #define init HM^J73011 Passing Command-Line Arguments—Other Approaches SQR examines an argument file for a program name. user name. The #INCLUDE command then uses the value of num to include the file printer18.dat-definitions for printer in Bldg 4. or password if none is provided on the command line. SQR User’s Guide 203 . the ASK command assigns the value 18 to the variable num. as shown in the following example: sqr ? ? @argfile.. which could include commands similar to the following: ! Printer18. or password on the command line or in an argument file.dat In this example. the user is prompted for the program name and user name/password.dat. The following command line omits the program name. You can use more than one question mark on the command line. SQR will prompt the user to supply these. and password: sqr @argfile. user name. If you do not want to specify the report name.

dat with an INPUT command.dat End acctlist. the double hyphen and double at sign are interpreted as single literal characters: Creating an Argument File from a Report You can create an argument file for one program from the output of another program. The hyphen precedes an SQR flag. state.Using the SQR Command Line SQR 4. To use either of these characters as the first character of a command-line argument. you could print a list of account numbers to the file acctlist.dat @@X2H44 In this example. then run a second report with the following command: sqr myreport sammy/baker @acctlist.dat with a flag such as "END." as shown in the following example: 123344 134455 156664 . double the character to indicate that it is a literal hyphen or at sign. co_name.. addr. contact.. END An SQR program could use the numbers in acctlist. city.dat. zip do print-page ! Print page with ! complete company data from customers where cust_num = $account end-select goto next ! Get next account number end_proc: end-procedure !get_company 204 SQR User’s Guide . and the at sign precedes an argument file name. as shown in the following example: sqr myreport ? --17 @argfile.3 Reserved Characters The hyphen (-) and at sign (@) characters have special meaning on the command line. as shown in the following example: begin-procedure get_company next: input $account batch-mode status = #status if #status = 3 goto end_proc end-if begin-select cust_num. For example.

your username/password. Windows NT. and Windows NT You can create UNIX shell scripts or MS-DOS batch (. Windows 95/98. UNIX. SQR User’s Guide 205 .SQR 4. then writes a temporary command procedure and submits it to the batch queue.3 Using the SQR Command Line Using Batch Mode SQR lets you run reports in batch mode in VAX/VMS. UNIX. SUBMITSQR. run-time arguments for the program (if supplied).COM. This DCL command procedure prompts you for the name of your report. and Windows 95/98 operating systems. VAX/VMS You can run your SQR reports in batch mode using the supplied procedure. Include the SQR command line in the file as you type it at the keyboard.bat) files to run SQR.

The next chapter explains how to create HTML output and publish it on a Web server. 206 SQR User’s Guide . • Use batch mode to run multiple programs. • Specify a command-line argument to supply information requested by an ASK or INPUT command. • Use a question mark on the command line to prompt a user for input. • Specify multiple arguments in an argument file referenced on the command line.3 Summary • Enter a flag on the command line to modify program execution or output.Using the SQR Command Line SQR 4.

SQR Capabilities Available with HTML The SQR language has a rich set of available features. Though. This chapter also explains how to create a script that will allow users browsing the Internet or an Intranet to request execution of an SQR program and view its output. • Centering The SQR features not currently supported for HTML output include: • Font selection SQR User’s Guide 207 . Many books and web sites offer information on this subject. if you you wish to create customized HTML output using SQR’s HTML Procedures you may find it helpful to learn more about HTML. • Font styles. or the Internet. The bold and underline font styles are supported. It is not necessary to be an HTML "expert" to generate fine quality HTML output with SQR. A point size specified in an SQR program is mapped into an appropriate HTML font size. À Note SQR makes it easy to generate professional quality HTML report files.28 Working with HTML This chapter explains how to generate HTML from an SQR program output and how to publish that output onto a Web site so that it will be available over an Intranet. The SQR features supported under HTML include: • Images • Font sizing. Extranet. HTML specifies font sizes in a value from one to six. The SQR language specifies font sizes in points. but some of these features are not available for HTML output due to the limitations of that format.

0 or 3. tables. The procedures used in the last two options are contained in a file called html. that output contains HTML tags. Each method provides a different level of HTML features.0 output viewable in a Web browser. HTML output looks something like this: <HTML><HEAD><TITLE>myreport.INC is located in the SAMPLE (or SAMPLEW) directory. 208 SQR User’s Guide .inc. An HTML tag is a character sequence that defines how information is displayed in a Web browser. • Using additional HTML procedures produces output with a full set of HTML features. • Running an unmodified SQR program with the command line flag -PRINTER:EH makes its HTML 3.lis</TITLE></HEAD><BODY> This code is just a portion of the HTML output that SQR generates.3 • • Bar codes Lines and boxes (Using -PRINTER:HT) Producing HTML Output There are four ways to produce HTML output from an SQR program. With this method.2 output viewable in a Web browser. including lists. The tags it contains indicate the starting and end points of HTML formatting. and hypertext links. With this method. To utilize HTML procedures. • Using two HTML procedures—html_set_head_tags and html_set_body_attributes—allows you to define a title and background image for the HTML output. you must still use the command line flag -PRINTER:HT. HTML Output When an SQR program is used to generate HTML output.inc’ The file HTML. Use the command line flag -I to specify its path. the SQR program must include the command: #include ’html. you must still use the command line flag -PRINTER:HT.Working with HTML SQR 4. • Running an unmodified SQR program with the command line flag -PRINTER:HT makes its HTML 2.

on Windows platforms) by including the -RT flag.SPF files by using a command similar to: sqrwp myreport. Using -PRINTER:EH You can generate Enhanced HTML output from an SQR program using the command-line flag -PRINTER:EH.spf -PRINTER:EH From within the the SQR Viewer. The -PRINTER:EH default output is HTML 3. the tag <HTML> defines the output that follows as HTML output.0.sqr sammy/baker@rome -RT -PRINTER:EH SQR User’s Guide 209 . Run the .ini file. The HTML level output from the SQR Viewer is also determined by your sqr. To generate Enhanced HTML use the -PRINTER:EH flag in the command: sqrw myreport.SQR 4.sqr sammy/baker@rome -PRINTER:EH You can control the version of HTML that is used by editing the [Enhanced-HTML] parameter FullHTML in the sqr. in the HTML code shown above. All output is displayed as fully formatted HTML 3. myreport. it is not necessary to re-run your SQR program.sqt sammy/baker@rome -PRINTER:EH As is true of executing any .SPF files from which you want to generate Enhanced HTML output.ini file settings and has the same default value.SQT file.SQT files")." above. You may invoke SQR Print (sqrp or sqrwp.0 or 3.lis.3 Working with HTML For example. depending on your platform) to output Enhanced HTML from .2 or FALSE for HTML 3. you may also output this same highquality HTML by selecting File | Save as HTML.SQT file against SQR Execute with a command similar to the following: sqrwt myreport. You may also generate Enhanced HTML files with pre-compiled SQR program files (". This will produce output which contains HTML formatting tags such as those shown in "HTML Output. you may run it against SQR (or SQRW. The tags <TITLE> and </TITLE> enclose the report title—in this case. The <BODY> tag indicates that the information following it comprises the body of the report. It's as simple as that. If you have existing . Adjust this based upon the level of HTML your web browser supports. Set FullHTML equal to TRUE for HTML 3.0.2 text. you can easily output high-quality HTML from SQR programs by just issuing a command similar to: sqrw myreport. Using -PRINTER:EH.

"Previous". you may also use additional flags such as -EH_CSV. You can also use the navigation links to move through the pages in any order you wish -.sqr (in Web browser) When -PRINTER:EH is specified. -EH_CSV:file. or "Next". -PRINTER:EH Output for ex7a. will be similar to the following example. -EH_Icons:dir specifies the directory where the HTML should look for the referenced icons. which produces a simple master/detail report.3 Chapter 7 in this User’s Guide contains the program ex7a. when viewed from a web browser. You can enter a specific page number and press <Enter> on your keyboard (or click "Go!"). -EH_Scale:{nn} sets the scaling factor from 50 to 200. -EH_CSV:file associates the CSV icon with the specified file. Note that a "banner" frame is produced which contains the means to navigate through the report.sqr. These flags only work with -PRINTER:EH. "Last". you can produce HTML output which. and -EH_Scale:{nn} to modify the ouput. 210 SQR User’s Guide . -EH_CSV creates an additional output file in Comma Separated Value format."First". By running it with -PRINTER:EH.Working with HTML SQR 4. -EH_Icons:dir.

insert %%Background extension at the beginning of your program: Print-Direct Printer=html ’%%Background tile. Enter code similar to the following at the beginning of your program: Print-Direct Printer=html ’%%Body-BgColor seashell’ For information about specifying colors. SQR User’s Guide 211 . Enhanced HTML extensions also allow you to include your own HTML tags in the output. These tags are passed-through to the output without change. and hyperlinks. By using these extensions you can specify features such as the HTML title. background color (or image). You can specify the title of the HTML page by using the %%Title extension at the beginning of your SQR program by entering: Print-Direct Printer=html ’%%Title Monthly Sales’ Specifying Background Color You may specify a background color for the pages generated with -PRINTER:EH by using the %%Body-BgColor extension.gif’ The background attribute can be any valid URL. Specifying HTML Title The HTML page title normally appears on the caption bar of the browser window and it is also used when creating a bookmark for the page. please refer to the section "Specifying HTML Colors" below. It is placed between the <TITLE> </TITLE> HTML tags. Specifying a Background Image for the Report If you would like to use a background image for the report pages that enhanced HTML generates. SQR suports extensions that allow you to control the generated HTML. text color. you may want additional control over the Enhanced HTML code that is generated with -PRINTER:EH.3 Working with HTML Setting HTML Attributes under -PRINTER:EH In certain cases.SQR 4. You can use this feature to include advanced HTML capabilities such as JavaScript and <APPLET> tags.

A subsequent invocation of %%Color with a different color will set the current color to the new color.com’ Specifying Text Color To change the color of text you can use the %%Color and %%ResetColor extensions. 212 SQR User’s Guide . or it could be the location in the page where the link takes you.sqribe. Print-Direct Printer=html ’%%Anchor section2’ Print ’XYZ’ () In our example. you can control which frame will display the target of the link using the target option of the %%Href extension. To restore the color back to the default (normally.3 Specifying Hyperlinks To specify a hyperlink in your report use the %%Href extension. black) use the %%ResetColor extension. image. or chart object into a link. For example. clicking on the "ABC" text on the page will jump to the "XYZ" text.Working with HTML SQR 4. examine the following piece of code: Print-Direct Printer=html ’%%Href #section2’ Print ’ABC’ () . The latter is specified using the %%Anchor extension. This is similar to the behavior of the ALTER-PRINTER command in SQR. For example.. The %%Color extension affects all text (and number) printing from this point on. This extension allows you to make a text. When using frames or multiple browser windows. The object can be the item on which you click to activate the link. when the value of the column is over 100000 we print it in red. specify on one line Print-Direct Printer=html ’%%Href target="_top" http://www. This is demonstrated in the following code example: If &Salary > 100000 Print-Direct Printer=html ’%%Color red’ End-If Print &Salary () If &Salary > 100000 Print-Direct Printer=html ’%%ResetColor’ End-If In our example. number..

lightcyan. and the last two specify the blue. lightgreen. violet. tan. By invoking the "html_on" procedure. darkblue. cyan. gray. lightpink. Using a name is the easiest and offers considerable variety. azure. gold. Including Your Own HTML Tags The SQR PRINT with CODE-PRINTER=HT provides a means for you to inject any text into the HTML output. ’>’. green. maroon. Be careful however not to try to use this hook for formatting as it is very likely that your formatting will conflict with -PRINTER:EH enhanced HTML formatting. lavender.inc" and are documented in this chapter and in the SQR Language Reference. To gain full control over formatting you can use the HTML procedures that are defined in "html. blue. limegreen. darkgreen. darkcyan. When using SQR PRINT with CODE-PRINTER=HT. royalblue. plum. green would be #00FF00. beige.SQR 4. lightgrey. navajowhite. aqua. violet. darkorange. This text could have anything that your browser understands. SQR User’s Guide 213 . silver. red. coral. orange.3 Working with HTML Specifying HTML Colors Color can be specified in one of two ways: by name or by value. The first two digits specify the intensity of the red. black. skyblue. purple. Enhanced HTML will not translate special symbols that are used in HTML tags such as ’<’. you instruct Enhanced HTML to perform no formatting at all. olive. seashell. aquamarine. lime. lightcoral. SQR makes no attempt to check the text you are printing.inc" or by using SQR PRINT with CODE-PRINTER=HT to insert HTML codes. magenta. white. darkgray. You will then specify all formatting using the HTML procedures in "html. You might consider trying some of the following colors: antiquewhite. navy. crimson. Your browser’s documentation should contain a complete listing of supported colors. goldenrod. lightyellow. turquoise. pink. For example. -PRINTER:EH enhanced HTML makes extensive use of HTML tables. and yellow. lightblue. the next two specify the green. teal. and ’&’. brown. This is done by entering a # character followed by six hexadecimal digits. Specifying color as an RGB hexadecimal value is more complicated.

HTML reserved characters are mapped into the corresponding HTML sequence.. >. Add either DECLARE-PRINTER with the argument TYPE=HT or USEPRINTER-TYPE HT. Font sizes are mapped to an appropriate HTML font size. respectively. " are mapped into the character sequences &lt. will be similar to the following example. The "navigation bar" permits you to move the first page and last page or move one page forward or back from your relative page viewing position. HTML output is generated as follows: • • • • • All output is displayed as preformatted text. &gt. you can make some simple modifications to your program. and &quot. 214 SQR User’s Guide . using the HTML <PRE> </PRE> tags. &amp. Chapter 7 in this User’s Guide contains the program ex7a.. This prevents the Web browser from mistaking such output as an HTML sequence.3 Using -PRINTER:HT Another method for generating HTML output from an SQR program is by running your program with the command-line flag -PRINTER:HT. you can produce HTML output which. Note that a left frame is produced with hyperlinks to each page of the report.Working with HTML SQR 4. Text is displayed using a fixed-width font such as Courier. Text is positioned on the page by the position coordinates specified in the SQR program. when viewed from a web browser. Alternatively. The characters <.. The right frame also features a "navigation bar" which appears at the top of every page in the report.. By running it with -PRINTER:HT. &. With these methods.sqr produces a simple master/detail report.

You can then focus on information that is truly of interest. 3. you can also specify the report page ranges you wish to see within an HTML file. you can generate HTML ouput files "burst" by report page numbers -. -BURST:P0.one report page per . you can generate HTML format reports using -PRINTER:EH or -PRINTER:HT command line flags. (This is frequently referred to as "demand paging.1.htm file.3 Working with HTML -PRINTER:HT Output for ex7a. You can do all of these things by using -BURST:{xx} in conjunction with -PRINTER:EH or -PRINTER:HT.") So. Using -BURST:P (or BURST:P1) with -PRINTER:EH or -BURST:P1 with -PRINTER:HT. 4 and 5.3-5 generates an HTML file containing only report page numbers 1.htm output files. For example. with SQR.SQR 4. if you have a 25 page report. Using -PRINTER:HT.sqr (in Web browser) "Bursting" and Demand Paging We have shown you how. SQR User’s Guide 215 . you might want to preview a report’s Table of Contents in your web browser without generating an entire report. it will be divided into 25 separate . But what if you want your HTML files to be smaller in size for faster load time or divided on the basis of report page ranges? Or.

Working with HTML SQR 4. 216 SQR User’s Guide . Using -BURST:S. As an example of how simple it is to use DECLARE-TOC and TOCENTRY to improve the information available in generated HTML output. your Table of Contents will provide more detailed information than simple hyperlinked page numbers as illustrated in the example below. If you have used DECLARE-TOC and TOC-ENTRY commands in your SQR program.in the main procedure immediately after the begin-select and Print ’Customer Information’ (. if you specify -PRINTER:HT with -BURST:T. We added the following code to the beginning of ex7a.3 Similarly. And. we modified ex7a.sqr: begin-setup declare-toc common for-reports=(all) dot-leader=yes indentation=2 end-declare end-setup We also added code to the body of the program -.g. you will only generate the Table of Contents file.sqr. -BURST:S2 bursts on level 2). you will generate report output according to symbolic Table of Contents entries.1) toc-entry text = &name The HTML ouput from the modified ex7a. if you if you specify -PRINTER:HT with -BURST:S. you can specify the numeric level to burst on.sqr program is shown in the illustrations that follow.. (e.

SQR 4.3 Working with HTML -PRINTER:HT with -BURST:T Output for Modified ex7a.sqr -PRINTER:HT Output from Modified ex7a.sqr SQR User’s Guide 217 .

gif"’) The first line of this code causes the title "Monthly Report" to be displayed. as described in "Producing HTML Output. To utilize these procedures. Specifically. the entire sequence ’<TITLE>Monthly Report</TITLE>’ is passed as an argument to the procedure html_set_head_tags." above. the SQR program must include the file html.inc. For example: do html_set_head_tags(’<TITLE>Monthly Report</TITLE>’) do html_set_body_attributes(’BACKGROUND="/images/mylogo. 218 SQR User’s Guide .Working with HTML SQR 4. Note that the argument is enclosed in single quotes.sqr Setting Attributes with HTML Procedures You can use SQR’s HTML procedures html_set_head_tags and html_set_body_attributes to define a title and background image for a report.3 -PRINTER:EH Output Table of Contents File from Modified ex7a. You must also run the program using the command-line flag -PRINTER:HT. These procedures must be called at the start of the program.

sqr will create a FRAME file (myreport. including HTML physical tags and logical markup tags.3 Working with HTML The second line causes the background image mylogo.gif to be displayed for the Web page. columns. and strikethrough.INI file. including paragraph breaks.gif"> Using Additional HTML Procedures Using additional HTML procedures in the SQR program provides enhanced capabilities. including captions. unordered lists. superscript. an argument is passed to the procedure. and menus • Paragraph formatting. <HTML><HEAD><TITLE>My Report</TITLE></HEAD> <BODY BACKGROUND="/images/mylogo. and horizontal dividers • Tables. code. and sample. The value of zz ranges from 00 to 99 and reflects the report number. including ordered lists. HTML logical markup tags include citation.hzz and when set to LONG the files use the form myreport_zz. Again. HTML physical tags include subscript. SQR User’s Guide 219 . directory lists. line breaks. rows. while the file name and path are enclosed in double quotes. When set to SHORT the report output files use the form myreport. Note that the entire argument is enclosed in single quotes.htm. The report output file extensions are controlled by the OUTPUT-FILE-MODE entry in the [Default-Setting] section of the SQR.htm) and report output file(s). the two lines of code above will generate the following HTML output. Together. including: • Highlighting. • Headings • Hypertext links • Lists. and column headings Output File Types An SQR report named myreport.SQR 4. keyboard. definition lists.

If myreport.sqr created multiple reports. such as spaces between PRINT commands. and other information are placed in the HTML output in the order in which they are generated by the SQR program. If your Web browser supports the HTML FRAME construct. Each report output file contains a list of pages (hypertext links) at the end of the file. In addition. • 220 SQR User’s Guide . White space.h00. Text is displayed using a proportional font such as Arial. is removed. Text. then the FRAME file will contain a link to each report output file. myreport_00.Working with HTML SQR 4. An SQR program with these procedures generates output as described above in "Using Printer:HT. To test a program’s output." with the following exceptions: • • • The HTML <PRE> </PRE> tags are not used. each report output file will contain links to the other report output files that were created during the program run.htm). HTML tags. Testing HTML output produced by an SQR program can be previewed on a local system. Positioning values specified in the SQR program are ignored. otherwise open the report output file (myreport.htm). open the file in the Web browser. This is a good way to test the output before it is published on a Web site. Using HTML Procedures in an SQR Program To enhance the appearance of the HTML output.3 The FRAME file shows a list (hypertext links) of report pages in one frame and the report text in another frame. open the FRAME file (myreport_frm. use HTML procedures in an SQR program.

As before. the program must specify a large page length to prevent page breaks. Thus.SQR 4. the SQR program must include the file html. If a page break falls in the middle of an HTML construct. The SQR program must also call the procedure html_on at the start of the program. as displayed by the Web browser.1) #total_amount (4. as described in "Producing HTML Output. All position qualifiers in the SQR program are ignored. regardless of their position qualifiers. Note that all the text appears on the same line with no spaces between the data." above. such as spaces between PRINT commands is removed.20) The output from the above sample code. print print print print print ’Report summary:’ (1. Positioning Objects When HTML procedures are turned on. such as a table. HTML output is generated without the <PRE></PRE> tags.1) ’Amount billed:’ (3. the output may display incorrectly. The command that calls this procedure is: do html_on Additionally. and program output and HTML tags are placed in the output file in the order in which they are generated. the HTML procedures must be used to format the report. you must run the SQR program with the -PRINTER:HT command-line flag. White space. Use the command DECLARE-LAYOUT with a large MAX-LINES setting to prevent page breaks from occurring. follows.1) #amount_amount (3. How to Use HTML Procedures To utilize the HTML procedures.3 Working with HTML À Note See the SQR Language Reference for more information on the HTML procedures available with SQR. SQR User’s Guide 221 .inc. The following SQR code does not use the HTML procedures to format the output.20) ’Total billed:’ (4. SQR automatically inserts the page navigation hypertext links and an HTML <HR> tag at a page break.

20) do html_table_end The output from the above code is displayed by the Web browser as follows: 222 SQR User’s Guide . This empty string is required if no other argument is passed. Note that an empty string is passed to each procedure as it is called.1) do html_td(’’) print #total_amount (4. the output can be formatted properly. print ’Report summary:’ (1.’’) do html_table(’’) do html_tr(’’) do html_td(’WIDTH=300’) print ’Amount billed:’ (3.3 With the HTML procedures for line breaks and a table.1) do html_br(2.1) do html_td(’’) print #amount_amount (3.Working with HTML SQR 4. The procedures html_table. html_td. html_tr. The following SQR code uses the procedure html_br to separate the first two lines of text. and html_table_end are used to display the totals in a tabular format.20) do html_tr(’’) do html_td(’WIDTH=300’) print ’Total billed:’ (4.

but it can be used for completeness.3 Working with HTML Table Procedures When the HTML procedures are turned on. but it can be used for completeness. • Column headings—call html_th to mark the start of a column heading and html_th_end to mark the end of the column heading.inc’ begin-program do main end-program ! set a large page length to prevent page breaks begin-setup declare-layout default max-lines=750 end-declare end-setup begin-procedure main ! turn on HTML procedures do html_on Program continues on the following page. the position values cannot be used to display records in a tabular format. • Columns—call html_td to mark the start of a column and html_td_end to mark the end of the column. • Rows—call html_tr to mark the start of a new row in the table and html_tr_end to mark the end of the row. but it can be used for completeness. To display records in a tabular format use the following procedures: • Tables—call html_table to start a table and html_table_end to end a table. SQR User’s Guide 223 . The following SQR program uses these table procedures to display information in a tabular format. The end is typically implied and html_tr_end is not needed. Thus.SQR 4. all positioning values in the SQR program are ignored. The end is typically implied and html_td_end is not needed. Program ex28a. but it can be used for completeness. The end is typically implied and html_caption_end is not needed. The end is typically implied and html_th_end is not needed.sqr #include ’html. • Captions—call html_caption to mark the start of a table caption and html_caption_end to mark the end of the table caption.

Working with HTML SQR 4.25) next-listing skiplines=1 need=1 from customers end-select ! end the table do html_table_end end-procedure Output for ex28a.3 Program ex28a.1) do html_tr(’’) do html_th(’’) print ’Cust No’ (+1.6) edit 099999 do html_td(’’) name (1.10.sqr (continued) ! start the table and display the column headings do html_table(’border’) do html_caption(’’) print ’Customer Records’ (1.10) ! display each record begin-select do html_tr(’’) do html_td(’’) cust_num (1.sqr 224 SQR User’s Guide .1.1) do html_th(’’) print ’Name’ (.

• Citation—call html_cite and html_cite_end. The available heading levels range from one to six. The following SQR code displays text as a second-level heading: do html_h2(’’) print ’A Level 2 Heading’ (1.SQR 4. call the corresponding end procedure.1) do html_h2_end Highlighting The highlighting procedures provide the ability to display text in the various HTML highlighting styles.3 Working with HTML Headings The heading procedures display text using heading levels such as those used in this book. Once the text is output call the corresponding end procedure. • Superscript—call html_sup and html_sup_end. To utilize the highlighting procedures. • Code—call html_code and html_code_end.1) do html_sub(’’) print ’subscript’ () do html_sub_end print ’ text’ () SQR User’s Guide 225 . call the appropriate highlighting procedure before the text is output. • Sample—call html_sample and html_sample_end. • Keyboard—call html_kbd and html_kbd_end. Highlighting is also called logical markup. a first-level heading is the highest. • Strike—call html_strike and html_strike_end. • Subscript—call html_sub and html_sub_end. To utilize the heading procedures. Once the text is output. The following SQR code displays text in the subscript style: print ’Here is ’ (1. The following highlighting procedures are available: • Blink—call html_blink and html_blink_end. call the appropriate heading procedure before the text is output.

Working with HTML

SQR 4.3

Hypertext Links
The hypertext link procedures provide the ability to create hypertext links and hypertext link anchors. When the user clicks on the hypertext link, the Web browser switches to the top of the specified HTML document, to a point within the specified document, or to a link anchor within the same document. A hypertext link can point to the home page of a Web site, for example. To insert a hypertext link, use the procedure html_a, output the information that is to become the hypertext link, and use the procedure html_a_end to mark the end of the hypertext link. Two useful attributes for the procedure html_a, are the HREF and NAME attributes. Use the HREF attribute to specify where the hypertext link points to. Use the NAME attribute to specify an anchor to which a hypertext link can point. These attributes are passed as arguments to the procedure html_a. The following SQR code creates an anchor and two hypertext links. The anchor is positioned at the top of the document. The first hypertext link points to the HTML document home.html. The second hypertext link points to the anchor named TOP in the current document. Note the pound sign (#) in the argument, which indicates that the named anchor is a point within a document. The third link points to an anchor named POINT1 in the document mydoc.html.
do html_a(’HREF=home.html’) print ’Goto home page’ () do html_a_end do html_a(’NAME=TOP’) do html_a_end print ’At the top of document’ () do html_br(40, ’’) print ’At the bottom of document’ () do html_p(’’) do html_a(’HREF=#TOP’) print ’Goto top of document’ () do html_a_end do html_a (’HREF=mydoc.html#POINT1’) print ’Goto point1 in mydoc.html’ () do html_a_end

226

SQR User’s Guide

SQR 4.3

Working with HTML

Images
An image can be included in an HTML output with the PRINT-IMAGE command or the procedure html_img. Both of these produce the HTML <IMG> tag. The PRINT-IMAGE command displays images for all printer types but only allows you to specify the image type and source. The html_img procedure displays images only for HTML printer type but it allows you to specify any of the attributes available for an HTML <IMG> tag. For HTML output, only files of the GIF or JPEG format can be used. With PRINT-IMAGE, use the argument TYPE=GIF-FILE or TYPE=JPEG-FILE, respectively.

Lists
The list procedures display lists. To utilize these procedures, call the appropriate procedure before the list is output. Once the list is output, call the corresponding end procedure. The following list procedures are available.

• Definition (for lists of terms and their definitions)—call html_dl and html_dl_end. • Directory—call html_dir and html_dir_end. • Menus—call html_menu and html_menu_end. • Ordered (numbered or lettered) lists—call html_ol and html_ol_end. • Unordered (bulleted) lists—call html_ul and html_ul_end.
To display a list, except for the definition list, call the appropriate list procedure before the list is output. Call html_li to identify each item in the list; you can also call html_li_end for completeness. Once the list is output call the corresponding end procedure. The following code displays an ordered list:
do html_ol(’’) do html_li(’’) print ’First item in list’ (1,1) do html_li_end do html_li(’’) print ’Second item in list’ (+1,1)

SQR User’s Guide

227

Working with HTML

SQR 4.3

do html_li_end do html_li(’’) print ’Last item in list’ (+1,1) do html_li_end do html_ol_end

To display a definition list call html_dl before the list is output. Call html_dt to identify a term and html_dd to identify a definition. Once the list is output call html_dl_end. You can also call html_dd_end and html_dt_end for completeness The following code displays a definition list:
do html_dl(’’) do html_dt(’’) print ’A daisy’ (1,1) do html_dt_end do html_dd(’’) print ’A sweet and innocent flower’ (+1,1) do html_dd_end do html_dt(’’) print ’A rose’ (+1,1) do html_dt_end do html_dd(’’) print ’A very passionate flower’ (+1,1) do html_dd_end do html_ol_end

Paragraph Formatting
The HTML procedures provide various paragraph-formatting capabilities. To utilize these procedures, call the appropriate paragraph procedure before the list is output. The following procedures are available:

• Paragraph breaks—call html_p to mark the start of a paragraph and html_p_end to mark the end. Many HTML constructs imply an end of paragraph; thus, the procedure html_th_end is not needed, but it can be used for completeness. • Line breaks—call html_br to insert a line break. • Horizontal dividers (usually a sculpted line)—call html_hr to insert a horizontal divider. • Prevent line wrapping—call html_nobr to mark the start of a section of text that cannot be wrapped by the Web browser to fit the width of the browser window. Use the procedure html_nobr_end to mark the end.

228

SQR User’s Guide

SQR 4.3

Working with HTML

The following code uses the paragraph-formatting procedures to format text into paragraphs:
print ’Here is some normal text’ (1,1) do html_p(’ALIGN=RIGHT’) print ’Here is right aligned text’ (+1,1) do html_br(1,’’) print ’and a line break’ (+1,1) do html_p_end do html_hr(’’) do html_nobr(’’) print ’A very long line of text that cannot be wrapped’ (+1,1) do html_nobr_end

User-Defined HTML
You can incorporate your own HTML tags into the HTML output. To do so, use the PRINT command with the argument CODE-PRINTER=HT. Text printed with this argument is placed only in the HTML output generated when the HTML printer type is specified. With all other printer types, the text is not placed in the output. In addition, the specified text is placed directly in the HTML output without any modifications, such as the mapping of reserved characters. The following SQR code uses the HTML <B> tag to print bold text:
print ’<B>’ () code-printer=ht print ’Bold text’ () print ’</B>’ () code-printer=ht

Modifying an Existing SQR Program
In this section, an existing SQR program, ex12a.sqr, is modified to use HTML procedures. (The modified program is named ex28b.sqr). First, examine the output from ex12a.sqr when this program is run without modifications using the command line flag -PRINTER:HT. Three HTML files are generated: ex12a.htm, ex12a_frm.htm, and ex12a_toc.htm. If your web browser supports HTML frames, after opening ex12a_frm.htm, you should see the following:

SQR User’s Guide

229

Working with HTML

SQR 4.3

Program ex28b.sqr
#include ’html.inc’ begin-setup declare-layout default max-lines=10000 end-declare end-setup begin-program do main end-program begin-procedure main do html_on print $current-date (1,1) edit ’DD-MON-YYYY’ do html_p(’’) do html_table(’BORDER’) do html_tr(’’) do html_th(’WIDTH=250’) print ’Name’ (3,1) do html_th(’WIDTH=120’) print ’City’ (,32) do html_th(’WIDTH=60’) print ’State’ (,49) do html_th(’WIDTH=90’) print ’Total’ (,61)

Program continues on the next page.
230 SQR User’s Guide

sqr (continued) begin-select do html_tr(’’) do html_td(’’) name (. WIDTH defines the width of the columns. and html_th are used to position the information in a tabular format.55. SQR User’s Guide 231 . The procedures html_table.40) do html_td(’ALIGN=RIGHT’) print #grand_total (. html_tr. COLSPAN causes the label "Grand Total" to be spanned beneath three columns of data.1. The procedure html_on is used to turn on the HTML procedures.+1. Note the arguments passed to the HTML procedures.16) do html_td(’’) state (.+1. html_td. Instead of using a HEADING section. the procedure tr_th is used to display column headings.11) edit 99999999. a DECLARE-LAYOUT command with a large page length setting specified in the MAX-LINES argument is issued to prevent page breaks.+1.3 Working with HTML Program ex28b.11) edit 99999999. BORDER produces the sculpted border seen in the output that follows.30) do html_td(’’) city (.99 next-listing no-advance need=1 let #grand_total = #grand_total + &tot from customers end-select do html_tr(’’) do html_tr(’’) do html_td(’COLSPAN=3 ALIGN=RIGHT’) print ’Grand Total’ (+1.5) do html_td(’ALIGN=RIGHT’) tot (.SQR 4. ALIGN right-aligns the text in the "Total" column.99 do html_table_end end-procedure ! main In this code.

you must: 1.3 Output for ex28b. The directory must be one that is pointed to by a URL on your server. 3. 232 SQR User’s Guide . Copy the generated HTML output files to the chosen directory on the Web server. If the output is generated on a client PC. See your Webmaster for more details on creating a URL. use a utility such as FTP to transfer the HTML output files to the Web server. 4. Thereafter.sqr Publishing the Report A report generated by an SQR program can be published onto the Web site. the user of a Web browser can view the report over the Internet or an Intranet by specifying the report’s URL address. Determine where the report output will be stored on the Web server. Run the SQR program.Working with HTML SQR 4. To publish a report. 2. Create hypertext links in a home page or other Web site that point to the report files so users browsing the network can navigate to the report and view it.

) SQR User’s Guide 233 . it should only contain a single page. The output file can be viewed at a later time to diagnose any problems.SQR 4. Only the report output file would be required for publication on a Web site. (Use the directory name appropriate for your server. • Runs the SQR program /usr2/reports/myreport.htm) and labeled to indicate "frame version. The program can even be launched using a scheduling utility to automatically run the program and publish it on the Web site at specified times. See the documentation of your particular scheduling software for more details.com/myreport. • Specifies /dev/null as the source of standard input to prevent the program from hanging if it requires input. • Copies the generated report files to the directory /usr2/web/docs to publish it on the Web server. In that case.3 Working with HTML To support older Web browsers that do not support the HTML FRAME construct. Publishing Using an Automated Process The Webmaster can create a program that automates the publishing process.sqr and generates the output files /usr2/reports/myreport. create two separate hypertext links – one pointing to the FRAME file (. • Redirects the standard output to /usr2/reports/myreport. however.h00.out to capture any status messages. If the report was created with HTML procedures. Viewing the Published Report The Web browser can be used to view a report that is published onto a Web site. The program should run the SQR program and copy the output to the appropriate location.myserver. specify a URL address in your Web browser. To do this. for example http://www. The sample Bourne shell program shown below: • Sets the necessary environment variables.htm." and another pointing to the report output file and labeled to indicate "non-frame version". a listing of report pages contained in the FRAME file would not be needed.htm and /usr2/reports/myreport.

export ORACLE_SID ORACLE_HOME=/usr2/oracle7. 3.3 Here is the code: #! /bin/sh # set the appropriate environment values ORACLE_SID=oracle7. One way to allow the user to run an SQR report is by providing a fill-out form. This method consists of the following steps: 1.h00 /usr2/web/docs À Note The environment variables and the file names must be adjusted to fit your particular environment. The CGI script runs the SQR program. Publishing Using a CGI Script In the CGI script method. export ORACLE_HOME SQRDIR=/usr2/sqr/bin. The user enters information on the fill-out form and presses a button to invoke the CGI script.htm /usr2/web/docs cp /usr2/reports/myreport. The CGI script copies the report output file to the standard output.out 2>&1 < /dev/null # copy over the output cp /usr2/reports/myreport. 4. The user views the report. 5. 2. export SQRDIR # invoke the SQR program sqr /usr2/reports/myreport. the user of a Web browser can run an SQR report and view the output. The user of the Web browser navigates to a fill-out form. The following items are required for this process: • The fill-out form • The CGI script • The SQR program 234 SQR User’s Guide .Working with HTML SQR 4.sqr orauser/orapasswd \ -PRINTER:ht -I$SQRDIR \ > /usr2/reports/myreport.

sh will be invoked when the submit button is pressed. For more information on implementing an HTML fill-out form.sh"> <B>Select the Field to Sort By</B><P><DIR> <INPUT TYPE="radio" NAME="rb1" VALUE="cust_num" CHECKED> Number<BR> <INPUT TYPE="radio" NAME="rb1" VALUE="name"> Name<BR> <INPUT TYPE="radio" NAME="rb1" VALUE="city"> City<BR> <P><INPUT TYPE="submit" NAME="run" VALUE="Run Report"></DIR> </FORM> </HTML> The FORM METHOD tag specifies that the CGI script /cgi-bin/myreport. The submit button invokes the CGI script. see HTML documentation available in print or on the Internet. Here is the HTML code: <HTML> <TITLE>View Customer Information</TITLE> <FORM METHOD=POST ACTION="/cgi-bin/myreport. In the INPUT tags. The radio buttons allow the user to specify the sorting criteria. SQR User’s Guide 235 . The URL address of the CGI script must be adjusted to fit your particular environment. as shown in example that follows.SQR 4. The VALUE attribute of the selected radio button is passed via the CGI script to the SQR program. The following HTML code defines a fill-out form with three radio buttons and a submit button. the attribute TYPE="radio" defines a radio button.3 Working with HTML Creating the Fill-Out Form This section explains how to create an HTML fill-out form that allows the user to enter some values and launch the request.

A CGI script can be any executable program. We do not recommend that SQR be called directly as a CGI script—a Perl script.HTM file is not used since it points to the . a shell script.LIS file to the standard output stream.Working with HTML SQR 4. The . Reads the contents of the standard input stream and parses it to obtain the values entered on the fill-out form. this step is not required. Identifies the output as being in HTML format by outputting the string "Content-type: text/html" along with an extra empty line to the standard output stream. 236 SQR User’s Guide . Outputs the generated . Invokes the SQR program. 3. or a C program all provide simpler routines for processing as a CGI script. The CGI script performs the following tasks: 1.LIS file with a relative URL address. 4. 2. The relative address does not tell the Web browser where to find the . We also recommend that you make provisions within your SQR program to output an error message. Values entered by the user on the fill-out form are passed to the SQR program via the CGI script and the command line.3 The fill-out form will look like this: Creating the CGI Script The CGI script is launched when a user makes a request from a fill-out form. see the HTML documentation available in print or on the Internet. If the fill-out form has no input fields.LIS file. For more information on implementing a CGI script.

out echo "</PRE></BODY></HTML>" fi # remove temp files rm /tmp/myreport$$."‘ # invoke the SQR program sqr7 /usr2/reports/myreport.. the script redirects the standard input from /dev/null to prevent the program from hanging if the program requires any input. The value is passed to the SQR program on the command line.*rb1=.*. The report file /usr2/reports/myreport.3 Working with HTML The following Bourne shell is an example of a CGI script. s. export ORACLE_SID ORACLE_HOME=/usr2/oracle7. The script runs the SQR program.&.. SQR User’s Guide 237 .out 2>&1 < /dev/null if [ $? -eq 0 ].sqr is used and the file /tmp/myreport$$.lis -I$SQRDIR "$SORTBY" \ > /tmp/myreport$$. then # display the output cat /tmp/myreport$$. Next.sqr orauser/orapasswd \ -PRINTER:ht -f/tmp/myreport$$.out to capture any status messages. display the error echo "<HTML><BODY><PRE>" echo "FAILED TO RUN SQR PROGRAM" cat /tmp/myreport$$. it outputs the string "Content-type: text/html" along with an extra empty line to the standard output stream to identify the text as being HTML format.. export ORACLE_HOME SQRDIR=/usr2/sqr/bin.* This script first sets the necessary environment variables. #! /bin/sh # set the appropriate environment values ORACLE_SID=oracle7.SQR 4. In addition. export SQRDIR # identify the output as being HTML format echo "Content-type: text/html" echo "" # get values from fill-out form using the POST method read TEMPSTR SORTBY=‘echo $TEMPSTR | sed "s. The script retrieves the value of the selected radio button into the variable SORTBY.lis is generated. It also redirects the standard output to /tmp/myreport$$. The $$ is the process ID of the program and is used as a unique identifier to prevent any multiuser problems.lis else # error ocurred.

Passing Arguments to the SQR Program The SQR program must be modified to accept values entered by the user on the fill-out form. It has been modified to use the SORT BY value passed from the CGI script.+1. • Modifying an SQR program with the argument TYPE=HT of the DECLARE-PRINTER command or USE-PRINTER-TYPE HT will also cause it to produce HTML output.30) do html_td(’’) city (.1) do html_th(’’) print ’City’ (. 238 SQR User’s Guide .16) do html_td(’’) state (. The code shown below is the procedure main from file ex28b.+1. The modified lines are shown in bold. The $sortby variable is obtained from the command line with an INPUT command and used as dynamic variables in the ORDER BY clause.sqr. If an error occurs it outputs the status message file instead to allow the user to view the status messages.32) do html_th(’’) print ’State’ (.49) begin-select do html_tr(’’) do html_td(’’) name (. it deletes any temporary files. begin-procedure main input $sortby ’Sort by’ type=char do html_on do html_table(’’) do html_tr(’’) do html_th(’’) print ’Name’ (3.1.5) next-listing no-advance need=1 let #grand_total = #grand_total + &tot from customers order by [$sortby] end-select Summary • Running an existing SQR program with the -PRINTER:EH or -PRINTER:HT command-line flag will cause the program to produce HTML output.Working with HTML SQR 4. Finally.3 The script then copies the generated report file to the standard output stream.

run the SQR program and copy the output file to the Web server. use a CGI script and a fill-out form.inc in your SQR program and call the procedure html_on. • To generate customized HTML output. use a shell script or a scheduling utility.inc. • To publish an SQR report on a Web server.htm) and report output file(s) (myreport. • To allow users to request an SQR report.3 Working with HTML • An SQR program run that produces HTML output will create a FRAME file (myreport. • A fill-out form allows users to request an SQR program and specify values such as sorting criteria. • To automate the publishing process. SQR User’s Guide 239 . These procedures are contained in a file called html. include the file html.h00. • To utilize these HTML procedures. • The command PRINT-IMAGE and the HTML procedure <IMG> provide support for GIF and JPEG images. use HTML procedures. myreport_00.SQR 4.htm). • A CGI script invokes the SQR program and passes values entered in the fill-out form to it.

.

AFTER-TOC.29 Tables of Contents This chapter describes how to create Tables of Contents for your reports. you may also utilize the TOC argument of the DECLARE-REPORT command. (The default setting is 4. TOC-ENTRY places an entry into the Table of Contents. and AFTER-PAGE.) INDENTATION specifies the number of spaces that each level will be indented by. The FOR-REPORTS argument allows you to specify the reports within the SQR program which will use this Table of Contents. AFTER-TOC specifies a procedure to be executed after the Table of Contents is generated. the procedure does not execute. DECLARE-TOC defines a Table of Contents and its attributes. If no Table of Contents is generated. . DOT-LEADER specifies whether or not a dot leader will precede the page number. In the simplest form. If no Table of Contents is generated.) DECLARE-TOC also supports procedures frequently used for setup and initialization purposes: BEFORE-TOC. you may specify a Table of Contents name. end-setup After the DECLARE-TOC command. this is accomplished through the use of two SQR commands: DECLARE-TOC and TOC-ENTRY. The DECLARE-TOC command must be issued in your program’s SETUP section similar to the following example: begin-setup declare-toc toc_name for-reports = (all) dot-leader = yes indentation = 2 end-declare . . (The default setting is NO and the DOT-LEADER is suppressed in all HTML output except when -BURST:T with -PRINTER:HT are also specified. When generating multiple reports and Tables of Contents from one SQR program. (Use (all) if you want all the reports to use one Table of Contents. BEFORE-TOC specifies a procedure to be executed before the Table of Contents is generated. SQR User’s Guide 241 . BEFORE-PAGE. the procedure does not execute.) Specifying individual report names is only necessary when you are generating multiple reports with different TOCs from one program.

But.3 BEFORE-PAGE specifies a procedure to be executed at the start of every page. AFTER-PAGE specifies a procedure to be executed at the end of each page. you may also wish to generate ouput files for printing reports on paper.sqr to use the DECLARE-TOC and TOC-ENTRY commands. include code similar to the following in the SETUP section of your program: begin-setup declare-report toc = toc_name end-declare . 242 SQR User’s Guide . “Working with HTML. . you may use the FOR-REPORTS argument of the DECLARE-TOC command to identify the reports to which the DECLARE-TOC applies. run the modified version of ex7a. Legal text includes text literals.LIS file (or use -PRINTER:WP on Windows). (If this argument is not specified. And the Table of Contents features work here as well. The Table of Contents ouput will contain the traditional dot leaders and necessary page numbers relating to a hardcopy report.” we modified ex7a. and columns. Under HTML. the Table of Contents file is a hyper-linked point of navigation for the online report. variables. you must include the FORTOCS argument in your DECLARE-TOC statements or the TOC argument in your DECLARE-REPORT statements. Alternatively.Tables of Contents SQR 4. . To test this. we generated HTML output from the modified program using the -PRINTER:EH and PRINTER:HT command-line flags. To specify the name of the Table of Contents applicable to a given report using the TOC argument of the DECLARE-REPORT command. If you wish to include levels in your Table of Contents.) If you are writing programs which generate multiple reports. end-setup In Chapter 28. you have some options to choose from. As previously mentioned. TOC-ENTRY places an entry into the Table of Contents and takes the mandatory argument TEXT which specifies the text to be placed in the Table of Contents. However. the previous level’s value will be used.sqr program from Chapter 28 and print it from an . Then. Your program may have multiple DECLARE-TOC statements and multiple DECLARE-REPORT statements. use the LEVEL argument which specifies the level at which to place the text. you can use the TOC argument of the DECLARE-REPORT command to specify the name of the Table of Contents you want the report to use.

25) toc-entry text = &name level = 1 Program continues on the following page.1) end-procedure begin-procedure main begin-select print ’Customer Info’ () print ’-’ (+1.1. The BEFORE-PAGE and AFTER-TOC arguments of the DECLARE-TOC command are used to print simple messages here.62) Fill name (+1. The dot leader is turned ON. SQR User’s Guide 243 .SQR 4.1. The program identifies the Table of Contents with the specific name cust_toc.3 Tables of Contents The following program is based on cust.sqr which is located in the SAMPLE (or SAMPLEW) directory. One Table of Contents level is set using the TOCENTRY command’s LEVEL=1 argument.1) end-procedure begin-procedure before_page position (+1.1) print ’Before Page’ () bold position (+1.1) print ’After TOC’ () bold position (+1. Indentation is set to 3. Table of Contents Sample Program #1 begin-setup declare-toc cust_toc for-reports=(all) dot-leader=yes indentation=3 after-toc=after_toc before-page=before_page end-declare end-setup begin-program do main end-program begin-procedure after_toc position (+1.

" Table of Contents Sample Program #2 begin-setup declare-report cust end-declare declare-toc cust_toc for-reports=(cust) dot-leader=yes indentation=3 after-toc=after_toc before-page=before_page end-declare declare-variable integer #num_toc integer #num_page end-declare end-setup Program continues on the following page.1. the Table of Contents to which the particular heading or footing section applies. The FOR-TOCS argument of the BEGIN-HEADING and BEGINFOOTING commands allows you to specify. It is similar to the previous program but declares two Table of Contents levels. The Table of Contents heading of this program prints "Table of Contents" and the page number.16) state (.1) Edit ’DD-MON-YYYY’ page-number (1.Tables of Contents SQR 4. The Table of Contents footing prints "Company Confidential. 244 SQR User’s Guide . The page numbers in the Table of Contents print as roman numerals.30) city (+1. by name.69) ’Page ’ end-heading The following program is also based on cust.15) edit (xxx)bxxx-xxxx position (+2.sqr.2) phone (+1. if your program is generating multiple reports with multiple Tables of Contents. This program also creates Table of Contents specific headings and footings.1.1) from customers order by name end-select end-procedure ! main begin-heading 3 print $current-date (1.17.3 Table of Contents Sample Program #1 (continued) cust_num (. you may apply unique or common headings and footings to reports and Tables of Contents.35. So.

1) do orders(&cust_num) position (+2.order_num b.3 Tables of Contents Table of Contents Sample Program #2 (continued) begin-program use-report cust do main end-program begin-procedure after_toc position (+1.SQR 4.1) print ’Before Page’ () bold position (+1.1) end-procedure begin-procedure main begin-select print ’Customer Info’ () print ’-’ (+1.17.20) toc-entry text = &description level=2 Program continues on the following page.62) Fill name (+1.10) print ’-------------’ (+1.1.25) toc-entry text = &name level = 1 cust_num (.30) city (+1.1.1.15) edit (xxx)bxxx-xxxx position (+2.1) print ’After TOC’ () bold position (+1.10.+1. SQR User’s Guide 245 .1) from customers order by name end-select end-procedure ! main begin-procedure orders (#cust_num) let #any = 0 begin-select if not #any print ’Orders Booked’ (+2.35.1.2) phone (+1.20) Edit ’DD-MON-YYYY’ description (.10) let #any = 1 end-if b.product_code order_date (+1.1) end-procedure begin-procedure before_page position (+1.16) state (.

order_num = b.product_code = c.3 Table of Contents Sample Program #2 (continued) c.quantity (.+1.0) center print $current-date (1.$$0.cust_num = #cust_num order by b. products c where a.order_num.99 from orders a.1) Edit ’DD-MON-YYYY’ end-footing begin-heading 3 for-tocs=(cust_toc) print ’Table of Contents’ (1.1.product_code end-select end-procedure ! orders begin-footing 3 for-tocs=(cust_toc) print ’Company Confidential’ (1.69) ’Page ’ end-heading 246 SQR User’s Guide .13) Edit $$$$.69) print $page () end-heading begin-heading 3 print $current-date (1.order_num and b.Tables of Contents SQR 4. b.price * b. ordlines b.1) Edit ’DD-MON-YYYY’ page-number (1.product_code and a.1) bold center let $page = roman(#page-count) print ’Page ’ (1.

SQR 4. • You may output multiple Tables of Contents and multiple reports from the same program..3 Tables of Contents Two Level Table of Contents HTML File Output with PRINTER:EH Summary • Use the DECLARE-TOC and TOC-ENTRY commands to create Tables of Contents for your reports. Use the TOC argument of the DECLARE-REPORT command or the FOR-REPORTS argument of the DECLARE-TOC command to specify which TOC goes with which report • You may create headings and footings for specified Tables of Contents using the FOR-TOC argument to the BEGIN-HEADING and BEGINFOOTING commands. SQR User’s Guide 247 .

52 with HAVING clause. 244 FOR-REPORTS option with. 130 BEGIN-SELECT. 169 #INCLUDE. 135 BEGIN-PROCEDURE. 49 BEGIN-SELECT. 176 ASK. 216 T. 153 $sqr-program. 86.Index ! ! (comment character). 7 command-line. 216 Bursting. 120 B bar codes. 9. 205 BATCH-MODE argument. 202 argument passing. 121. 190 #INCLUDE. 201 arrays. 120 $username. 190 #IF. 112 BOLD option with PRINT. 5. 137 ON-ERROR option with. 105 argument files. 189 #ELSE. 5. 189 #IFDEF. 189 #page-count. 20 BEGIN-SQL. 215 S. 139 bind variables. 19–43 breaks. 168 #DEFINE. 112 bmp-file. 169 #IF. 215 $ $current-date. 201 creating file from reports. nesting. 56. 63 performance issues. 201 BEGIN-FOOTING. 244 FOR-REPORTS option with. 11 BEGIN-PROGRAM. 215 P.SQT files. 120 $sqr-locale. 123–30 arguments SQR User’s Guide 249 . 204 used with ASK or INPUT. 29 $sql-error. 135 BEGIN-HEADING. 86. . 190. 86. 169 #ENDIF. 169. 100 multiple. 49 ORDER BY clause with. 201 # #DEBUG. 189 #IFNDEF. 107 BOTTOM-MARGIN option. 1 BEGIN-SELECT. 169. 120 . 189 A ALTER-LOCALE. 92 batch mode. 189. 23 -BURST{xx}. 116 bitmaps. 47 break logic. 153 ALTER-PRINTER. 152.

195 DECLARE-REPORT. 119 Demand Paging. 47 DECLARE-PRINTER. 75 dynamic SQL. 84 defining page width with. 45 Enhanced HTML. 111 DECLARE-PRINTER. 31 END-PROCEDURE. 75. 144 datetostr function. 55–67 D DATA-ARRAY option. 215 DML (Data Manipulation Language) 137–140 document markers. 142 converting from strings. 146 ELSE. 15 columnar data. 142 dates. 6 END-IF. 99 DECLARE-IMAGE. 71. 11 END-SETUP. 75. 195 FOR-REPORTS option with. 108 CGI script. 193. 105 charts. 11 end-program. 199 DDL (Data Definition Language). 1 END-SELECT. 47 MAX-LINES option with. 229 column variables. 241 DELETE. 91 DOCUMENT section. 142 datenow function.Index SQR 4. 234. 80 END-FOOTING. 2 counters. 95–103 CODE-PRINTER qualifier. 111 CODE-PRINTER qualifier. 88 DECLARE-LAYOUT. printing. 145 converting to strings. 106. 195 DECLARE-TOC. 91 document section. 3 END-PROGRAM. 189–91 compiling SQR programs performance issues. 201 comments.3 C CENTER option. 69 command line using reserved characters on. 59 cross-tabular reports. 47 ORIENTATION option with. 142. 168 debugging SQR programs. 31 ENCODE. 141 comparing. 145 formats. 47 PAPER-SIZE option with. 236 character grid. 47 setting margins with. 193. 46. 100 DATA-ARRAY-ROW-COUNT argument. 204 using special characters. 167 declarations. 100 DATA-ARRAY-COLUMN-COUNT argument. 203 command-line arguments. 45 DECLARE-CHART TITLE option with. 148 dates. 100 database inserts. 7 compiling. 115. 46. 71 MAX-COLUMNS option with. 71 CREATE-ARRAY. 116–19 dynamic variables. 142 datediff function. 6 END-HEADING. 201 command-line flags. 118 E edit masks case sensitivity. 137 date arithmetic. 209 250 SQR User’s Guide . 142 date variables. 195 TYPE option with. 142 DB2. 186 connectivity. 137–40 -DEBUG flag. 194. 3. 241 PRINTER-TYPE option with. 142. 148 dateadd function.

12 Informix. 199 initcap function. 83 K -KEEP command-line flag. 86. 227 LOAD-LOOKUP. 195. 227 G GIF format. 75–77 FOR-REPORTS option. 227 indentation. 219. 112 EVALUATE. 105–9 footing. 7 exporting data. 219. 173 loops. 113. 12 H HAVING clause with BEGIN-SELECT. 225 highlighting with HTML. 30. 5.3 Index eps-file. 6 form letters. 129 performance issues. 128 FONT option. 219. 87. 112 HTML. 225 HORZ-LINE option. 235 flags. 146. 153 LOOKUP. 2 floor function. 79–81 external files. 85 hpgl-file. 227 global variables. 47 LET use of functions in. 86 graphics. 190 INPUT. 172 JPEG format. 128 J joins. 201 INSERT. 151–56 switching. 157–66 F -F command-line flag. 137 I IF.SQR 4. 121 INPUT. 31 SQR User’s Guide 251 . 194 L LaserJet printers. 207–39 hypertext links. 164 LET. 80 LEVEL keyword. 23 lists with HTML. 84 fill-out form. 226 hyphens. 86. 219. 172 local procedures. 119. 139 interoperability. 51 IF. 196 FILL option. 7 LEFT-MARGIN option. 86 fonts. 199 Ingres. 5. 6 headings with HTML. 112 LAST-PAGE. 31 images with HTML. 135 FOR-REPORTS option with DECLARE-PRINTER. 130 heading. 60 exclamation mark. 124 GRAPHIC. 124 local variables. 162 INPUT. 123 locales. 195 functions.

120. 119. 86 procedures. 29 NO-ADVANCE option. 200 ORDER BY clause. 111 -PRINTER:{xx} EH. print. 100 DATA-ARRAY-ROW-COUNT argument with. 112. 128 MS-DOS. 21 with BOLD. 171 PIE-SEGMENT-PERCENT-DISPLAY qualifier. 112 PRINT-IMAGE. 227 SOURCE option with. 95. 71 -NOLIS command-line flag. 3. 20 ORIENTATION option. 200 report body. 86 PostScript printers. 108–9 PRINT-CHART. 2 in Windows. 10 Q P queries. 19–43 limitations. 1. 2 252 SQR User’s Guide . 86 POSITION. 205 multiple reports. 124 PROGRAM section. 10. 139 Oracle. 50 page breaks with ON-BREAK. 12. 203 performance issues. 47 ON-BREAK option with. 196 O ON-BREAK. 194 PRINTER-DEINIT. 100 TYPE option with. 5 reserved characters with HTML. 112 PRINT-CHART DATA-ARRAY option with. 123–30. 91.Index SQR 4. 111 PRINTER-TYPE option. 181 report arguments file on command line. 100 DATA-ARRAY-COLUMN-COUNT argument with. 30 R recursive procedures. 86 TYPE option with. 118 ORDER BY clause with BEGIN-SELECT. 11. 91 position. 194. 228 passing command-line arguments. 151 NEED argument. 41 ON-ERROR option. 131–35 performance issues. 29. 3. 115. 46. 193. 100 SUB-TITLE argument with. 189 running SQR programs in UNIX. 38 paragraph formatting with HTML. 111 printer-independent reports. 111–13 PRINTER-INIT. 84 FILL option with. 112 PRINT. 49–53 mod function. 214 reserved variables.3 M mailing labels. 69 master/detail reports. 185 N national language support. 195 PRINT-IMAGE. 86. 124 -RS command-line flag. 219. 214 -PRINTER:xx command-line flag. 107 WRAP option with. 103 POINT-SIZE option. 189 -RT command-line flag. nesting of. 12 FILL option with. 7. 100 PRINT-DIRECT. 87. 85. 209 HT.

190 performance issues. 167 text positioning. 88. 196 SPF Viewer. 47 tuning issues. 152 SQRW. 158–61 SQR Execute.INI. 166 V variables. 45–48. 165 ufunc on Windows NT. 122 SUB-TITLE argument. 121. 200 SYMBOL-SET argument. 205 upper function. 200 SQR calling from another application. 99 TOC-ENTRY. 163. 162. 167 tab-delimited file. 158 SQR API. 79 SQL dynamic. 165 UFUNC.3 Index run-time arguments. 86. 31 UNIX. 164 STRING. 166 with Windows NT. 134 SKIPLINES argument. 91 variables in SQL.COM.SQR 4. 193. 194. 186 SQR Portable Format. 195 S script files. See SPF file format SQR Print. 189–91. 119–20 SQL statements and SQR performance. 166 userfuncs. 118 SETUP section. 119 SELECT paragraph. 205 VMS SUBMITSQR. 2 spreadsheets. 171 SQLBase. 15 common error with. 169 defining. 161 underscores. 115 SQL and substitution variables. 115–16 VMS. 241 tables with HTML. 190 with multiple reports. 194 SQR Viewer. 29. 205 SELECT paragraph. xiii temporary database tables performance issues. 202 T -T command-line flag. 142 substitution variables. 79 Tables of Contents. 2 STATIC keyword. 205 SQR User’s Guide 253 . 71 SKIPLINES argument. 100 SYBASE. 30 for positioning. 241 TOP-MARGIN option. 195 user functions with Windows 95. 22 SOURCE option. 80 strtodate function. 88. 194 SPF file format. 120. 87 SPF file format. 171 TYPE option. 116 USE-PRINTER-TYPE. 175 SQL error checking. 120–22 SQL cursor status performance issues. 29. 75 in documents. 69. 111 U ufunc on Windows 95. 176 testing SQR programs. 194 SQR. 100. 12. 219 Technical Support. exporting to.C. 105 TITLE option. 11.

166 WRAP option. 108–9 254 SQR User’s Guide .3 W Windows 95 user functions with.Index SQR 4. 166 Windows NT user functions with.

Sign up to vote on this title
UsefulNot useful