Structured Query Report Writer is a programming language that combines the power of SQL queries, the sophistication of procedural logic, and the freedom of the multiple-platform development. It works equally well on client and server side, on different OS platforms, and covers nearly all-relational databases. Such as, Oracle, Sysbase, MS SQL Server, DB2, SQLBase, Informix, Ingres, Red Brick, Rdb and AllBase. Ownership of SQR has passed through a long series of companies. In 2007 ,it was acquired by Oracle Corp. PeopleSoft, which was also acquired by Oracle, purchased rights to the SQR source code and maintained its own version of SQR.    

What we can do with an sqr ?
With SQR we can do the following 1. Reports 2. Background sql process 3. Interfaces (file handling) . 


SQR we can extract data from and load data into the


Process complex file structures . Print sophisticated reports with dynamic breaks at multiple levels . 


interfaces between different systems.

Generate Form letters with business charts, graphs and images.


SQR, from Oracle Corp., is a powerful and flexible programming language for accessing and manipulating data to create custom reports. SQR components include Sqr Server, Sqr viewer, Sqr Print, Sqr Execute, and Sqr Workbench for windows. (Brio Technology). SQR Execute enables you to run previously compiled SQR programs. SQR Print enables you to configure reports for most printers. SQR will be stored on File Server not on the DB. All SQR commands and functions are platform-transparent and require no changes when SQR programs are moved across platforms.


To create an SQR program :

Open a text editor and enter the code in the sample program . 

SQR programs usually have a file extension of .sqr.

To run the Sqr programs :

you must create a sample database . 

To do so, run the loadall.sqr program. 

If SQR is installed on

Windows, you can run loadall.sqr by double -clicking the Loadall icon. If your system does not display this icon, run loadall.sqr from the SAMPLEW directory of SQR for PeopleSoft Hrms90\bin\sqr\mss\

RUNNING AN SQR PROGRAM :We can able to run an SQR program in 3 ways. Namely, 1. Through SQRW workbench , 2. Through Command line , 3. Through Process scheduler .


This SQR Dialog box will be appear in WINDOWS, when we run an sqr program through SQR workbench .  Here , ´Report name´ is the name of our SQR program. Plz note that , we have to enter the fully qualified path before the program name . 

´ Data source ´ is the Name of the Data base which Will be used in our sqr program . ´Username ´ is the your User Access ID . ´ Password ´ Your password to access the database . ´Report arguments ´ are the SQR command line flags and arguments   


-Oc:\hrms90\sqr\eg.log ! to get log file, with name 'eg.log' -Fc:\hrms90\sqr\example.lis ! to get output file, means .lisfile (generally it is created with pgm filename only) .

-ic:\hrms90\sqr\Example.lis ! to overrite the .lis filename with our desired name . -ziv ! to get output direcltly, means it shows(views) the output when we execute .


- Printer:PD -EH_Pdf ! To generate Adobe PDF files as output .

RUNNING THROUGH CMD LINE :When executing an SQR program from the operating system command line, you need to enter 

The name of the SQR engine (SQRW in Windows, SQR in UNIX, etc.) Your program name . The database connectivity string . SQR command line flags . Application-specific arguments . Example of an SQR program executing in cmd line :C:\HRMS90\bin\sqr\MSS\BINW\sqrw.exe C:\HRMS90\sqr\a.sqr HRMS90/sa/sa -Oc:\hrms90\sqr\eg.log -Fc:\hrms90\sqr\example.lis -ziv

SQR PROGRAM STRUCTURE :In SQR there are 5 sections available . 1. Setup Section BEGIN-SETUP {setup commands}... END-SETUP 2. Heading Section BEGIN-HEADING {heading_lines} {heading commands}... END-HEADING 3. Footing Section BEGIN-FOOTING {footing_lines} {footing commands}... END-FOOTING

4. Program Section BEGIN-PROGRAM {commands}... END-PROGRAM 5. Procedure Section BEGIN-PROCEDURE {procedure_name} {procedure commands}... END-PROCEDURE 


1. Setup section :The Setup section describes overall characteristics of the report. This section is optional but, if included, must be placed at the beginning of the program. The Setup section is processed during the program compilation stage before actual program execution. 2. Heading section :Commands in this section are executed every time SQR generates a page . When an SQR program generates multiple reports, we can have more than 1 heading section, however, there can be only 1 heading for each report . 3. Footing section :The structure of footing section is similar to the heading section . But the commands in this are executed at end of every page .   

