SQR

What is SQR?
• Structured Query Report Writer (SQR) is a programming language that combines the power of Structured Query Language (SQL) queries, the sophistication of procedural logic, and the freedom of multiple-platform development.1

Program Structure
• The basic structure of a SQR program consists of five sections: o Program (or Report) o Setup o Heading o Footing o Procedures Rules for Entering Commands: o All SQR commands are case insensitive. o Command names and arguments are separated by at least one space, tab, or carriage return character. o Most commands may consist of multiple lines, but each new command must begin on a new line. o Except where explicitly noted otherwise, you can break a line in any position between delimiters or words except within a quoted string. o You can optionally use a hyphen (-) at the end of a line to indicate the following line is a continuation. o An exclamation point (!) begins a single-line comment that extends to the end of the line. Each comment line must begin with an exclamation point. If you need to display an exclamation point or single quote in your report, type it twice to indicate it is text.

1

Landres, G. and Landres, V. 1999. SQR in PeopleSoft and Other Applications. Greenwich: Manning Publications.

Page 1

Program File Header block and Program Modification History block o Must be placed at the beginning of each program. o Program naming conventions  First two characters (XX) represent the scope prefix  Second two characters (YY) represent the Product/Module qualifier  Fifth character (S) represents this as an SQR program (.sqr). Use an “I” to represent SQR include files (.sqc).  Sixth through eighth characters are sequential numbering
!******************************************************************** ! XXYYSnnn.sqr: <short description of the program> * !******************************************************************** ! * ! Description: <Long Description or narrative of the purpose of * ! the program> * ! * ! Input Parms: <run control panel name> <short description> * ! <input file name> <short description> * ! * ! Output Parms: <output file name> - <short description> * ! * ! Tables: <PS_TABLENAME> <DML actions performed on table> * ! * ! Notes: None * ! * !******************************************************************** ! Modification History * ! * ! ProjectRef# Date Who Description * ! ---------- ---------------------------------------------* ! XXXXXXXXXX MM/DD/YYYY <euid> Original Program Creation * !********************************************************************

Must Have: PeopleSoft begins each SQR program by setting SQL platform-specific environments. #include ‘setenv.sqc’ !Set environment

The setenv.sqc file uses #define commands to define substitution variables that identify things that are specific to your database platform, operating system and default printer type. • Begin-Setup
!*********************************************************************** ! Begin-Setup * !*********************************************************************** #include 'setup32.sqc' ! Initialize Printer and Page Variables #include 'useprntr.sqc' ! Initialize Printer

Page 2

o The Setup section is optional. If used it contains commands that describe general report characteristics such as page size in lines and columns, whether form feeds are to be used, and printer initializations. o The Setup section is preprocessed and is automatically interpreted before the program begins execution. o PeopleSoft has standardized the Setup section using SQC files references by the #include command. Examples o setup31.sqc Portrait mode o setup32.sqc Landscape mode o setup06.sqc Extract or interface programs that do not print reports Note: These #include statements must appear before the Begin-Heading section o If customization of the Setup section is required (rather than using a #include of one of the standard setup .sqc files), the following statement must be included in order to handle some environmental settings that are database platform-specific: #include ‘setupdb.sqc’ o Some of the valid commands for the Setup section include: ASK Prompts the user for substitution variable BEGIN-SQL Begins a SQL paragraph CREATE-ARRAY Creates an array of fields to store and process data DECLARE-CHART Defines the attributes of a chart DECLARE-IMAGE Declares the type, size, and source of an image DECLARE-LAYOUT Defines the attributes of a report layout DECLARE-PRINTER Overrides the printer defaults DECLARE-PROCEDURE Defines specific event procedures DECLARE-REPORT Defines reports and their attributes DECLARE-VARIABLE Allows user to explicitly declare a variable type DECLARE-TOC Defines Table of Contents and its attributes LOAD-LOOKUP Loads columns into an internal array

Page 3

o To understand an SQR program, it will help to see how SQR views the page.

The locations are referenced in the commands that use them (for example Print) using (Row Position, Column Position, Length of Item) • Begin-Program
!*********************************************************************** ! Begin-Program * !*********************************************************************** begin-program do Initialize-Processing ! Initialize Procedure do Process-Main ! Main Processing Procedure do Finalize-Processing ! Finalization Procedure end-program

Page 4

o The Program section determines where SQR will begin and end execution of your report. PeopleSoft uses this section to control the flow of processing by calling procedures using the Do command, thereby utilizing modular programming. o Begin-Program executes after the Setup section. o This section is required! • Begin-Heading
!*********************************************************************** ! Begin-Heading * !*********************************************************************** begin-heading # #include 'stdhdg01.sqc' ! Standard Heading Definitions <Print column headings> end-heading

o The Heading section usually contains Print commands that are processed in the heading portion of a page. The headings are printed at the top of each page after the body of the page has been filled. o The # is the total number of lines that define the heading portion of the page. o PeopleSoft delivers several xxHdg##.sqc files, one of which is usually referenced by a #include, followed by any report-specific headings. o You must code whatever column headings are relevant to the particular report. • Begin-Footing
!*********************************************************************** ! Begin-Footing * !*********************************************************************** begin-footing # #include 'reset.sqc' ! Reset Printer Procedure end-footing

o The Footing section usually contains Print commands that are processed in the footing portion of a page. The footing is printed after the body and heading of the page. o The # is the total number of lines that defines the footing portion of the page. o The Footing section is a good place to put any confidentiality statements required by the university. o PeopleSoft delivers a simple footing section in reset.sqc that places the “End of Report” text at the bottom of the last page of the report.

Page 5

Complex forms can be designed with the inclusion of graphic commands. SQR requires that column names be flush with the left margin and any SQR commands be indented. Delete)  Document The Begin-Document paragraph allows you to mix background text with data retrieved from the database and user defined variables. the embedded SQR commands will not be executed. line them up as in this example. Update. o Procedure names must be unique. SQR commands cannot directly reference column names. The paragraph mimics rudimentary word processing. they can only reference the &Colname or &Synonym variable created by the begin-SELECT. SQR column variables . They are populated from the database by the begin-SELECT paragraph. Page 6 .  Select The Begin-Select paragraph is the heart of the SQR program. begin-SELECT [DISTINCT][Loops=#][ON-ERROR=procedurename] COLUMN_NAME ! normally one per line [SQR commands] ! must be indented FROM TABLE/VIEW [WHERE…] [Order by …] end-SELECT      If the Select statement is not successful or returns 0 rows.• Begin-Procedure !*********************************************************************** ! Procedure: Procedure_Name * ! Description: Description of the procedure goes here. If more than ! one line is required. Code all column and table names in uppercase. * !*********************************************************************** begin-procedure procedure_name [paragraphs] [commands] end-procedure procedure_name * o A procedure is a list of commands and/or paragraphs that are processed when referenced by a corresponding Do command. o Procedures can contain regular SQL commands as well as three special kinds of paragraphs  SQL The Begin-SQL paragraph allows you to execute any non-select SQL statements (Insert.&Colname – are read only.

+2) end-procedure Get-Student-Info Processing Sequence SQR divides it’s processing into two passes through the source program. (Note: Load-Lookup commands can be placed in any section of the SQR program.sqc) are inserted into the program source.sqc source files is checked. If two database columns of the same name are SELECTed in two or more begin-SELECT paragraphs.STUDENT_ID (+1. • The begin-setup section is processed. • All #commands are evaluated (For example: #IF/#End-If). end-SELECT print &A. Page 7 .STUDENT_ID B.ini) • Optimization of the SQL data access path is determined by RDBMS. • Work buffers are allocated by SQR (pssqr. • The #define text substitution variables in the program source are replaced with their values (For example: {MyValue} is replaced by the value set in #define MyValue. First Pass • All #include external source files (. including allocation and population of memory arrays created by the Load-Lookup and Array commands. • Syntax of SQR source program and . they must be given different synonyms to avoid ambiguity during SQR’s parsing stage.DESCR &Course_Name FROM PS_PSU_STUDENT_TBL A. PS_PSU_COURSE_TBL C WHERE ……. however.+2) print &Course_Name (.1) print &Customer_Name (.DESCR &Customer_Name C.SQR automatically provides a column variable: &Colname.. PS_PSU_CUST_TBL B. it will only be executed at compile time if it is placed in the setup section). An example of synonyms: begin-procedure Get-Student-Info begin-SELECT A.

Processes data for the body section. Processes begin-footing section c. Body. Processes begin-heading section 4. commits pending SQL transactions and terminates program. SQR calculates the body section’s working page size by subtracting lines reserved by the begin-heading and beginfooting sections from Page-Size declared in the begin-setup section.Second Pass • In the second pass. If the length coordinate is zero (or omitted). the actual length of the literal or user-defined variable is used Page 8 . The placement of information is controlled by a set of position coordinates. and Footing area of the page buffer  Line  Column  Length o Two ways to specify position coordinates  Fixed places information in absolute grid positions within the appropriate buffer area  Relative uses a signed number to place information forward or backward a specified number of lines or columns relative to the current cursor position o Position coordinates can be numeric literals or user-defined SQR variables o If the line or column coordinate is zero (or omitted). the actual execution of the program source occurs starting at begin-program and stopping at end-program. Returns back to step 2. • Position Coordinates o The Print command uses three coordinates to place information relative to the Heading. Processes begin-heading section b. Writes entire page buffer to the output device and then erases the page buffer 6. the current position is used. Edit masks and formatting options may also be used to control the appearance of the data. If page overflow occurs or a New-Page command is encountered in the code: a. Then based on the number of available lines. Closes any open files. Initializes variables 2. Writes page buffer to the output buffer d. SQR: 1. Processes begin-footing section 5. Printing in SQR The Print command is used in SQR to place and format information in the page buffer. above 3.

SQR implies that if print coordinates are present.+2.[length]]]) Example: begin-SELECT A. you can use a variety of formatting options. Syntax: begin-SELECT COLUMN1 [&synonym] COLUMN2 … FROM … end-SELECT ([line][. or a literal. It cannot be used to print SQR variables or literals.Name print $Report-Title print ‘PeopleSoft’ ([line][. Some of these options can be used in combination with others and some are mutually exclusive. Implicit printing only works with database columns in a begin-SELECT paragraph.NAME (+1.[column][.[column][. Syntax: Example: print {variable | literal } print ‘Student Name’ print &A.[length]]]) ([line][.+5. See the following chart for formatting compatibility: Page 9 . 1.15) FROM PS_PERSONAL_DATA A end-SELECT Format Options With the Print command.11) (.[length]]]) (1. a userdefined variable.30) (+1. This is true whether you are performing an explicit or implicit print.30) A.• Explicit Print Command Use an explicit Print command to print a column variable (&Colname).[column][. An explicit print is the only way to print SQR variables or literals.1.PHONE ( . it should print the value from that column in the position indicated.10) () Center • Implicit Printing You can implicitly print the value from the database column by placing print coordinates to the right of the column name (or synonym).

There are several types of edit:  Numeric  Text  Date Page 10 . Syntax: print {variable | literal} (position) Bold Bold Example: Box print ‘Course Description’ (0. PeopleSoft routinely uses this option to center text in the standard headings. the column value of the position coordinate is ignored. or conformity to your business standards. This option has no effect for line printers.1. Syntax: Example: print {variable | literal} print $subTotalLine (position) (+2. Syntax: Example: print {String_var | literal} print ‘PeopleSoft’ (position) () Center Center Edit The Edit option allows you to edit each field before it is printed for improved appearance.0) Box Box Here is a sample output for the coding example above: Total for Course 1001 Center on 01/12/1996 is: 10 Use the Center option to position the information on a line.30) Box draws a one-line deep graphical box around the printed data. When the Center option is used.+2. consistency.Bold Bold Box Center Edit Fill Shade Underline Wrap Box Center Edit Fill Shade Underline Wrap Bold Bold causes the information to be printed in bold type.

99 123.99 100 $ 1 0 0 . 0 0 ) $$$9.99PS -100 ( 1 0 0 . 5 6 9.999. and fills to the left of the decimal point with spaces. Syntax: print {variable | literal} (position) Edit {mask} Numeric Edit Masks  The 9 mask is used to print numbers.Each of these edit types has several format masks.56 1 .999. 4 6 9.ini and can be changed using the SQR Alter-Locale function. the smaller of the two is used.999. 0 0 $$. If you use a single dollar sign.456 1 2 3 .999. Any other characters in the edit mask are printed as literals. If you use two or more dollar signs. it is printed in a fixed position.99PF -10 ( $ 1 0 . * *  The 0 mask if added to the front of a 9 mask to left fill with leading zeros. 0 0 9.999.99 100 1 0 0 .$$9.99PS -10 ( $ 1 0 .99 1234.67 * * * * * .99 -16 .99 12345. Mask Value Result $9. It is better to leave the length coordinate blank and let the edit mask determine the length. it is printed as a floating currency symbol. The characters X. B. 2 3 4 . 0 0 9. Mask Value Result 099999 100 0 0 0 1 0 0 099999 123456 1 2 3 4 5 6 The $ mask is used to print numbers with a leading currency symbol. 0 0 )   Text Edit Masks Text edit masks allow you to format string data.99 100 $ 1 0 0 . and ~ have special meaning. 0 0 ) 9999.1 6 . When the length component of the position coordinate and the size of the edit mask are in conflict. 0 0 The PS and PF masks may be added to the end of a numeric edit mask to add parenthesis around negative numbers. Mask Value Result 9.99PF -100 ( 1 0 0 . The currently symbol is set by the MONEY-SIGN parameter in pssqr.999. It fills to the right of the decimal point with zeroes. Page 11 . 0 0 ) $$$9. Mask Value Result 9999.

Year of the Japanese Imperial Era. The B mask embeds a space in the corresponding position of the print string. 4-digit year. BC/AD indicator Quarter of year (1. Returns the current year within the Japanese Imperial Era.6 7 8 9 5 6 7 8 9 1 / 2 0 0 0 ) 3 4 5 . Y YYYY. Day of year (1-366). 2. Last 2 digits of year. “S” prefixes BC dates with “-“. Julian day (variation). Week of year (1-53) where week 1 starts with the first day of the year and ends with the seventh day of the year. 4713 BC.6 7 8 9 ) 3 4 5 . SYYYY RR CC or SCC BC AD Q RM WW W DDD DD D DAY DY ER EY J AM PM HH Description Last 3. Returns the name of the Japanese Imperial Era in the appropriate kanji (“Heisei” is the current era). Mask Value Results xxx-xx-xxxx xxx~xx~xxxx xx/~xx/~xxxx (xxx)Bxxx-xxxx ‘(xxx) xxx-xxxx’ 123456789 123-45-6789 12-31-2000 0123456789 0123456789 1 1 1 ( ( 2 2 2 0 0 3 3 / 1 1 4 3 2 2 4 5 . Day of month (1-31).6 7 8 9 Date Edit Masks Character Mask YYY. Sunday is first day of week. the number of days since Jan 1.   The X mask prints the corresponding character from the print string. Name of day. Assumes current century and/or decade.2. Week of the month (1-5) where week 1 starts on the first day of the month and ends with the seventh day of the month.3. YY. Roman numeral month (I-XII: JAN=1). Century: “S” prefixes BC dates with “-“. Meridian indicator. for years in other centuries. Numbers specified with “J” must be integers. Assumes 24-hour clock unless meridian indication Page 12 . Abbreviated name of day. The ‘~‘ (tilde) mask skips the corresponding character from the print string. or 1 digit(s) of year. Japanese Imperial Era.4: JAN-MAR = 1). Day of week (1-7).

and MONTH. December 19. but Day would print Monday. Syntax: Example: print {String_var | literal} print ‘*’ (prints a line of asterisks) (position) (+1.0) Edit 9999 Page 13 . Precise to microseconds. Seconds past midnight (1-86399). Single quotes are required with spaces are included in the edit string. not the corresponding edit mask character. NNNNN. For example. The characters will be repeated as many times as is necessary to fill the entire area defined by the position coordinates. NNNNNN MONTH MON MM MI SS  specified. YYYY’ ‘The cu\rre\nt \mo\nth is: Month’ 12-19-2000 12-19-2000 12-19-2000 12/19/2000 Tuesday.1. For line printers this argument has no effect.HH12 HH24 SSSS N. Name of month. but Mon would print as Jan. shaded graphical box around the printed data.   Case matters in some date formats such as DY. 2000 The current month is: December Fill The Fill option is used to fill an area of the page buffer with a specified set of characters. NN. Fractions of a second. Hour of day (0-23). Hour of day (1-12). MON. Month (01-12: JAN=01). NNN. The ‘\’ (backslash) character may be placed in front of any character to indicate that it should be treated as a literal. DAY. Second (0-59). the mask MON would print JAN. The length component of the position coordinate is required when the Fill option is used. Abbreviated name of month. DAY would print as MONDAY. Mask Value Result MM/DD/YYYY ‘Day. for most hardware and databases. NNNN.1. Syntax: Example: print {variable | literal} print ‘Grand Total is --->:’ print #Grand (position) Shade Shade Shade (+3.124) Fill Fill Shade The Shade option draws a one-line deep. this much accuracy will not be attainable. Minute (0-59). Month DD. however.0) (0.+2.

Page 14 .

The Underline option is not compatible with the Box option. For line printers. Syntax: Example: print {variable | literal} print ‘Start Date’ (position) (0. This process continues up to a specified maximum number of lines.  The On argument scans the print string for the specified “on” characters.  Both Strip and On arguments will accept regular characters plus nondisplay characters whose ASCII values are surrounded by angled brackets (<nn>). when possible. only breaks between two words.+2. Syntax: print {String_var | literal} (position) {length_lit | _var} {lines_lit | _var} Strip={Strip_lit | _var} On={On_lit | _var} Keep-top Page 15 . underscore characters are used to emulate underlining.0) Underline Underline Sample output for the coding example above: Start Date Wrap The Wrap option prints a specified number of characters from a long text field. the entire word will be wrapped to the next line. Each new line of text is aligned directly under the previous line. ASCII code for carriage return is <13>. Once the current line is full. it is removed.Sample output for the coding example above: Grand Total is --->: 1382 Underline The Underline option adds a horizontal line under the printed text.  The Keep-top argument keeps track of the top line so additional information could be printed on the same line as the beginning of the wrapped text. The Wrap option also supports three additional arguments:  The Strip argument scans the print string for the specified “strip” characters. it is replaced with a space. If an “on” character is found. The Wrap option recognizes word boundaries and. If a “strip” character is found. ASCII code for line feed is <8>. If a complete work will not fit on the current line. the remaining text is wrapped to the next line. and a break occurs at that point.

update. The valid SQR data types are: Data Type Text Date Float Decimal Integer Maximum Size/Range of Values 32. The number of rows affected by a DML statement (insert. End of File (EOF) indicator.767 bytes Jan 1. Name of encoding for character data written to files used with the open command. Name of encoding for SQR source files and include files.483. This variable is set to 1 following the execution of a Read statement that results in an EOF exception. an LIS file or a PostScript file). {sqr-encoding-file-output} $sqr-encoding-report-output. {sqr-encoding-file-input} $sqr-encoding-file-output. The numeric return code from the DBMS upon execution of an SQL command. The current date/time stamp on the host machine. {sqr-encoding-report-output} $sqr-encoding-source. 4713 BC to Dec 31. The report generated by SQR (for example. A value that may be passed back to the operating system at the completion of the SQR program. or delete). unless declared as local arguments.647 Initial Value Null Null Zero Zero Zero Example $Name $Today #Average #Salary #Counter SQR provides internal.648 to 2. {sqr-encoding-source} Description The current column position within the page grid.483. The text message returned from the DBMS upon execution of an SQL command. Page 16 . {sqr-encoding-database} $sqr-encoding-file-input.147. This is the absolute line position (not the line number relative to a report area). This value may be altered during execution. Variable #current-column $current-date #current-line #end-file #page-count #return-status #sql-count $sql-error #sql-status $sqr-encoding-console. Variables are global throughout a report.147. Name of encoding for character data written to the log file or console. {sqr-encoding-console} $sqr-encoding-database. Name of encoding for character data read from files used with the open command. reserved variables with values maintained and updated by SQR. The current page number. The current line position within the page grid. 9999 AD Double Precision – Platform dependent Precision (1-38 digits) -2.SQR Variables and Commands SQR variable names can be any length and are not case sensitive. The character data retrieved from and inserted into the database.

when you want to refer to the contents of the substitution variable. or SJIS. $sqr-report reflects the actual name of the file to be used (as specified by the –f flag or NEW-REPORT command). Valid values are VMS. ORACLE Specifies whether SQR recognizes double-byte character strings. The name of the SQR program file. The hardware/operating system type for which SQR was compiled. MVS. A “+” at the end of the name indicates an argument used in the locale has changed. The value may be either YES or NO. ODBC. you simple put the variable name inside brackets. The maximum number of columns as determined by the layout. Page 17 . this variable is automatically updated to reflect the new layout. {sqr-platform} $sqr-program $sqr-ver $username $sqr-report The database type for which SQR was compiled. SYBASE. The name of the current locale being used. The value can be ASCII. Substitution variables may also be created through the use of the ask command as well as certain command line flags.$sqr-database. or UNIX. When a new report is selected. or SQL statement. This variable contains the name of the computer on which SQR is currently executing. The maximum number of lines determined by the layout. Subsequently. database type and date created). at compile time. WINDOWSNT. • User-Defined Variables o Substitution Variables are used to supply all or part of an SQR command. substitution variables are defined at the beginning of your SQR program using a #define statement. while #define statements may be placed anywhere in your SQR program. The name of the default encoding as defined by the ENCODING environment variable when SQR is invoked. operating system. substitution variable must be defined before they can be referenced. The name of the report output file. {sqr-hostname} $sqr-locale #sqr-max-lines #sqr-max-columns #sqr-pid $sqr-platform. The database user name specified on the command line. #sqr-pid is unique for each run of SQR. The process ID of the current SQR process. This variable is useful in creating unique temporary names. JEUC. When a new report is selected. SQR version (including version number. {sqr-dbcs} $sqr-encoding. Normally. Valid values are: DB2. {sqr-encoding} $sqr-hostname. INFORMIX. this variable is automatically updated to reflect the new layout. {sqr-database} $sqr-dbcs.

Syntax: #define sub_var [lit_value] Example: #define ColR 108 … Let #Colr = {ColR} – 2 o Runtime Variables are allocated and manipulated during the execution phase of your SQR program. This value may range from 1 to 38. However. This value must be decimal. If omitted. it will be known in that procedure only. • Declare-Variable Command SQR provides the ability to explicitly typecast program variables via the declarevariable command. Typically. The valid data types for runtime variables are text. specifies the data type of all variables that follow. float. Likewise. date. As with the default-numeric argument. if a variable is declared within a local procedure. the maximum number of digits is 16. By default. Date variables must be declared if they will be used in calculations or complex formatting Syntax: declare-variable [Default-Numeric={Decimal[Digits)] | Float | Integer} [Type Var1A [Var1B][…]] [Type Var2A [Var2B][…]] end-declare Default-Numeric defines the default format for all numeric variables. the maximum number of digits may be specified. If the data type is decimal. When allocated by reference. runtime variables are allocated by reference and are not explicitly declared. and numeric. This applies to all numeric variables not explicitly declared.0. it is known throughout your program). as of SQR version 4. all numeric variables are created as data type float. or text. variables can be explicitly declared and typecast using the declare-variable command in the Setup section. the maximum number of Digits Type Page 18 . The default-numeric option may be used to override this default. runtime variables are initialized by SQR to null for text and dates. integer. all numeric variables will default to float. If no value is specified. This command must be used in the Setup section or as the first statement of a local procedure. a variable is global (i. date.e.. or zero for numbers. When declared in the Setup section. specify the maximum number of digits allowed for decimal numbers.

Syntax: move source_data to target_variable [edit_mask] source_data target_variable edit_mask may be a literal or a variable must be a user-defined variable any valid edit mask Example: move &name to $emplname move &NID to $nid xxx-xx-xxxx o The let command is used to assign the value of a literal or variable.EMPLID let #Avg = (#C1 + #C2 + #C3) / 3 o Benchmark tests show that the move command is more efficient that the let command for assignment statements. • Display and Show Commands o The display and show commands are used to place information into the SQR trace file. will default to 16 digits. This is the same place that SQR writes informational and error Page 19 . Syntax: let user_var = expression Example: let #Stot = 0 let $EmplID = &A. to a user-defined variable. or the results of an expression.digits may range from 1 to 38. operators. and if omitted. and functions. an edit mask may be applied in conjunction with the move statement. Example: declare-variable default-numeric=decimal(8) integer #Qty #LineNbr decimal(12) #Price float #LineItemAvg text $PartNbr date $BackOrderDate end-declare • Assignment Statements o The move command is used to copy data from one storage location to another. Optionally. An expression may be formed as a combination of operands.

For this reason. Syntax: show {variable | literal} [edit_mask] [{var | lit} [edit_mask] …] Example: show ‘The sql error is ‘ #sql-status ‘ – ‘ $sql-error The show command also allows you to specify formatting options for your output. All edit masks that are available with the print command are also available with the show command. The noline option may be added to the end of the display command to prevent SQR from issuing a carriage return after the value is printed. However. unlike the display command. but cannot be used to show the results of expressions. Month dd. Syntax: display {variable | literal} [edit_mask] [noline] Example: ! Write the SQR internal variables #sql-error and #sql-status ! to the SQR trace file display ‘The sql error is’ noline display #sql-status noline display ‘ – ‘ noline display $sql-error o The show command also writes information to the SQR trace file.$$$. The do command causes the flow of the SQR program to branch to the named procedure. each display command writes its output on a separate line. The display command also allows you to specify an edit mask when writing your output.99 • Control Statements o Do The do command is used to call or invoke a procedure. o The display command writes a single value to the SQR trace file.$$9. Example: show ‘Report date: ‘ $AsOfToday Edit ‘Day. By default.messages. All edit masks available to the print command are also available to the display command. The display and show commands can be used to show variables and literals. yyyy’ show ‘Total revenue: ‘ #TotalRev Edit $$$$. The procedure must be located in the same file as the SQR program or in an SQC file that has been linked by a #include statement. display and show commands are frequently used for debugging programs. The code in that procedure is executed and then control is Page 20 . show may be used to write one or more variables or literals with each statement.

>. or. and not. <. If statements may be nested within another if statement.passed back to the next statement following the do command. <. >=. The Boolean operators and. and <= and the Boolean operators and. but each one must have its own matching end-if. and <= in the conditional expression. The value being evaluated is compared to the when condition. >=. <>. an or condition may be simulated by using two Example: o Evaluate Page 21 . An if statement may optionally contain an else block. The SQR commands defined within the else block are executed when the if condition is false. <>. or. all of the statements within that when block are executed. Optionally. SQR recognizes the logical operators =. You may use the operators =. If the condition is true. However. o If Syntax: if condition {Command(s) to execute when condition is true} [else {Command(s) to execute when condition is false}] end-if if $EndOfReport = ‘Y’ print ‘End of Report’ () center end-if The evaluate command is useful for branching to different commands depending on the value of a variable or literal. and not are not allowed in the evaluate statement. the break command may be used to exit from the evaluate construct. >. Conditions may be any simple logical expression. then the when-other block is executed. Syntax: do procedure_name [(parm_list)] parm_list Example: one or more literals or variables (separated by commas) begin-program do Initialize-Processing do Process-Main do Finalize-Processing end-program The if command allows conditional execution of one or more SQR commands. If no when condition is true.

while condition [{Command(s) to execute while the condition is true} [break] . .. therefore the embedded SQR commands might not be executed.] end-while Example: o While Syntax: Page 22 . when condition_n [{Command(s) to execute when condition_n is true} [break]] [when-other {Command(s) to execute when nothing else is true}] end-evaluate evaluate &EmplType when = ‘S’ let $Type = ‘Salaried’ do Count-Salaried break when = ‘E’ when = ‘H’ ! Implied ‘or’ condition let $Type = ‘Hourly’ do Count-Hourly break when = ‘N’ let $Type = ‘Not Applicable’ do Count-NA break when-other ! when no other condition is true do Invalid-Type end-evaluate The while loop is used to process a set of SQR statement for as long as some condition is true. It is the developer’s responsibility to do something within the loop to make the condition true. with no intervening SQR commands. ..or more when conditions. Optionally. the break command (typically in conjunction with an if statement) may be used to exit the while loop. Syntax: evaluate {literal | variable} when condition_1 [{Command(s) to execute when condition_1 is true} [break]] . The condition is always tested first.

o Break o Exit-SELECT Syntax: Example: o Goto o Stop Page 23 . the stop command triggers SQR error 3301 and causes the following message to be added to the SQR trace file: (SQR 3301) Program stopped by user request. . The stop command is an immediate termination of the currently executing SQR program. . Exit-SELECT is used to unconditionally branch to the next statement following the end-SELECT command. The label must be entered on a line by itself. If used by itself. This is considered an abnormal termination by SQR and will trigger a database rollback. It is similar to the break command as used in the while or the evaluate statements. The use of goto is not recommended. left-justified and must end with a colon.Example: while #Count < #TotalCount do More-work if #Errs > 3 ! If error threshold is exceeded break ! Exit the while loop end-if add 1 to #Count end-while The break command may be used in a while or an evaluate command to perform an unconditional branch to the next statement following the end-while or end-evaluate. end-SELECT The Goto command is an unconditional branch to a specified label within the same program section (or procedure). exit-SELECT begin-SELECT EMPLID NAME do Reformat-Name if #Errs > 3 exit-SELECT end-if FROM PS_JOB WHERE .

Using the let command. The result is placed in a text variable specified by the into argument. but the SQR trace file message is suppressed.If accompanied by the quiet option. or expressions by placing the concatenation symbol (two vertical bars) between each one.’ || Fld4 The string command allows you to concatenate together two or more fields using a common delimiter. ‘ || $state || ‘ ‘ || &zip let $CSV = $Fld1 || ‘. starting at a specified position and continuing for a set number of characters. let result_str_var = {StrLit1 | var1 | Expl}||{StrLit2 | var2 | Exp2}[ || …] Syntax: Example: String let $Address = $city || ‘. there are many methods used to extract a portion of one string from another. Expressions are the result of the execution of an SQR string function. Page 24 . the program will be terminated.’ into $CSV !Begin address line !Complete address line !Comma delimited output Syntax: Example: o Extraction As with concatenation. The most common involve the use of the substr function (with the let command) and the unstring command. Substr The substr function allows you to extract one string from another.’ || $Fld2 || ‘. Syntax: Example: stop [quiet] if #Errs > 3 show ‘The maximum number of errors was exceeded.’ stop quiet end-if • String Manipulation and Formatting o Concatenation Let The two most common techniques used to concatenate strings are the let and string commands. variables. string {Str_Lit1 | var1} {Str_Lit2 | _var2} [… {Str_LitN | _varN}] by {StrDelimiter_Lit | _var} into ResultStrVar string &City &State by ‘. ‘ into $Address string $Address &Zip by ‘ ‘ into $Address string $Fld1 $Fld2 $Fld3 $Fld4 by ‘.’ || $Fld3 || ‘. you may concatenate two or more string literals.

‘ ‘) (trim trailing spaces) Page 25 . 1. $Fld3. 1) (find area code delimiter in phone #) The rtrim and ltrim functions remove unwanted characters from the right or left side of a text string. $Fld2. Unstring {Str_Var | _Lit} by {Str_Delimiter_Var | _Lit} into StrVar1 StrVar2 … StrVarN unstring &Phone by ‘/’ into $AC $TheRest unstring $Input by ‘. Syntax: let NumericVar = instr({Source_Str_Lit | _Var | _Exp}. 3) The unstring command divides a string into two or more text variables using a specified delimiter. Syntax: Example: o Instr let NumericVar = length({Str_Lit | _Var | _Exp}) let #Len = length($EmplName) (find the length of the student name) The instr function returns the starting position of one string within another string. {Len_Num_Lit | _Var | _Exp}) let $AC = substr(&Phone. $Fld4 Example: Unstring Syntax: Example: • Miscellaneous o Length The length function returns the length of a string.’ into $Fld1. You may begin your search at any point within the source string by specifying a starting position.Syntax: let StrVar = substr({Str_Var | _Lit | _Exp}. ‘/’. {Start_Pos_Num_Lit | _Var | _Exp}) Example: o Rtrim. {Search_Str_Lit | _Var | _Exp}. Ltrim let #Pos = instr(&Phone. including leading and trailing spaces. {Trim_Str_Lit | _Var | _Exp}) Syntax: Example: Let $Course = rtrim($Course. { Start_Pos _Num_Lit | _Var | _Exp}. let New_Str_Var = {R | L}trim ({Source_Str_Lit | _Var | _Exp}.

‘(xxx) xxx-xxxx’) (format phone number) let $Total = ‘Total Sales: ‘ || edit(#TotalSales. ‘ ‘) (add up to 4 trailing spaces) let $Line = lpad(&OrderLineNbr. edit_mask) let $Phone = edit(&Phone. {Pad_Str_Lit | _Var | _Exp}) Syntax: Example: let $FieldValue = rpad(&CourseRt.Let $Amount = ltrim($Amt. let New_Str_Var = {R | L}pad ({Source_Str_Lit | _Var | _Exp}. or expression (of any data type) and returns a string value. Syntax: Example: let Str_Var = edit({Source_Lit | _Var | _Exp}. 4. Lpad The rpad and lpad functions pad a source string up to a maximum length with a given string (usually spaces). or expression is empty.99’) o Uppercase. ‘$$$. Syntax: Example: uppercase Str_Var lowercase Str_Var uppercase $Course lowercase $Name o To_Char The to_char function converts a numeric literal. or expression into the equivalent character string. Rpad adds to the right side of the source string and lpad adds to the left. variable.$$9. variable. otherwise it returns a false (0). Syntax: Example: o Isnull let Str_Var = to_char({Numeric_Lit | _Var | _Exp) let $Total = to_char(#Counter) The isnull function returns a true value (1) is the specified literal. ‘*’) (trim leading asterisks) o Rpad. 6. {Max_Len_Num_Lit | _Var | Exp}. Page 26 . variable. Lowercase The uppercase and lowercase commands convert string variables to uppercase or lowercase respectively. ‘0’) (add up to 6 leading zeroes) o Edit The edit function applies formatting to a literal. This function is only valid for text or date values. A text field is considered to be empty if it contains a string whose length is zero.

variable. carriage return. Valid date units are ‘year’. o Datenow The datenow function returns the current date from the operating system in SQR date format. ‘day’.e. ASCII codes 0 and 9-13). SQR recognizes date data types and stores their values in a proprietary format. ‘month’. The isnull function is usually used as the conditional test in an if or while command. This function is only valid for text or date values. Syntax: Example: let #Boolean_Var = isnull({Date_or_Text_Lit | _Var | _Exp}) if isnull($InputParameter) show ‘Input parameter was not specified’ end-if o Isblank The isblank function returns a true value (1) is the specified literal. {Num_Lit | _Var | _Exp}) Page 27 . Syntax: Example: let Date_Var = datenow() let $Today = datenow() !Get Today’s Date o Dateadd The dateadd function returns a new date value after a specified number of date units are added to or subtracted from a given date value. Syntax: Example: let #Boolean_Var = isblank({Date_or_Text_Lit | _Var | _Exp}) let #Test = isblank($EmplID) if #Test show ‘EmplID was not specified or is empty’ end-if • Date Manipulation and Conversion As of version 4.0. tab.A date is considered to be empty if it contains null values. The isblank function is usually used as the conditional test in an if or while command. White space is any combination of null. Syntax: let $New_Date = dateadd({Date_Var | _Exp}. ‘quarter’. ‘hour’. and ‘second’. and line feed characters (i. To take advantage of this data type. ‘minute’. or expression is empty or contains only white space. {Date_Unit_Lit | _Var | _Exp}. form feed.. date variables must be explicitly declared using the declare-variable command. ‘week’.