4. Program section : SQR program may include a number of different sections, but the only required one is the Program Section .  Note: In earlier SQR versions the Program Section was called the ¶Report Section·. 5. Procedure section : An SQR program may include 1 or more SQR procedures .  Procedures allow us to split our program into several logical pieces , which makes the program easy to understand and maintain .  Procedures can global or local . By default, all procedures are global , all variables and selected columns from a global procedure can be referenced in other procedures .  To make procedure local , we have to declare using local keyword . All procedures with parameters are considered as local only .

ENTERING INTO SQR LANGUAGE :SQR Data Elements :Each SQR data element begins with a special character that denotes the type of data element .

Columns :Columns are the fields that are defined in the database. The ampersand character (&) begins a database column or expression name.

Variables :Variables are the storage places for text or numbers that you define and manipulate. Variables begin with special characters: $ begins a text or date variable. # begins a numeric variable. % begins a list variable. @ begins a variable name for a marker location. Marker locations identify positions to begin printing in a BEGINDOCUMENT paragraph .

Predefined SQR variables :SQR reserves a number of variables with special names. These variables are not declared in the program, but they can be used in the program logic. There are nearly 30 pre-defined variable exists ,such as 


#current-line -- denotes the current line number within the current page. #current-column -- the current column number on the page. #page-count -- the current page number. $current-date -- the current date and time on the local machine. and etc.,

Literals :Literals are nothing but the text or numeric constants . A single quote begins and ends a text literal . For example: ¶Hello· Numerals 0ï9 begin numeric literals . For example, -543.21. 


Like string variables, date variable names are prefixed with a dollar sign ($) but, unlike string variables, date variables must be explicitly declared with the help of the Declare-Variable cmd . Declare-Variable Date $Mydate End-Declare


End-Setup LIST VARIABLES :- List variables contain ordered collections of SQR variables . These variables are not nested i.e, you cannot include one list variable within another. 

List variables cannot be passed as parameters to local functions . Denoted with the percent symbol (%). Create list variables with the LET command . For example: Let %list1 = list (num_var1|str_var1, num_var2|str_var2,...)


There are four arithmetic commands Add, Subtract, Multiply, Divide .

These work with 2 numeric fields, (a source field and a target field) perform the proper arithmetic operation, and store the result in the target field. Here ,the source field can be a variable, a column, or a literal; and the target field can be only a variable; Examples :Add #Empl_Sal To #Total_By_Dept Subtract 1 From #Employee_Count Multiply &Rate_Increase Times #Total Round 2 Divide #No_Of_Emps Into #Avg_Sal Round 2 On-Error=Zero

Let command :  

Syntax : Let dst_var = expression Assigns the value of an expression to a string, numeric, or date variable. A single Let command may be capable of replacing a number of data manipulation and logic commands. Expressions in the Let command can be combinations of operands, operators, and functions. Example :let #answer = #float_no * #decimal_no / #integer_no Syntax : Move source_fld to dest_fld [ edit_mask ] The Move command is more versatile than the let commands. In addition to moving data from one field to another, it can also perform data conversions and data editing using special edit masks. Example :move 1234567.89 to #value move #value to $value 999,999,999.99 Here it is converting a number to string using an edit mask .

Move command : 


Display and Show :There are no fancy step-through debuggers to de-bug an sqr program . Our main weapons are the two SQR commands: Show and Display . We can use these commands anywhere in your program except the Setup section. Both the Show and Display commands display the specified texts and variables on the screen and also write the same information into the program log file.

!Using the Show command to display selected columns Show 'Select Started' Begin-Select A.Emplid A.Name Show 'Selected Emplid = &A.Emplid ' Name= ' &A.Name From PS_PERSONAL_DATA Where Name Like 'Abr%' End-Select  The Display command is somewhat similar to the Show command, but it has less power: you cannot display multiple fields in one Display command .  For the same above example , if we use Display we need to use four display commands .

Print : 

Puts data on the page at a specified position. We need to specify the position and length of each output field with the help of three parameters (X, Y, Z). X signifies the line position of the page; Y, the column number; Z, the number of positions allocated for the field. Syntax and Examle :Begin-Select Count(*) &EE_Count Print 'Employee count = ¶ (1,1) Print &EE_Count End-Select ( ,+1) From Employment_Data Where Hire_Dt < Sysdate 

In above example we are print the selected count value by using print command. This is called ´explicit printing ´.  

We can also able to print a value of a selected column without using the Print command by placing a position parameter immediately after the column name. The printing will be performed at the moment of selection. This method of printing is called ´ implicit printing ´ . Begin-Program Do Get_Employees End-Program !***************************** Begin-Procedure Get_Employees Begin-Select Emplid (+1,1) !Implicit Printing Move &Emplid to $Emplid Name ( ,+2) City ( ,+2) State ( ,+2) From Personal_Data Where State = 'NY' End-Select End-Procedure


The PRINT command has the following format commands : BOLD causes the string or number to print in bold type. eg :- print &name (1, 20) bold BOX draws a one-line deep graphical box around the printed data. eg :- print ·Happy Birthday !!· (1,1) box CENTER centers the field on a line. The position qualifier for column is ignored . eg :- print ·Quarterly Sales· (1) center FILL fills the page with the specified character or string as indicated by the print position and length. eg :- print ·*· (1,1,79) fill ! Fill line with *·s UNDERLINE prints the specified data with underlined characters. eg :- print &name (+1, 45) underline EDIT causes each field to be edited before it is printed. Edit has the following syntax: Edit edit_format eg :- print #total (7,55,0) edit $999,999.99     


In business reporting, when the value of a column is changed (that is, when a break occurs), it is common to do some special processing. We may need to skip lines, print a value only if changed, execute a special procedure before or after the break, print subtotals , etc,. Print :- is the default qualifier of on-break When using the Print qualifier with on-break option we need to specify when the break field should (or should not) be printed . Always , The break field will be printed for each detail group. Never , The break field will not be printed. Change , The break field will be printed only when its value is changed. Change/top-page , The break field will be printed when its value is changed and only at the top of each new page. 

Example :Begin-program Do List_Employees End-program Begin-Procedure List_Employees !******************************* Begin-Select B.Company (,1,7) On-Break Print=Change/Top-Page Skiplines=1 B.Paygroup (,+2,8) A.Emplid (,+2,8) A.Name (,+2,20) B.Annual_Rt (,+2,12) edit $,$$$,$$$.00 From Personal_Data A, Job B Where A.Emplid=B.Emplid And B.Effdt=(Select Max(D.Effdt) From Job D Where D.Effdt<=Sysdate And D.Emplid=B.Emplid ) End-Select End-Procedure

In SQR there are 3 Paragraphs available . Namely , 1. Select Paragraph Begin-Select/End-Select 2. SQL Paragraph Begin-SQL/End-Sql 3. Document Paragraph Begin-Document/End-Document 

The SQR Select paragraph is used to retrieve data from your database . It is very similar to SQL Select stmt . The Select paragraph starts with the Begin-Select statement , followed by a list of all columns to be selected from the database as well as the table names and the selection criteria. The End-Select command is coded at the end of the Select paragraph. 

Here is an example: Begin-Select Emplid Name City State Do Print_Row From ----------------You can insert SQR commands in the Select paragraph. PS_PERSONAL_DATA Where Name like 'A%' End-Select In our example, the Do command invokes the ¶Print_Row· procedure for each selected row.

when a column value is selected from a database, SQR automatically creates a ´column variable´ for that column. The name of the column variable is the column name prefixed with an ampersand (&). Note :- The Column variables are read-only variables. You can not change column variable values or assign them new values .

SQL paragraph :o

The sql statements other than sql select are handled in this SQL paragraph. We use this paragraph to load data into the DB or to update certain records in the DB . The Sql paragraph can be used in Procedure section, Program Section, Setup Section. The Sql paragraph starts with Begin-sql and ends with End-sql commands .



The following example shows how to use the SQL Paragraph in the Procedure section: Begin-Procedure Update_Delete
!****************************** ********************

Begin-SQL On-Error =Db_Error Update PS_PERSONAL_DATA Set POSTAL = $New_Zip Where POSTAL = $Old_Zip ; Delete from PS_TEMP_EMPL End-SQL End-Procedure
!***************************************************** Multiple SQL statements in one SQL paragraph are separated by a semicolon.

Begin-Procedure Db_Error Show 'SQL Error occured in Update_Delete proc¶ End-Procedure


SQR Document paragraph allows to put information onto a report pages same as word processor. A document paragraph enables you to write free-form text to create form letters, invoices, and so on. This is useful when creating form letters . You can reference database columns, SQR variables, and document markers within a document. Syntax :Begin-Document position --------End-Document

‡ Use spaces (not tabs) to indent text or field. ‡ Use .b to indicate an entire blank line.


Now away days XMLP is a wonderful reporting tool. Creating a report using XMLP is many times easier, faster than SQRs. But , Is XMLP a complete replacement to SQRs? Ans :- No . why because XMLP is not designed to work with multiple data sets and can not handle such a scenario where conditional logic has to be executed on multiple data sets . Both XMLP and SQRs have their own strengths and why can't we continue to use SQRs for requirements that are easier to code and better handled by that tool? For me, the most prudent (best) approach will be to have a mix of both tools and choose the right tool for the right requirement.