Page 28 .

{Date_Var2 | _Exp2}. Valid date units are ‘year’. Syntax: Example: • let $Date_Var = strtodate({Str_Lit | _Var | _Exp} [. If no edit mask is specified. and ‘second’. and functions. edit_mask]) let $MyBirthDate = strtodate(‘04/08/1961’. ‘day’. o Let The let statement is the most common command used for numeric expressions.ini. $Today. the date format will default to the sqr_db_date_format specified in pssqr. ‘minute’. Syntax: let Num_Var = datediff({Date_Var1 | _Exp1}. Commands. The date edit mask is used to indicate what format the string is in prior to conversion. Syntax: Example: let $Str_Var = datetostr({Date_Var | _Exp} [. ‘week’) (returns number of weeks between Today and EndDate) o Datetostr The datetostr function returns the alphanumeric representation of a date value based on a date edit mask. ‘+’. ‘week’. the date format will default to the sqr_db_date_format specified in pssqr. and ‘/’. commands. {Date_Unit_Lit | _Var | _Exp}) Example: let #Weeks = datediff($EndDate. If no edit mask is specified. Page 29 . Only whole numbers are returned.Example: o Datediff let $EndDate = dateadd(&StartDate. The following are some of the more common numeric expressions. ‘mm/dd/yyyy’) Numeric Expressions. ‘hour’. edit_mask]) let $PPEDate = datetostr($EndDate. ‘-‘. ‘*’. you can program most linear equations using the standard operators.ini. ‘month’. Month dd. yyyy’) o Strtodate The strtodate function returns the SQR date representation of an alphanumeric string. and Functions SQR provides a wide variety of techniques for performing numeric calculations. ‘quarter’. ‘day’. ‘Day. 15) (add 15 days to StartDate) The datediff function returns the difference between two dates based upon a specified date unit type. With the let command.

multiply. {Precision_Lit | _Var | _Exp}) let #basrt2 = round(#basrt. the precision may be from 0 to the maximum size defined for the number.00 let #CostOfUnits = &Units * 75. you may round the result to a specified precision.5 let #AvgLength = (#Fld1 + #Fld2 + #Fld3) / 3 Example: o Add SQR also provides a set of COBOL-like commands for numeric manipulation. 0) Page 30 . the precision may be from 0-15 positions to the right of the decimal point. Otherwise. Syntax: Example: add {Num_Lit1 | _Var1} to Num_Var2 [round = {Precision_Lit | _Var} add 1 to #Index add &UnitAmt to #SalesTotal Round=2 o Round The round function is used with the let command to round a fractional value to a specified decimal precision. Syntax: Example: let Num_Var = round({Num_Lit | _Var | _Exp}. {Position_Lit | _Var | _Exp}) let #AvgLength = trunc(#Units. Syntax: Example: let Num_Var = trunc({Num_Lit | _Var | _Exp}. If the resulting number is floating point. only add is still in common usage. 22) o Trunc The trunc function drops all decimal digits beyond a specified position.Syntax: let Num_Var = {Num_Lit1 | _Var1 | _Exp1} [Operator1 {Num_Lit2 | _Var2 | _Exp2} [Operator2 {Num_Lit3 | _Var3 | _Exp3} […]]] let #NewDays = &LengthDays + 1 let #UnitDiscount = &Units – 25. the precision may be from 0 to the maximum size defined for the number. Optionally. however. Of these commands. These commands include add. If the number is floating point. with a decimal number. with a decimal number. Otherwise. the position may be from 0-15 positions to the right of the decimal point. and divide. the precision may be from 0 to 38 positions to the right of the decimal point. If used with a floating-point number. Otherwise. subtract. with a decimal number. 2) let #trate = round(#trate. the precision may be from 0-15 positions to the right of the decimal point.

PeopleSoft has developed a library of frequently used procedures. SQC files can contain any type of SQR statement. Where you #include the file depends on what type of code the file contains. If a numeric character is found. it will be embedded within the section that the SQC code supports. To reduce development time and ensure consistency. and scanning continues. from a few lines of code to a complete set of procedures. it is #included at the end of the SQR program.o To_Number The to_number function converts a text string to a numeric value. it is converted. operating system. Otherwise. The members of this library are called SQC files. let Num_Var = to_number({Str_Lit | _Var | _Exp}) let #LengthDays = to_number($LengthDays) Syntax: Example: PeopleSoft SQC Files PeopleSoft has developed several conventions to make it easier to manage your SQR environment. The to_number function scans the string from left to right one character at a time. datetime. and paper orientation.sqc Description Defines information that is common to your database platform. However. if a non-numeric character is found the conversion process stops. printer configuration. setup31.sqc (P) Standard setup sections that define the setup32. Some of the most common uses of SQC files include: o Definition of SQR environment variables o Definition of the Setup section o Definition of the standard heading o Definition of the footing section o Data formatting and conversion o Lookup of descriptions and translate values The following SQCs are common to most SQR programs: File Name setenv. and report environment.sqc (L) page layout. by convention.sqc Creates edit masks for conversion of date and time variables from one format to Procedure Name N/A N/A/ Init-DateTime Format-DateTime Page 31 . If the SQC contains one or more complete SQR procedures.

language. and effective date. It also contains procedures to perform the actual conversion of those variables.sqc another.sqc stdhdgtr.sqc curdttim.datemath.sqc Financial file Description Company fshdg02. This SQC produces four variables: $AsOfToday and $AsOfNow. These procedures allow the SQR program to communicate with the Process Monitor and Report Manager inside the PeopleSoft environment. field value.sqc reset. Format-NativeTime Convert-To-DTU-Date Convert-From-DTU-Date Get-Current-DateTime readxlat. Contains the application program interface procedures. the date and time in native database format.sqc stdhdg04.sqc stdhdg03. Converts dates between native database format and DTU format (yyyy-mm-dd) Retrieves the current date and time from the database.sqc stdhdg05.sqc N/A Reset Begin-Footing Define-Prcs-Vars Get-Run-Control-Parms Successful-EOJ Other Heading SQCs HRMS/SA file stdhdg02.sqc stdhdg06.sqc stdapi. in standard report format.sqc Init-Number Format-Number Format-Amt ConvertCurrency Read-Translate-Table stdhdg01. Contain print statements used as part of the PeopleSoft standard heading Contains the reset procedure and the standard footing section.sqc fshdg04.sqc fshdg01.sqc fshdg01.sqc Business Unit As Of Date Pay Period End Check Date Pay Group Additional Variables* $Company $CompanyName $Business_Unit $Business_Unit_Descr $AsOfDate $PayEndDate $AsOfDate $PayGroup $PayGroupName Page 32 . and $ReportDate and $ReportTime. Retrieves the long and short names from the Translate table for a specified field name. Contains generalized routines to initialize currency edit masks and to format numbers.sqc number.

sqc.sqc Business Unit/Ledger Group/Ledger stdhdg07.sqc Company/For The Period stdhdg20.sqc fshdg07. You use procedures to modularize your programs and to make your code reusable. You need to determine the following: • The SQC file name • The procedure name • Input variable(s). By saving commonly used procedures as SQC files.sqc Standard Report (with two title lines) $Business_Unit $Business_Unit_Descr $Ledger_Name $Ledger_Descr $Business_Unit $Business_Unit_Descr $Ledger_Group_Name $Ledger_Group_Descr $Ledger_Name $Ledger_Descr $PayEndDate $DeptID $DeptName $SetID $SetID_Descr $FromDate $ThruDate $CompanyName $CompanyDescr $AsOfDate $CompanyName $CompanyDescr $EmplID $Name $CompanyName $CompanyDescr $FromDate $ThruDate $ReportTitle2 * These variables are in addition to those identified in stdhdg01.sqc fshdg05. if any. Local procedures allow us to create and utilize local variables that are hidden from the rest of your program. you need to do some upfront analysis. these procedures are often defined as local procedures.sqc stdhdg09.sqc stdhdg10. if any Page 33 . In order to use the code in SQC files that contain procedures.sqc stdhdg08.sqc Pay Period End/Cost Center SedID For the Period Company/As Of Date Company/EmplID stdhdg11. To avoid possible conflicts with variable names.sqc fshdg01. you create libraries of functions that may be called from any SQR program.fshdg06.sqc Business Unit/Ledger fshdg06a. and whether they are required or optional • Output variable(s).

A New-Page will automatically occur if page overflow is detected. The text specified in the pre_txt_lit and post_txt_lit are printed immediately before and after the number.COURSE if #CurrentLine > 65 new-page end-if • PAGE-NUMBER This function places the current page number on the page. • Use the output variable(s) created by the procedure. • Include the SQC at the bottom of your program (#include). Using last-page causes SQR to delay printing until the last page has been processed so the number of the last page is known. Page 34 . as This function places the last page number on each in “page N of X”. UNIX filenames are case sensitive and PeopleSoft-delivered SQCs are always in lowercase. SQC filenames should always be entered in lowercase in the #include statement. unless you specify Formfeed=No in the Declare-Layout for this program in the Begin-Setup section. Syntax: Example: new-page begin-select A. Advanced Printing with SQR Page Commands • NEW-PAGE output This function sends the current page buffer to the device and begins a new one. you can implement the SQC using these steps: • Populate any necessary input variable(s). • Perform (Do) the procedure. A form feed character is added to the output file after each New-Page occurs. Syntax: Position Pre_txt_lit Post_txt_lit page-number (position) [pre_txt_lit [post_txt_lit]] Specifies the print position of the page number Specifies a text string to be printed before the page number Specifies a text string to be printed after the page number • LAST-PAGE page.Once you have finished your analysis.

The logical top of page is reset to the position of the cursor following the next-listing command (i. a new page will be started.Syntax: Position Pre_txt_lit Post_txt_lit Example: last-page (position) [pre_txt_lit [post_txt_lit]] Specifies the position for printing the last page number Specifies a text string to be printed before the last page nbr Specifies a text string to be printed after the last page nbr begin-footing 1 page-number (1. Specifies the minimum number of lines needed to begin a new listing or set of detail lines. If the value is less than or equal to 0. next-listing [no-advance] [skiplines = #] [need = #] Suppresses any line movement when no printing has occurred since the previous next-listing or newpage. Causes the specified number of lines to be skipped before setting up the new offset.37) ‘Page ‘ last-page ( ) ‘ of ‘ ‘. the current line becomes line 1 of the report body).’ Column Commands • NEXT-LISTING Next-listing causes a new vertical offset in the page to begin. Negative values will be ignored.’ end-footing !will appear as !’Page 12 of 25. Need can be used to prevent a group of detail lines from being broken across two pages.. This function ends the current set of detail lines and begins another. If this number of lines does not exist. Syntax: no-advance skiplines need Page 35 .e. The default increments the line position even when nothing was printed. then 1 is assumed.

This is useful when printing columns down the page.CITY A.COUNTRY ORDER BY A. ‘ ‘) B. ‘ ‘) – ||’. next-column [at-end = {newline | newpage}] [Goto-Top = num_lit | _var | _col] [Erase-page = num_lit | _var | _col] Takes effect if the current column is the last one defined when next-column is invoked Causes the current line in the next column to be set.COUNTRY=B. PS_COUNTRY_TBL B WHERE A.EMPLID (1.EMPLID end-select • COLUMNS Columns are analogous to defining tab stops. 0) next-listing skiplines=1 need=5 FROM PS_PERSONAL_DATA A. 20.DESCR (4. 1. ‘ ‘) – ||’ ‘||rtrim(&A.ADDRESS1 A.STATE A.POSTAL let $address = rtrim(&A. If at-end is used.ORIG_HIRE_DT (2. 1.NAME (0. Syntax: at-end goto-top erase-page Page 36 . 20.Example: begin-select A. The columns command defines the left-most position of one or more logical columns (or tab stops) within the current page layout. Syntax: columns [int_lit1 | _var1 | _col1 [int_lit2 | _var2 | _col2 […]]] int_lit | _var | _col Example: • NEXT-COLUMN Specifies the left margin position of each column !defines the starting pos for 3 columns columns 1 29 57 This command sets the current position on the page to the next column defined with the columns command. It moves the cursor to the position defined by the first logical column.STATE. Specifies where to begin erasing the page when an at-end=newpage occurs. 0) A. ‘||rtrim(&A.CITY. 10) A. goto-top is ignored. 0) A.POSTAL.

NAME (0. 1.NAME end-select end-procedure Process-Main !prints names and hire dates !across the page !define two columns • Example: Prints columns down the page begin-procedure Process-Main columns 1 45 let #BottomLine = 55 begin-select A. use-column num_lit | _var | _col use-column 3 !move cursor to the 3rd logical column Syntax: Example: • Example: Prints columns across the page begin-procedure Process-Main columns 1 45 begin-select A. +3.• USE-COLUMN This command sets the current position on the page to a specified column defined with the columns command.NAME end-select end-procedure Process-Main Page 37 . 20) A. 0) !define two columns !print names and hire dates !down the page if #current-line >= #BottomLine next-column goto-top=1 at-end=newpage else print ‘ ‘ (+1.ORIG_HIRE_DT (0.ORIG_HIRE_DT (0. 1) end-if FROM PS_PERSONAL_DATA A ORDER BY A. +3. The command use-column 0 turns off column processing.NAME (0. 0) next-column at-end=newline FROM PS_PERSONAL_DATA A ORDER BY A. 1. 20) A.

Graphic • BOX Box draws a box of any size at any location on the page. Specify 0 if no border is desired. There are 720 decipoints per inch. width) horz-line rule-width graphic (4. 62. 1. The top left corner of the box is drawn at the line and column specified. You can specify relative placement with (+). The width is the horizontal size in character columns. width) box depth rule-width shading Line and column Width and depth Rule-width Shading Position coordinates for the upper left hand corner of the graphic. Boxes can be drawn with any size rule and can be shaded or left empty. 10) Horz-line draws a horizontal line from the location specified for the length specified. Example: • HORZ-LINE graphic (4. 1 is very light and 100 is black. The default rule-width (thickness) is 2 decipoints. or numeric variables. depth is the vertical size in lines. 66) horz-line 10 (put line under page heading) graphic (+1. A number between 0 and 100 indicating percentage of gray scale. (-). Page 38 . The bottom right corner is calculated using the width and depth. Horizontal lines are drawn just below the base line. Vertical lines are drawn just below the base line of the line position specified to just below the base line of the line reached by the length specified. 12) horz-line (put line under final total) • VERT-LINE Vert-line draws a vertical line from the location specified for the length specified. as with regular print positions. Syntax: Example: graphic (line. If no shading is specified. column. 160) box 2 5 10 print ‘Outstanding balance due: ‘ (+1. column. Syntax: graphic (line. 5. 0 shading is assumed.

Height_Num_Lit)] [source end-declare Example: = {File_Name_Lit}] begin-setup #include ‘ptset01.e. PDF files only accept JPEG and GIF files. .sqc’ . Different printer types accept different image types. You do not have to declare an image before it can be printed. For example. SPF only accepts BMP files. HPGL.Syntax: Example: graphic (line. EPS. The image file must be one of the supported formats (i. For example. and HPLaserJets only allow HPLG file. The print-image command can be placed in any section of a report except the Setup section. or BMP).5) source = ‘c:\temp\pslogo. Different printer types accept different image types. 54) vert-line Declare-Image The declare-image command is used in the Setup section to define default characteristic for images. column. 27. and HPLaserJets only allow HPLG file. Syntax: declare-image {Image_Name} [type = {Image_Type_Lit}] [image-size = {Width_Num_Lit. 52. . PDF files only accept JPEG and GIF files. GIF. declare-image pslogo type = bmp-file image-size = (40. 54) vert-line (draw lines between columns) graphic (1. Page 39 . The only caveat is that if you don’t use the declare-image to define them. end-setup Print-Image The print-image command is used to print a graphical image. you must supply all three is its attributes as part of the print-image command. SPF only accepts BMP files.. JPEG.bmp’ end-declare . Images can be printed in a report with the print-image command whether or not they are declared in the Setup section. depth) vert-line rule-width graphic (1.

2-decipoint character width is equivalent to 10 characters per inch. Example: a standard 7. SQR supports files of type: EPS-FILE. Example: begin-heading 12 !adjust size to allow for image print-image CompanyLogo (1. or change. to print an image that is 2 inches wide.e. b.1) position (+6) #include ‘stdhdg01. you will use on-break to: • Suppress duplicate values • Produce subtotals • Produce subheadings • Control the flow of your SQR Syntax: print {field} (a.. HPGL-FILE. image-size = The width and height of the image using standard printer coordinates (i. Specifically. columns and lines). GIFFILE. c) on-break {print = change | print = change/top-page | print = always | print = never} before = procedure_name after = procedure_name save = $text_var skiplines = nn level = nn Page 40 . and BMP-FILE. you would specify a width of 20 columns.Syntax: print-image [image_name] (position) [type = {image_type_lit | _var | _col}] [image-size = (width_num_lit | _var | _col.sqc’ … end-heading On-Break Processing On-break is a very powerful SQR feature that will allow you to control what happens when values in a column break. JPEG-FILE. height_num_lit | _var | col)] [source = {file_name_txt_lit | _var | _col}] type = Type of file for the image. source = The path and file name of the image file. Therefore.

• Print = change/top-page Values are repeated after a page break even when they don’t change • Print = always The values are always repeated (whether they change or not) and one or more additional on-break options are executed when the values change • Print = never Values are never printed. Can only be used within a begin-select paragraph. After= is very useful for subtotaling. but one or more additional onbreak options are executed when the values change • Before = Specified procedure to invoke before the value changes. • • On-Break Processing Order Levels also affect the order in which on-break processing occurs. Level = Option specified level of break for report with multiple on-break options. If no rows are selected. When one of the break field changes value. Skiplines = Specifies how many lines to skip when the value changes. • • Save = Indicates a string variable where the previous value of a break field will be stored. will not be processed. The position of the cursor will be moved by the procedure(s) and therefore the relative coordinates may produce inconsistent results. all higher level numbers will be treated as if they broke as well. be prepared to experiment until you get the desired result. If skiplines= is used it should be used on all levels for consistent results. Break= is very useful for subheading. If you use skiplines=. Lowest level is the outermost or most major. If no rows are selected. will not be processed. After = Specified procedure to invoke after the value changes. Note: Do not use relative position coordinates with print statements that include either a before= or after= procedure that also includes print statements. highest level is the innermost or most minor.On-break uses a number of parameters to control printing and program flow: • Print = Option has four possible choices: • Print = change (default) Values for the columns specified in the on-break command are printed only when they change. The sequence of events for a query containing on-break fields is as follows: Page 41 . Can only be used within a begin-select paragraph.

2. Note: In order for your SQR program to make appropriate use of the on-break logic. All save= variables are initialized. This situation requires the SQR program to retrieve subordinate data and can be done via a join. Before= procedures are processed in ascending sequence from the current break level to the highest on-break level number. Lookup Tables A common function within an SQR program is to join tables in order to get the long description of some data code. after= procedures are processed in descending level sequence (highest to lowest). your SQL statement would need to Order by on the same fields on which you are breaking. When a break does occur. 5. After= procedures are processing in descending sequence from the highest level to the level of the current break field (the field triggering the break). For instance. 7. the following happens: 3. 8. You can use lookup tables to save static data in a dynamic structure providing you more efficient data retrieval during the execution of an SQR program. such as Init-Report. However. Only the skiplines= argument for the current level is honored. The new value is printed. Their values will print regardless of whether or not their value changed. Any breaks with the same or higher level numbers are cleared. Page 42 . 4. for large tables with large amounts of data. If skiplines= was specified. Load-lookup This command can be used in any SQR section. Lookup tables are implemented in SQR programs using the load-lookup and lookup commands. in a given table. or by performing a procedure that performs a separate SELECT from within the main SELECT statement. The detail line is printed. It is good practice to place your load-lookup commands in an initialization procedure. a table join can be a slow process. any after= procedures are processed in descending level sequence (highest to lowest). Save= variables are set with the new value. 9. Any before= procedures that have been declared are processed in ascending level sequence (current level to highest) before the first row of the query is processed. After last detail line is printed. you may have a COURSE or DEPT_ID but the corresponding description is in another table. the current line position is advanced.1. There is a more efficient way of retrieving this data in SQR. 6. After the query finishes (at end-select). 10.

only integers 12 digits or less are permitted for the key column. The array name is referenced in the lookup command. The warning message stating the number of duplicate keys found is also suppressed. Keys can be any database-supported expression and can be concatenated columns. Extent The amount to increase the array when it becomes full. the where clause is limited to 512 characters. Where A conditional clause used to select a subset of all the rows in the table. Sort Specifies the sorting method to be used. a value of 100 will be used.Syntax: load-lookup name={lookup_table_name} table={database_table_name} key={key_column_name} return_value={return_column_name} [rows= {initial_row_estimate_int_lit | _var| _col}] [extent= {size_to_grow_by_int_lit | _var | _col}] [where= {where_clause_txt_lit | _var | _col}] [sort= {sort_mode}] [quiet] Name The name of the lookup table. case-sensitive sort • DI Database sorts data. This is optional. or numeric data types. Return_value The name of the column (or expression) that will be returned for each corresponding key. if not specified. if not specified. case-insensitive sort Quiet Suppresses all warning messages generated by the loadlookup command (such as “Loading lookup array …”) when the command executes. which is used for looking up the information. case-sensitive sort • SI SQR sorts data. the selection begins after the word where. Page 43 . Note you can combine several columns into an expression if you need several fields returned for each lookup. Rows The initial size of the lookup table. This is optional. a value of 25 percent of the initial rows value will be used. case-insensitive sort • SC SQR sorts data. Table The name of the table or view in the database. where the key and return_value columns or expressions are stored. If specified. Key The name of the column that will be used as the “key” in the array. Keys can be character. If numeric. When a literal value is used. This is achieved by concatenating columns. The following values are permitted: • DC Database sorts data. date.

or literal. Using a lookup table can be slower because the entire table has to be loaded and sorted for each report run. variable. A variable into which the corresponding value is returned. The key used for the lookup. lookup Int-Rooms &RoomAbbr $RoomName Limitations If the report is small and the number of rows to join is small. lookup {lookup_table_name_lit} {key_lit | _var} {return_value_var} Syntax: lookup_table_name key return_value Example: Specifies the lookup table. a lookup table is NOT the way to go.Example: load-lookup name=Int-Rooms rows=12 table=PSXLATITEM key=FIELDVALUE return_value=XLATLONGNAME where=FIELDNAME=’’CLASSROOM’’’ and (effective dating logic) … XlatLongName Room A Room B Room C Room D Room E Other Given the following rows in PSXLATITEM: Fieldname Fieldvalue CLASSROOM A CLASSROOM B CLASSROOM C CLASSROOM D CLASSROOM E CLASSROOM X The lookup table would look like this: Key Return_value A Room A B Room B C Room C D Room D E Room E X Other Lookup The lookup command searches a lookup table for a key value and returns the corresponding return_value string. which represents Page 44 . This table must be previously loaded with a load-lookup command. It could be a column.

or ID is more than just one column. with some table data. Defines the number of elements in the array (analogous to table rows). there is also no limit to the number of lookup tables that can be defined. The name is referenced in other array commands. Arrays and Graphics Arrays can be defined to store intermediate results or data retrieve from the database. a SELECT paragraph can retrieve data. Arrays can also be used when the subordinate data that is associated with a certain code.some processing overhead. Or perhaps some of the data that needs to be stored in conjunction with a certain data code is calculated and not just pulled from a table. Which one is best? Try it both ways in your SQR program to find out. such as a file. The createarray command can be written in any section of the program. Create-array Creates an array of fields to store and process data. before a program starts to execute). create-array name=array_name size=nn {field=name: type [:occurs] [=init_value_lit]} [{field=name: type [:occurs] [=init_value_lit]} …] Syntax: Name Size Field Names the array. Typically. it is recommended that all arrays be created in the setup section of your program. The only limit to the size of a lookup table is the amount of memory available. These scenarios do not lend themselves to a lookup table so a common array that stores many data items in each row makes more sense. the more subordinate data involved and the more table joins that are done. perhaps there are several data elements. Rather than one data element like NAME associated with ID. Defines each field or column in the array. Except for the amount of memory available. This must be either a hard-coded value or a substitution variable. SQR creates arrays at compile time (i. however. For example. You may even need to integrate information from an external data source. store it in an array. Each field is defined as type: • Number uses the default-numeric type • Char (or Text) character string • Date same as date variable Page 45 . Therefore. abbreviation.e. a summary could be printed followed by the data previously stored in the array.. When the query finishes. and gather statistics all at the same time. the more significant the performance boost can be for SQRs that use lookup tables.

You can also specify an initialization value for each field. Page 46 . they can be repeated occurs times. The maximum number of arrays in a single SQR program is 128. character and date fields are set to null. Each field is set to this value when the array is created or when the clear-array command is executed. If no initialization value is specified. which gives the array an apparent third dimension.• • • Decimal [(p)] Float Integer decimal numbers with an optional precision (p) double precision floating point numbers whole numbers Fields can optionally have a number of occurrences. Example: create-array name=Benefits size=12 field=EmpNum:number field=Name:char field=Coverage:char:3=’Full’ field=Dependants:number:3 That code would produce a virtual array something like this: Note: Subscripts start at 0. that is. The maximum number of fields per array is 200. numeric fields are set to zero.

let $variable_name = array_name. and let commands.{fldocc_lit | _var | _col}]) = expression let $name = Benefits.Value assignment Columns retrieved from the database and SQR variables or literals can be moved into or retrieved from an array using the put. The let command can be used to reference a value in an array.name(5) let Benefits. Let works as described previously.Jane’ put {value1_lit | _var | _col} [{value2_lit | _var | _col} […]] into array_name_lit ({rownbr_lit | _var | _col}) [field1[({fld1_occ_lit | _var | _col})] [field2[({fld2_occ_lit | _var | _col})] […]]] !Data values are: !#j = 5.field([row_nbr_lit | _var | _col} [.{fld1_occ_lit | _var | _col}]) let array_name. &EmpNum=621333. The array must have been created previously using the create-array command.array_field (#I) let var = array_name. Get and put work in the same fashion as the move command.name(9) = ‘Doe. copying that value to a variable. get.field({row_nbr_lit | _var | _col} [. and !$DentalPlan=’E+3’ put &EmpNum &Name ‘Med-A’ $DentalPlan into Benefits(#j) Let syntax: Example: Put syntax: Example: empnum name coverage(0) coverage (1) Get syntax: get value1_var [value2_var […]] from array_name_lit({row_nbr_lit | _var | _col}) [field1{({fld1_occ_lit | _var | _col})] [field2 {({fld2_occ_lit | _var | _col})] […]]] Get # empno $name $medical from Benefits(#j) empnum name coverage(0) Example: Page 47 . It also can be used to copy data to the array from a variable. John’. &Name = ‘Smith.

Common Programming Errors with Arrays o Subscript Value problems: The most common programming error to make when working with arrays is to try accidentally to reference an array element using a subscript value that is outside the range specified by the array. another common error is getting stuck in an endless loop for whatever Page 48 . a warning message is displayed. but easy to diagnose and correct. The exact error reads as follows: (SQR 1500) Array element out of range (25) for array ‘rev_break_down’ on line 165. The array must first be created using the create-array command. Therefore. text fields are reset to null. and SQR continues executing. numeric fields are reset to zero. If no initial value was specified. the result field is unchanged. placing the results into the corresponding field in the array. The four array arithmetic commands perform on one or more source numbers. and date fields are reset to null. This is typically not detected during compile because the reference to the array element often uses a variable as a subscript. clear-array {name=array_name} Syntax: Example: clear-array name=Benefits Additional Array Commands The following four commands perform arithmetic on one or more elements in the array. o Looping problems: Because loops are typically used to load and manipulate arrays.Clear-array The clear-array command resets each field of the named array to the initial value specified for that field in the create-array command. Syntax: array-add {numeric_lit | _var | _col} to array_name (row) [field[(occurs)]] … array-subtract {numeric_lit | _var | _col} from array_name (row) [field[(occurs)]] … array-divide {numeric_lit | _var | _col} into array_name (row) [field[(occurs)]] … array-multiply {numeric_lit | _var | _col} times array_name (row) [field[(occurs)]] … If division by zero is attempted. this particular programming error can be difficult to prevent.

To add a business chart to an SQR report. To help prevent data type errors.). Trying to load an invalid data type in an array element or trying to lead an array element value in a different variable type are two common errors made when working with arrays. These errors are found during compilation and are easily diagnosed. create an array and optionally define default chart characteristics: • Use create-array to allocate an array. These code problems would not result in a specific SQR error but would cause the program to run endlessly because it was stuck in an endless loop. etc. • Optionally. The error for data type mismatching is as follows: Error on line 166: (SQR 3514) PUT and GET variables must match array field types. You can print multiple charts in one program. you can use the special characters in array field names. The special characters used in variable names to designate data type can be sued in the naming of fields in an array like this: create-array name=ClassBreakDown size=25 field=ProjRole$:char field=Count#:number SQR Charts Arrays are used to create graphics in SQR. each of which could have unique chart attributes. Page 49 . Several different chart types are supported from bar graphs to pie charts to xy-scatter plots. referencing the wrong variable in logic to break out of the loop. SQR provides two rather complex commands for creating charts in a report: declare-chart and print-chart. Another common error also related to looping is the mistake of using the wrong variable or counter in the subscript when referencing an array element. there is a basic three-step approach that PeopleSoft outlines in their Developer’s Guides: 1) In the Setup section of your program.reason (not incrementing counters properly. you may use declare-chart to define the basic attributes of a chart. Arrays are used to store the data for charts and are created at compile time (and loaded at run-time). o Data Type issues: Another common programming error is data type conflicts.

Charts used arrays for their data source.2) Put the data into an array. chart_depth_int_lit)] [title = {title_txt_lit}] [sub-title = {subtitle_txt_lit}] [fill = {fill_lit}] [3D-effects = {3d_effects_lit}] [type = {bar_type_lit}] [legend = {legend_lit}] [legend-title = {legend_title_txt_lit}] end-declare Chart-size is optional. • Reference the data for the chart with the data-array argument. Enter none for no title OR enter the text to be used as a title for the chart immediately after the = and enclosed in single quotes. • Load the data into an array. The default values are underlined. Some of the other arguments for the declare-chart command are described in the table below. The attributes that were set in the declare-chart command may be overridden in the program with print-chart command. such as position coordinates and chart size. Enter none for no sub-title OR enter the text to be used as a sub-title Page 50 . see the SQR Language Reference. For a complete listing of all command arguments. • Provide certain print attributes. but must be defined in either the declare-chart or print-chart command. • Use the print-chart command to print the chart. Among the available attributes are the following: Syntax: declare-chart {chart_name_lit} [chart-size = (chart_width_int_lit. The command may only appear in the Setup section of an SQR report. Declare-chart Defines the default attributes of a chart that can be printed in an SQR report. Chart_name is the only required field because the other arguments have predefined default values. 3) Print the chart. Argument chart-size title none Text none Text Valid Values Default value Description The width and depth of the chart specified in SQR position coordinates.

legend legend-title General Notes:  Specifies if there will be a legend displayed for this chart. then it may appear as grayscale. The sub-title is placed just below title. piesegments. Title for the chart legend. Specifies the type of fill that is applied to the shapes (bars. None displays all graph shapes filled with white. then chart is displayed in a “flat” 2D mode.fill grayscale color crosshatch none 3D-effects yes no line pie bar stacked-bar 100%-bar overlapped-bar floating-bar histogram area stacked-area 100%-area xy-scatter-plot high-low-close yes no none text type sub-title for the chart immediately after the = and enclosed in single quotes. etc. Page 51 . Specifies the type of chart. 3D-effects will give your chart depth if set to yes. Crosshatch uses patters to fill the shapes representing each data set. Grayscale varies the density of black dots. If the current printer does not support color.) that represent the data loaded into the chart. If no. Color sends color instructions to the current printer. All declare-chart attributes may be overridden by the printchart command.

  Print-chart Declare-chart arguments specified more than once will produce a warning. If the data-array has a greater number of rows. print-chart expects multiple rows of data with at least two columns. the first column character and the others numeric. This must be the name of an array defined with the create-array command. General Notes:  Print-chart expects the data-array to be organized in a particular way. Data-array-column-count Specifies the number of columns to be used from the data-array. position coordinates may be relative. the cursor is repositioned to this position. For a bar chart. Prints a chart at the designated position within the report buffer. print-chart expects the data array to be composed of two columns and multiple rows of data. Arguments can be specified in any order. As with other print commands. SQR uses the first instance of the argument and ignores all subsequent references. After execution of the print-chart command. If the data-array has a greater number of columns. for pie charts. each numeric column would represent another rows of data with at least two Page 52 . Data-array Specifies the name of the array containing the data to be plotted. Position Specifies the position of the upper-left corner of the chart. Data-array-row-count Specifies the number of rows or sets of data to be used from the data-array. only data-array-column-count will be included in the chart. print-chart [chart_name_lit] (position) data-array = array_name data-array-row-count = {x_num_lit | _var | _col} [chart-size = {chart_width_int_lit. only data-array-row-count will be included in the chart. This name is not necessary if you specify the chart-size and all other pertinent attributes in the printchart command. For example. the first column should be character and the second column should be numeric. chart_depth_int_lit)] Syntax: Chart_name Specifies the name of the chart from the declare-chart command.

there are five other parameters. and data-array-column-labels. this is HP LaserJet model 3 and higher) will render chart output. Therefore. data-array-column-count. If you attempt to print a chart to a LaserJet printer that does not support HPGL. Page 53 . the chart will be centered within the specified region. data-array-row-count. each numeric column would represent another Y-axis value. Chart commands used to send output to a line printer will be ignored. The position of the chart is described using the first parameter. All the attributes defined for declare-chart are valid for the print-chart command. it simply means that SQR has accommodated the shape of the region in order to provide the best possible appearing chart.    columns. and the dimensions will be scaled to accommodate the region. Only PostScript printers or HP printers that support Hewlett Packard HPGL (generally. In cases where the display area is not well suited to the chart display. the first column character and the others numeric. do not be alarmed if the chart does not fit exactly inside the box you have specified. Additionally. The data that support the chart are defined in the additional attributes: data-array. the HPGL command output will likely become part of your output. leaving one or more lines of meaningless data across your report. Print-chart will fill the area defined by chart-size as much as possible while maintaining a suitable ratio of height to width.

Sign up to vote on this title
UsefulNot useful