Anda di halaman 1dari 53

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 de elopment!

Program Structure
"he basic structure of a SQR program consists of fi e sections# o o o o o $rogram (or Report) Setup %eading &ooting $rocedures

Rules for 'ntering (ommands# o )ll SQR commands are case insensiti e! o (ommand names and arguments are separated by at least one space, tab, or carriage return character! o *ost commands may consist of multiple lines, but each new command must begin on a new line! o '+cept where e+plicitly noted otherwise, you can brea, a line in any position between delimiters or words e+cept within a quoted string! o -ou can optionally use a hyphen (-) at the end of a line to indicate the following line is a continuation! o )n e+clamation point (.) begins a single-line comment that e+tends to the end of the line! 'ach comment line must begin with an e+clamation point! /f you need to display an e+clamation point or single quote in your report, type it twice to indicate it is te+t!

Page 1

Page 2

$rogram &ile %eader bloc, and $rogram *odification %istory bloc, o *ust be placed at the beginning of each program! o $rogram naming con entions &irst two characters (00) represent the scope prefi+ Second two characters (--) represent the $roduct1*odule qualifier &ifth character (S) represents this as an SQR program (!sqr)! 2se an 3/4 to represent SQR include files (!sqc)! Si+th 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 arms: <run contro! pane! name> <short description> * ! <input fi!e name> <short description> * ! * ! "utput arms: <output fi!e name> # <short description> * ! * ! $a%!es: < S&$'(L)*'+)> <D+L actions performed on ta%!e> * ! * ! *otes: *one * ! * !******************************************************************** ! +odification ,istor* ! * ! ro.ect/ef0 Date 1ho Description * ! ########## ########## ### ##################################* ! XXXXXXXXXX ++2DD2YYYY <euid> "rigina! rogram 3reation * !********************************************************************

*ust %a e# $eopleSoft begins each SQR program by setting SQL platform-specific en ironments! #include setenv.sqc !Set environment

"he seten !sqc file uses 5define commands to define substitution ariables that identify things that are specific to your database platform, operating system and default printer type!

Page 3

6egin-Setup !*********************************************************************** ! Begin-Setup * !*********************************************************************** #include 'setup32.sqc' ! Initiali e !rinter and !age "aria#les #include 'useprntr.sqc' ! Initiali e !rinter o o o "he Setup section is optional! /f used it contains commands that describe general report characteristics such as page si7e in lines and columns, whether form feeds are to be used, and printer initiali7ations! "he Setup section is preprocessed and is automatically interpreted before the program begins e+ecution! $eopleSoft has standardi7ed the Setup section using SQ( files references by the 5include command! '+amples o setup3$.sqc $ortrait mode o setup32.sqc Landscape mode o setup%&.sqc '+tract or interface programs that do not print reports 8ote# "hese 5include statements must appear before the 6egin-%eading section o /f customi7ation of the Setup section is required (rather than using a 5include of one of the standard setup !sqc files), the following statement must be included in order to handle some en ironmental settings that are database platform-specific# #include setupd#.sqc o o o o o o o o o o o o o Some of the alid commands for the Setup section include# )S9 $rompts the user for substitution ariable 6':/8-SQL 6egins a SQL paragraph (R')"'-)RR)- (reates an array of fields to store and process data ;'(L)R'-(%)R" ;efines the attributes of a chart ;'(L)R'-/*):' ;eclares the type, si7e, and source of an image ;'(L)R'-L)-<2" ;efines the attributes of a report layout ;'(L)R'-$R/8"'R < errides the printer defaults ;'(L)R'-$R<(';2R' ;efines specific e ent procedures ;'(L)R'-R'$<R" ;efines reports and their attributes ;'(L)R'-=)R/)6L' )llows user to e+plicitly declare a ariable type ;'(L)R'-"<( ;efines "able of (ontents and its attributes L<);-L<<92$ Loads columns into an internal array

Page 4

"o understand an SQR program, it will help to see how SQR iews the page!

"he locations are referenced in the commands that use them (for e+ample $rint) using (Row $osition, (olumn $osition, Length of /tem)

Page 5

6egin-$rogram !*********************************************************************** ! Begin-!rogram * !*********************************************************************** #egin-program do Initiali e-!rocessing ! Initiali e !rocedure do !rocess-'ain ! 'ain !rocessing !rocedure do (inali e-!rocessing ! (inali ation !rocedure end-program o o o "he $rogram section determines where SQR will begin and end e+ecution of your report! $eopleSoft uses this section to control the flow of processing by calling procedures using the Do command, thereby utili7ing modular programming! 6egin-$rogram e+ecutes after the Setup section! "his section is required.

6egin-%eading !*********************************************************************** ! Begin-)eading * !*********************************************************************** #egin-*eading # #include 'std*dg%$.sqc' ! Standard )eading +e,initions -!rint column *eadings. end-*eading o o o o "he %eading section usually contains Print commands that are processed in the heading portion of a page! "he headings are printed at the top of each page after the body of the page has been filled! "he 5 is the total number of lines that define the heading portion of the page! $eopleSoft deli ers se eral ++%dg55!sqc files, one of which is usually referenced by a 5include, followed by any report-specific headings! -ou must code whate er column headings are rele ant to the particular report!

6egin-&ooting !*********************************************************************** ! Begin-(ooting * !*********************************************************************** #egin-,ooting # #include 'reset.sqc' ! /eset !rinter !rocedure end-,ooting o o o o "he &ooting section usually contains Print commands that are processed in the footing portion of a page! "he footing is printed after the body and heading of the page! "he 5 is the total number of lines that defines the footing portion of the page! "he &ooting section is a good place to put any confidentiality statements required by the uni ersity! $eopleSoft deli ers a simple footing section in reset.sqc that places the 3'nd of Report4 te+t at the bottom of the last page of the report!

Page 6

6egin-$rocedure !*********************************************************************** ! !rocedure0 !rocedure12ame * ! +escription0 +escription o, t*e procedure goes *ere. I, more t*an * ! one line is required3 line t*em up as in t*is e4ample. * !*********************************************************************** #egin-procedure procedure_name 5paragrap*s6 5commands6 end-procedure procedure_name o o o ) procedure is a list of commands and1or paragraphs that are processed when referenced by a corresponding Do command! $rocedure names must be unique! $rocedures can contain regular SQL commands as well as three special ,inds of paragraphs SQL "he 6egin-SQL paragraph allows you to e+ecute any non-select SQL statements (/nsert, 2pdate, ;elete) ;ocument "he 6egin-;ocument paragraph allows you to mi+ bac,ground te+t with data retrie ed from the database and user defined ariables! (omple+ forms can be designed with the inclusion of graphic commands! "he paragraph mimics rudimentary word processing! Select "he 6egin-Select paragraph is the heart of the SQR program! begin-S'L'(" >;/S"/8("?>Loops@5?><8-'RR<R@procedurename? COLUMN_NAME . normally one per line >SQR commands? . must be indented &R<* TABLE/VIEW >W%'R'A? ><rder by A? end-S'L'(" /f the Select statement is not successful or returns B rows, the embedded SQR commands will not be e+ecuted! (ode all column and table names in uppercase! SQR requires that column names be flush with the left margin and any SQR commands be indented! SQR column ariables - C(olname D are read only! "hey are populated from the database by the begin-S'L'(" paragraph! SQR commands cannot directly reference column names, they can only reference the C(olname or CSynonym ariable created by the beginS'L'("!

Page 7

SQR automatically pro ides a column ariable# C(olname! /f two database columns of the same name are S'L'("ed in two or more begin-S'L'(" paragraphs, they must be gi en different synonyms to a oid ambiguity during SQREs parsing stage! )n e+ample of synonyms# begin-procedure :et-Student-/nfo begin-S'L'(" )!S"2;'8"F/; 6!;'S(R C(ustomerF8ame (!;'S(R C(ourseF8ame &R<* $SF$S2FS"2;'8"F"6L ), $SF$S2F(2S"F"6L 6, $SF$S2F(<2RS'F"6L ( W%'R' AA!! end-S'L'(" print C)!S"2;'8"F/; print C(ustomerF8ame print C(ourseF8ame end-procedure :et-Student-/nfo (GH,H) (,GI) (,GI)

Page 8

Processing Sequence
SQR goes o er the source program in two stages! "he first stage is the compile stage, during which )ll e+ternal source files are inserted into the program source file! )ll compiler directi es are e aluated! (ompiler directi es start with 5 and are processed during the compile stage, not the e+ecution stage! "hese directi es help to automatically change the program logic based on the alues of certain ariables (called substitution ariables) without changing the source code of the program! /t is achie ed by ma,ing the SQR compiler ignore certain parts of the source code, depending on the alues of certain substitution ariables! "his ma,es SQR programs more fle+ible and easier to maintain )ll substitution ariables are resol ed! "hese ariables play the same role for parts of the source program as compiler directi es do for the program logic! With Just one ,ey stro,e, te+t substitution ariables allow you to change ariable names, literals, or e en entire pieces of code, thus eliminating the need for a time-consuming search-and-replace! SQR e+ecutes all )s, commands that prompt the user for the substitution ariables not coded in the program ! $rogram memory and wor, buffers are allocated! )ll memory arrays are created! SQR chec,s the synta+ of the source program! SQR determines how to optimi7e the SQL data access! alues of some

"he second stage comprises the actual program e+ecution and ta,es place only if SQR finds no compile errors in your program! ;uring the e+ecution stage, SQR starts processing at 6egin-$rogram and stops at 'nd-$rogram calculates the si7e of the report wor,ing page

Page 9

processes the report body processes the report heading processes the report footing writes the entire page to the output file and gets ready for the ne+t page!

2sually you wonEt separate the two stages when running the source program# SQR runs through the compile stage and, if no errors are found, immediately switches into the e+ecution stage! /n some cases, though, you may not want to proceed directly to the e+ecution stage! SQR does allow you to perform the compile step once, then sa e the pre-compiled ersion of the program, to rerun your report at a later date! 9eep in mind, howe er, that if you use a pre-compiled ersion of a program, SQR will not re-e+ecute all the abo e mentioned compile steps, including the )s, commands! SQR will use all e+ternal source files inserted during the compilation stage as well as all substitution ariable alues assigned! SQR does not compile your program into machine language# it will still run under SQR! "he result of the compilation is portable between different hardware platforms!

Page 10

Printing in SQR
"he Print command is used in SQR to place and format information in the page buffer! "he placement of information is controlled by a set of position coordinates! 'dit mas,s and formatting options may also be used to control the appearance of the data! $osition (oordinates o "he Print command uses three coordinates to place information relati e to the %eading, 6ody, and &ooting area of the page buffer Line (olumn Length o "wo ways to specify position coordinates &i+ed places information in absolute grid positions within the appropriate buffer area Relati e uses a signed number to place information forward or bac,ward a specified number of lines or columns relati e to the current cursor position o $osition coordinates can be numeric literals or user-defined SQR ariables o /f the line or column coordinate is 7ero (or omitted), the current position is used! /f the length coordinate is 7ero (or omitted), the actual length of the literal or userdefined ariable is used

'+plicit Print (ommand 2se an e+plicit Print command to print a column ariable (C(olname), a user-defined ariable, or a literal! )n e+plicit print is the only way to print SQR ariables or literals! Synta+# '+ample# print K ariable L literal M (>line?>,>column?>,>length???) print NStudent 8ameE print C)!8ame print PReport-"itle print N$eopleSoftE (H,H,HH) (,GI,OB) (GH,HB) ()

(enter

/mplicit $rinting -ou can implicitly print the alue from the database column by placing print coordinates to the right of the column name (or synonym)! SQR implies that if print coordinates are present, it should print the alue from that column in the position indicated! /mplicit printing only wor,s with database columns in a begin-S'L'(" paragraph! /t cannot be used to print SQR ariables or literals! Synta+# begin-S'L'(" (<L2*8H >Csynonym? (>line?>,>column?>,>length???) (<L2*8I (>line?>,>column?>,>length???) A &R<* A end-S'L'(" begin-S'L'(" )!8)*' (GH, H,OB) )!$%<8' ( ,GQ,HQ) &R<* $SF$'RS<8)LF;)") )

'+ample#

Page 11

end-S'L'("

Format Options
With the Print command, you can use a ariety of formatting options! Some of these options can be used in combination with others and some are mutually e+clusi e! "his is true whether you are performing an e+plicit or implicit print! See the following chart for formatting compatibility# 2nderlin e

6old 6old 6o+ (enter 'dit &ill Shade 2nderlin e Wrap

6o+

(enter

'dit

&ill

Shade

Wrap

Page 12

Bold

Bold causes the information to be printed in #old type! Synta+# print K ariable L literalM '+ample# (position) 6old (B,GI,OB) 6old

print N(ourse ;escriptionE

Bo4

Box draws a one-line deep graphical bo+ around the printed data! "his option has no effect for line printers! Synta+# print K ariable L literalM '+ample# (position) 6o+ (GI,H,B) 6o+

print Psub"otalLine

%ere is a sample output for the coding e+ample abo e# "otal for (ourse HBBH on BH1HI1HRRS is# 7enter HB

2se the Center option to position the information on a line! $eopleSoft routinely uses this option to center te+t in the standard headings! When the Center option is used, the column alue of the position coordinate is ignored! Synta+# print KStringF ar L literalM (position) '+ample# print N$eopleSoftE (enter () (enter

8dit

"he Edit option allows you to edit each field before it is printed for impro ed appearance, consistency, or conformity to your business standards! "here are se eral types of edit# 8umeric "e+t ;ate 'ach of these edit types has se eral format mas,s! When the length component of the position coordinate and the si7e of the edit mas, are in conflict, the smaller of the two is used! /t is better to lea e the length coordinate blan, and let the edit mas, determine the length! Synta+# print K ariable L literalM (position) 'dit Kmas,M

Page 13

2umeric 8dit 'as9s "he mas, is used to print numbers! /t fills to the right of the decimal point with 7eroes, and fills to the left of the decimal point with spaces! 'as9 "alue /esult R,RRR!RR HBB H B B ! B B R,RRR!RR HIO!TQS H I O ! T S R,RRR!RR -HS - H S ! B B R,RRR!RR HIOT!QS H , I O T ! Q S R,RRR!RR HIOTQ!SU V V V V V ! V V "he ! mas, if added to the front of a mas, to left fill with leading 7eros! 'as9 "alue /esult BRRRRR HBB B B B H B B BRRRRR HIOTQS H I O T Q S "he " mas, is used to print numbers with a leading currency symbol! /f you use a single dollar sign, it is printed in a fi+ed position! /f you use two or more dollar signs, it is printed as a floating currency symbol! "he currently symbol is set by the MONE#$%I&N parameter in pssqr!ini and can be changed using the SQR Alter$Locale'function! 'as9 "alue /esult PR,RRR!RR HBB P H B B ! B B PP,PPR!RR HBB P H B B ! B B "he $S and $& mas,s may be added to the add parenthesis around negati e numbers! 'as9 "alue /esult RRRR!RR$S -HBB ( H RRRR!RR$& -HBB ( H PPPR!RR$S -HB ( P PPPR!RR$& -HB ( P end of a numeric edit mas, to B B H H B B B B ! ! ! ! B B B B B B B B ) ) ) )

:e4t 8dit 'as9s "e+t edit mas,s allow you to format string data! "he characters (, B, and W ha e special meaning! )ny other characters in the edit mas, are printed as literals! "he ( mas, prints the corresponding character from the print string! "he B mas, embeds a space in the corresponding position of the print string! "he NWN (tilde) mas, s,ips the corresponding character from the print string! 'as9 "alue /esults +++-++-++++ HIOTQSUXR H I O - T Q - S U X R +++W++W++++ HIO-TQH I O T Q S U X R SUXR ++1W++1W++++ HI-OH-IBBB H I 1 O H 1 I B B B (+++)6+++-++++ BHIOTQSUX ( B H I ) O T Q - S U X R R N(+++) +++-++++E BHIOTQSUX ( B H I ) O T Q - S U X R R

Page 14

+ate 8dit 'as9s 7*aracter 'as9 ---, --, ----, S---RR (( or S(( 6( ); Q R* WW W ;;; ;; ; ;);'R 'Y )* $* %% %%HI %%IT SSSS 8, 88, 888, 8888, 88888, 888888 *<8"% *<8 ** */ SS +escription Last O, I, or H digit(s) of year! )ssumes current century and1or decade! T-digit year, 3S4 prefi+es 6( dates with 3-3! Last I digits of year, for years in other centuries! (entury# 3S4 prefi+es 6( dates with 3-3! 6(1); indicator Quarter of year (H,I,O,T# Y)8-*)R @ H)! Roman numeral month (/-0//# Y)8@H)! Wee, of year (H-QO) where wee, H starts with the first day of the year and ends with the se enth day of the year! Wee, of the month (H-Q) where wee, H starts on the first day of the month and ends with the se enth day of the month! ;ay of year (H-OSS)! ;ay of month (H-OH)! ;ay of wee, (H-U)! Sunday is first day of wee,! 8ame of day! )bbre iated name of day! Yapanese /mperial 'ra! Returns the name of the Yapanese /mperial 'ra in the appropriate ,anJi (3%eisei4 is the current era)! -ear of the Yapanese /mperial 'ra! Returns the current year within the Yapanese /mperial 'ra! Yulian day ( ariation)Z the number of days since Yan H, TUHO 6(! 8umbers specified with 3Y4 must be integers! *eridian indicator! )ssumes IT-hour cloc, unless meridian indication specified! %our of day (H-HI)! %our of day (B-IO)! Seconds past midnight (H-XSORR)! &ractions of a second! $recise to microseconds, howe er, for most hardware and databases, this much accuracy will not be attainable! 8ame of month! )bbre iated name of month! *onth (BH-HI# Y)8@BH)! *inute (B-QR)! Second (B-QR)!

Page 15

(ase matters in some date formats such as D#, DA#, MON, and MONT)! &or e+ample, the mas, MON would print ;<2, but Mon would print as ;an! DA# would print as '=2+<>, but Da* would print 'onda?! Single quotes are required with spaces are included in the edit string! "he N[E (bac,slash) character may be placed in front of any character to indicate that it should be treated as a literal, not the corresponding edit mas, character! 'as9 "alue /esult **1;;1---HI-HRHI1HR1IBBB IBBB N;ay, *onth ;;, ----E HI-HR"uesday, ;ecember HR, IBBB IBBB N"he cu[rre[nt [mo[nth HI-HR"he current month is# is# *onthE IBBB ;ecember

(ill

"he +ill option is used to fill an area of the page buffer with a specified set of characters! "he characters will be repeated as many times as is necessary to fill the entire area defined by the position coordinates! "he length component of the position coordinate is required when the +ill option is used! Synta+# print KStringF ar L literalM (position) '+ample# &ill &ill

print NVE (GH,H,HIT) ,print-'a'line'o.'a-teri-/-0

S*ade

"he %1ade option draws a one-line deep, shaded graphical bo+ around the printed data! &or line printers this argument has no effect! Synta+# print K ariable L literalM '+ample# (position) Shade (GO,H,B) (B,GI,B) 'dit RRRR Shade Shade

print N:rand "otal is ---\#E print 5:rand

Sample output for the coding e+ample abo e# :rand "otal is ---\# HOXI @nderline "he Underline option adds a hori7ontal line under the printed te+t! &or line printers, underscore characters are used to emulate underlining! Underline option is not compatible with the Box option! Synta+# print K ariable L literalM '+ample# print NStart ;ateE (position) 2nderline "he

(B,GI,B) 2nderline

Sample output for the coding e+ample abo e# Start ;ate

Page 16

Arap

"he Wrap option prints a specified number of characters from a long te+t field! <nce the current line is full, the remaining te+t is wrapped to the ne+t line! "his process continues up to a specified ma+imum number of lines! 'ach new line of te+t is aligned directly under the pre ious line! "he Wrap option recogni7es word boundaries and, when possible, only brea,s between two words! /f a complete wor, will not fit on the current line, the entire word will be wrapped to the ne+t line! "he Wrap option also supports three additional arguments# "he %trip argument scans the print string for the specified 3strip4 characters! /f a 3strip4 character is found, it is replaced with a space! "he On argument scans the print string for the specified 3on4 characters! /f an 3on4 character is found, it is remo ed, and a brea, occurs at that point! 6oth %trip and On arguments will accept regular characters plus non-display characters whose )S(// alues are surrounded by angled brac,ets (]nn\)! )S(// code for carriage return is ]HO\! )S(// code for line feed is ]X\! "he 2eep$top argument ,eeps trac, of the top line so additional information could be printed on the same line as the beginning of the wrapped te+t! Synta+# print KStringF ar L literalM (position) KlengthFlit L F arM KlinesFlit L F arM Strip@KStripFlit L F arM <n@K<nFlit L F arM 9eep-top

Page 17

SQR Variables and Commands


SQR ariable names can be any length and are not case sensiti e! =ariables are global throughout a report, unless declared as local arguments! "he alid SQR data types are# +ata :?pe "e+t ;ate &loat ;ecimal /nteger 'a4imum Si eB/ange o, "alues OI,USU bytes Yan H, TUHO 6( to ;ec OH, RRRR ); ;ouble $recision D $latform dependent $recision (H-OX digits) -I,HTU,TXO,STX to I,HTU,TXO,STU Initial "alue 8ull 8ull ^ero ^ero ^ero 84ample P8ame P"oday 5) erage 5Salary 5(ounter

SQR pro ides internal, reser ed ariables with alues maintained and updated by SQR! "aria#le 5current-column Pcurrent-date 5current-line 5end-file 5page-count 5return-status 5sql-count Psql-error 5sql-status Psqr-encoding-console, Ksqr-encoding-consoleM Psqr-encoding-database, Ksqr-encoding-databaseM Psqr-encoding-file-input, Ksqr-encoding-file-inputM Psqr-encoding-file-output, Ksqr-encoding-file-outputM Psqr-encoding-report-output, Ksqr-encoding-report-outputM Psqr-encoding-source, Ksqr-encoding-sourceM Psqr-database, Ksqr-databaseM Psqr-dbcs, Ksqr-dbcsM Psqr-encoding, Ksqr-encodingM Psqr-hostname, Ksqr-hostnameM +escription "he current column position within the page grid! "he current date1time stamp on the host machine! "he current line position within the page grid! "his is the absolute line position (not the line number relati e to a report area)! 'nd of &ile ('<&) indicator! "his ariable is set to H following the e+ecution of a 3ead statement that results in an '<& e+ception! "he current page number! "his alue may be altered during e+ecution! ) alue that may be passed bac, to the operating system at the completion of the SQR program! "he number of rows affected by a ;*L statement ( in-ert, update, or'delete)! "he te+t message returned from the ;6*S upon e+ecution of an SQL command! "he numeric return code from the ;6*S upon e+ecution of an SQL command! 8ame of encoding for character data written to the log file or console! "he character data retrie ed from and inserted into the database! 8ame of encoding for character data read from files used with the open command! 8ame of encoding for character data written to files used with the open command! "he report generated by SQR (for e+ample, an L/S file or a $ostScript file)! 8ame of encoding for SQR source files and include files! "he database type for which SQR was compiled! =alid alues are# ;6I, <;6(, S-6)S', /8&<R*/0, <R)(L' Specifies whether SQR recogni7es double-byte character strings! "he alue may be either -'S or 8<! "he name of the default encoding as defined by the '8(<;/8: en ironment ariable when SQR is in o,ed! "he alue can be )S(//, Y'2(, or SY/S! "his ariable contains the name of the computer on which SQR is currently e+ecuting!

Page 18

Psqr-locale 5sqr-ma+-lines 5sqr-ma+-columns 5sqr-pid Psqr-platform, Ksqr-platformM Psqr-program Psqr- er Pusername Psqr-report

"he name of the current locale being used! ) 3G4 at the end of the name indicates an argument used in the locale has changed! "he ma+imum number of lines determined by the layout! When a new report is selected, this ariable is automatically updated to reflect the new layout! "he ma+imum number of columns as determined by the layout! When a new report is selected, this ariable is automatically updated to reflect the new layout! "he process /; of the current SQR process! 5sqr-pid is unique for each run of SQR! "his ariable is useful in creating unique temporary names! "he hardware1operating system type for which SQR was compiled! =alid alues are =*S, *=S, W/8;<WS-8", or 28/0! "he name of the SQR program file! SQR ersion (including ersion number, operating system, database type and date created)! "he database user name specified on the command line! "he name of the report output file! Psqr-report reflects the actual name of the file to be used (as specified by the Df flag or 8'W-R'$<R" command)!

@ser-+e,ined "aria#les o Su#stitution "aria#les are used to supply all or part of an SQR command, or SQL statement, at compile time! 8ormally, substitution ariables are defined at the beginning of your SQR program using a 4de.ine statement! Subsequently, when you want to refer to the contents of the substitution ariable, you simple put the ariable name inside brac,ets! while 4de.ine statements may be placed anywhere in your SQR program, substitution ariable must be defined before they can be referenced! Substitution ariables may also be created through the use of the a-/' command as well as certain command line flags! Synta+# '+ample# 5define subF ar >litF alue? 5define (olR HBX

A Let 5(olr @ K(olRM D I o /untime "aria#les are allocated and manipulated during the e+ecution phase of your SQR program! "he alid data types for runtime ariables are text, date, and numeric! "ypically, runtime ariables are allocated by reference and are not e+plicitly declared! When allocated by reference, runtime ariables are initiali7ed by SQR to null for te+t and dates, or 7ero for numbers! %owe er, as of SQR ersion T!B, ariables can be e+plicitly declared and typecast using the declare$5aria6le ' command in the Setup section!

Page 19

+eclare-"aria#le 7ommand SQR pro ides the ability to e+plicitly typecast program ariables ia the declare$5aria6le' command! "his command must be used in the Setup section or as the first statement of a local procedure! When declared in the Setup section, a ariable is global ( i7e7, it is ,nown throughout your program)! Li,ewise, if a ariable is declared within a local procedure, it will be ,nown in that procedure only! 6y default, all numeric ariables are created as data type .loat! "he de.ault$numeric option may be used to o erride this default! ;ate ariables must be declared if they will be used in calculations or comple+ formatting Synta+# declare- ariable >;efault-8umeric@K;ecimal>;igits)? L &loat L /ntegerM >"ype =arH) >=arH6?>A?? >"ype =arI) >=arI6?>A?? end-declare De.ault$Numeric defines the default format for all numeric ariables! "his applies to all numeric ariables not e+plicitly declared! /f no alue is specified, all numeric ariables will default to .loat! specify the ma+imum number of digits allowed for decimal numbers! "his alue may range from H to OX! /f omitted, the ma+imum number of digits is HS! specifies the data type of all ariables that follow! "his alue must be decimal, .loat, inte8er, date, or text! /f the data type is decimal, the ma+imum number of digits may be specified! )s with the de.ault$numeric' argument, the ma+imum number of digits may range from H to OX, and if omitted, will default to HS digits!

Di8itT*pe

'+ample#

declare- ariable default-numeric@decimal(X) integer 5Qty 5Line8br decimal(HI) 5$rice float 5Line/tem) g te+t P$art8br date P6ac,<rder;ate end-declare

Page 20

<ssignment Statements o "he move command is used to copy data from one storage location to another! <ptionally, an edit mas, may be applied in conJunction with the mo5e statement! Synta+# mo e sourceFdata to targetF ariable >editFmas,? -ource_data may be a literal or a ariable tar8et_5aria6le must be a user-defined ariable edit_ma-/ any alid edit mas, '+ample# o mo e Cname to Pemplname mo e C8/; to Pnid +++-++-++++

"he let command is used to assign the alue of a literal or ariable, or the results of an e+pression, to a user-defined ariable! )n e+pression may be formed as a combination of operands, operators, and functions! Synta+# '+ample# let userF ar @ e+pression let 5Stot @ B let P'mpl/; @ C)!'*$L/; let 5) g @ (5(H G 5(I G 5(O) 1 O

6enchmar, tests show that the mo5e command is more efficient that the let' command for assignment statements!

Page 21

Display and Show 7ommands o "he di-pla* and -1o9 commands are used to place information into the SQR trace file! "his is the same place that SQR writes informational and error messages! &or this reason, di-pla* and -1o9 commands are frequently used for debugging programs! "he di-pla* and -1o9 commands can be used to show ariables and literals, but cannot be used to show the results of e+pressions! "he display command writes a single alue to the SQR trace file! 6y default, each di-pla* command writes its output on a separate line! "he noline option may be added to the end of the di-pla* command to pre ent SQR from issuing a carriage return after the alue is printed! "he di-pla* command also allows you to specify an edit mas, when writing your output! )ll edit mas,s a ailable to the print command are also a ailable to the di-pla* command! Synta+# '+ample# display K ariable L literalM>editFmas,? >noline?

. Write the SQR internal ariables 5sql-error and 5sql-status . to the SQR trace file display N"he sql error isE noline display 5sql-status noline display N D N noline display Psql-error

"he show command also writes information to the SQR trace file! %owe er, unli,e the di-pla* command, -1o9 may be used to write one or more ariables or literals with each statement! Synta+# '+ample# show K ariable L literalM >editFmas,? >K ar L litM >editFmas,? A? show N"he sql error is N 5sql-status N D N Psql-error

"he -1o9 command also allows you to specify formatting options for your output! )ll edit mas,s that are a ailable with the print command are also a ailable with the -1o9 command! '+ample# show NReport date# show N"otal re enue# N P)s<f"oday 'dit N;ay, *onth dd, yyyyE N 5"otalRe 'dit PPPP,PPP,PPR!RR

Page 22

7ontrol Statements o +o "he do command is used to call or in o,e a procedure! "he procedure must be located in the same file as the SQR program or in an SQ( file that has been lin,ed by a 4include' statement! "he do command causes the flow of the SQR program to branch to the named procedure! "he code in that procedure is e+ecuted and then control is passed bac, to the ne+t statement following the do command! Synta+# do procedureFname >(parm_li-t)? parm_li-t '+ample# one or more literals or ariables (separated by commas)

begin-program do /nitiali7e-$rocessing do $rocess-*ain do &inali7e-$rocessing end-program "he i. command allows conditional e+ecution of one or more SQR commands! SQR recogni7es the logical operators @, ]\, \, \@, ], and ]@ and the 6oolean operators and, or, and not! )n i. statement may optionally contain an el-e bloc,! "he SQR commands defined within the el-e bloc, are e+ecuted when the i. condition is false! I. statements may be nested within another i. statement, but each one must ha e its own matching end$i.!

I,

Synta+# if condition K(ommand(s) to e+ecute when condition is trueM >el-e K(ommand(s) to e+ecute when condition is falseM? end-if '+ample# if P'nd<fReport @ N-E print N'nd of ReportE () center end-if

Page 23

8valuate

"he e5aluate command is useful for branching to different commands depending on the alue of a ariable or literal! "he alue being e aluated is compared to the 91en condition! /f the condition is true, all of the statements within that 91en bloc, are e+ecuted! /f no 91en condition is true, then the 91en$ot1er' bloc, is e+ecuted! <ptionally, the brea, command may be used to e+it from the e5aluate construct! (onditions may be any simple logical e+pression! -ou may use the operators @, ]\, \, \@, ], and ]@ in the conditional e+pression! "he 6oolean operators and, or, and not are not allowed in the e5aluate' statement! %owe er, an or condition may be simulated by using two or more 91en conditions, with no inter ening SQR commands!

Synta+# e aluate Kliteral L ariableM when conditionFH >K(ommand(s) to e+ecute when conditionFH is trueM >6rea/?? !!! when conditionFn >K(ommand(s) to e+ecute when conditionFn is trueM >6rea/?? >when-other K(ommand(s) to e+ecute when nothing else is trueM? end-e aluate '+ample# e aluate C'mpl"ype when @ NSE let P"ype @ NSalariedE do (ount-Salaried brea, when @ N'E when @ N%E . /mplied NorE condition let P"ype @ N%ourlyE do (ount-%ourly brea, when @ N8E let P"ype @ N8ot )pplicableE do (ount-8) brea, when-other . when no other condition is true do /n alid-"ype end-e aluate

Page 24

A*ile

"he 91ile loop is used to process a set of SQR statement for as long as some condition is true! "he condition is always tested first, therefore the embedded SQR commands might not be e+ecuted! <ptionally, the 6rea/ command (typically in conJunction with an i. statement) may be used to e+it the 91ile' loop! /t is the de eloperEs responsibility to do something within the loop to ma,e the condition true!

Synta+# while condition >K(ommand(s) to e+ecute while the condition is trueM >6rea/? ! ! !? end-while '+ample# while 5(ount ] 5"otal(ount do *ore-wor, if 5'rrs \ O . /f error threshold is e+ceeded brea, . '+it the 91ile loop end-if add H to 5(ount end-while "he 6rea/ command may be used in a 91ile or an e5aluate command to perform an unconditional branch to the ne+t statement following the end$91ile or end$e5aluate! Exit$%ELECT is used to unconditionally branch to the ne+t statement following the end$%ELECT command! /t is similar to the 6rea/ command as used in the 91ile or the e5aluate' statements!

Brea9

84it-S8C87:

Synta+# e+it-S'L'(" '+ample# begin-S'L'(" '*$L/; 8)*' do Reformat-8ame if 5'rrs \ O e+it-S'L'(" end-if &R<* $SFY<6 W%'R' ! ! ! end-S'L'(" "he &oto command is an unconditional branch to a specified label within the same program section (or procedure)! "he label must be entered on a line by itself, left-Justified and must end with a colon! "he use of 8oto is not recommended! "he -top command is an immediate termination of the currently e+ecuting SQR program! :*is is considered an a#normal termination #? SE/ and Fill trigger a data#ase roll#ac9. /f used by itself, the -top command triggers SQR error OOBH and causes the following message to be added to the SQR trace file#

Doto

Stop

Page 25

(SQR OOBH) $rogram stopped by user request! /f accompanied by the :uiet option, the program will be terminated, but the SQR trace file message is suppressed! Synta+# stop >quiet? '+ample# if 5'rrs \ O show N"he ma+imum number of errors was e+ceeded!E stop quiet end-if

String 'anipulation and (ormatting o Cet 7oncatenation "he two most common techniques used to concatenate strings are the let and -trin8 commands!

2sing the let command, you may concatenate two or more string literals, ariables, or e+pressions by placing the concatenation symbol (two ertical bars) between each one! '+pressions are the result of the e+ecution of an SQR string function!

Synta+# let resultFstrF ar @ KStrLitH L arH ;''+plMLLKStrLitI L arI L '+pIM> LL A? '+ample# String let P)ddress @ Pcity LL N, N LL Pstate LL N N LL C7ip let P(S= @ P&ldH LL N,E LL P&ldI LL N,E LL P&ldO LL N,E LL &ldT "he -trin8 command allows you to concatenate together two or more fields using a common delimiter! "he result is placed in a te+t ariable specified by the into argument!

Synta+# string KStrFLitH L arHM KStrFLitI L F arIM >A KStrFLit8 L F ar8M? by KStr;elimiterFLit L F arM into ResultStr=ar '+ample# address line string P&ldH P&ldI P&ldO P&ldT by N,E into P(S= .(omma output o 84traction )s with concatenation, there are many methods used to e+tract a portion of one string from another! "he most common in ol e the use of the -u6-tr function (with the let command) and the un-trin8 command! delimited string C(ity CState by N, N into P)ddress string P)ddress C^ip by N N into P)ddress .6egin address line .(omplete

Page 26

Su#str

"he -u6-tr function allows you to e+tract one string from another, starting at a specified position and continuing for a set number of characters!

Synta+# let Str=ar @ substr(KStrF=ar L FLit L F'+pM, K StartF$os F8umFLit L F=ar L F'+pM, KLenF8umFLit L F=ar L F'+pM) '+ample# @nstring let P)( @ substr(C$hone, H, O) "he un-trin8 command di ides a string into two or more te+t ariables using a specified delimiter!

Synta+# 2nstring KStrF=ar L FLitM by KStrF;elimiterF=ar L FLitM into Str=arH Str=arI A Str=ar8 '+ample# unstring C$hone by N1E into P)( P"heRest unstring P/nput by N,E into P&ldH, P&ldI, P&ldO, P&ldT

'iscellaneous o Cengt* "he len8t1 function returns the length of a string, including leading and trailing spaces! Synta+# let 8umeric=ar @ length(KStrFLit L F=ar L F'+pM) '+ample# o Instr let 5Len @ length(P'mpl8ame) ,.ind't1e'len8t1'o.'t1e'-tudent'name0

"he in-tr function returns the starting position of one string within another string! -ou may begin your search at any point within the source string by specifying a starting position! Synta+# let 8umeric=ar @ instr(KSourceFStrFLit L F=ar L F'+pM, KSearchFStrFLit L F=ar L F'+pM, KStartF$osF8umFLit L F=ar L F'+pM) '+ample# let 5$os @ instr(C$hone, N1E, H) ,.ind'area'code'delimiter'in'p1one'40

/trim3 Ctrim

"he rtrim and ltrim functions remo e unwanted characters from the right or left side of a te+t string!

Synta+# let 8ewFStrF=ar @ KR L LMtrim (KSourceFStrFLit L F=ar L F'+pM, K"rimFStrFLit L F=ar L F'+pM) '+ample# Let P(ourse @ rtrim(P(ourse, N N) ,trim'trailin8'-pace-0

Page 27

Let P)mount @ ltrim(P)mt, NVE) ,trim'leadin8'a-teri-/-0 o /pad3 Cpad "he rpad and lpad functions pad a source string up to a ma+imum length with a gi en string (usually spaces)! 3pad' adds to the right side of the source string and lpad adds to the left!

Synta+# let 8ewFStrF=ar @ KR L LMpad (KSourceFStrFLit L F=ar L F'+pM, K*a+FLenF8umFLit L F=ar L '+pM, K$adFStrFLit L F=ar L F'+pM) '+ample# let P&ield=alue @ rpad(C(ourseRt, T, N N) ,add'up'to'<'trailin8'-pace-0 let PLine @ lpad(C<rderLine8br, S, NBE) ,add'up'to'='leadin8'>eroe-0

8dit

"he edit function applies formatting to a literal, ariable, or e+pression (of any data type) and returns a string alue! Synta+# let StrF=ar @ edit(KSourceFLit L F=ar L F'+pM, editFmas,) '+ample# let P$hone @ edit(C$hone, N(+++) +++-++++E) ,.ormat'p1one'num6er0 let P"otal @ N"otal Sales# N LLedit(5"otalSales, NPPP,P PR!RRE)

@ppercase3 CoFercase

"he upperca-e'and lo9erca-e commands con ert string ariables to uppercase or lowercase respecti ely!

Synta+# uppercase StrF=ar lowercase StrF=ar '+ample# o :o17*ar uppercase P(ourse lowercase P8ame

"he to_c1ar function con erts a numeric literal, ariable, or e+pression into the equi alent character string! Synta+# let StrF=ar @ toFchar(K8umericFLit L F=ar L F'+p) '+ample# let P"otal @ toFchar(5(ounter)

Isnull

"he i-null function returns a true alue (H) is the specified literal, ariable, or e+pression is emptyZ otherwise it returns a false (B)! "his function is only alid for te+t or date alues! ) te+t field is considered to be empty if it contains a string whose length is 7ero! ) date is considered to be empty if it contains null alues! "he i-null function is usually used as the conditional test in an i. or 91ile command! Synta+# let 56ooleanF=ar @ isnull(K;ateForF"e+tFLit L F=ar L F'+pM) '+ample# if isnull(P/nput$arameter) show N/nput parameter was not specifiedE

Page 28

end-if o Is#lan9 "he i-6lan/ function returns a true alue (H) is the specified literal, ariable, or e+pression is empty or contains only white space! "his function is only alid for te+t or date alues! White space is any combination of null, tab, carriage return, form feed, and line feed characters (i7e7, )S(// codes B and R-HO)! "he i-6lan/ function is usually used as the conditional test in an i. or 91ile command! Synta+# let 56ooleanF=ar @ isblan,(K;ateForF"e+tFLit L F=ar L F'+pM) '+ample# let 5"est @ isblan,(P'mpl/;) if 5"est show N'mpl/; was not specified or is emptyE end-if

+ate 'anipulation and 7onversion )s of ersion T!B, SQR recogni7es date data types and stores their alues in a proprietary format! "o ta,e ad antage of this data type, date ariables must be e+plicitly declared using the declare$5aria6le command! o +atenoF "he dateno9 function returns the current date from the operating system in SQR date format! Synta+# let ;ateF=ar @ datenow() '+ample# o +ateadd let P"oday @ datenow() .:et "odayEs ;ate

"he dateadd function returns a new date alue after a specified number of date units are added to or subtracted from a gi en date alue! =alid date units are NyearE, NquarterE, Nwee,E, NmonthE, NdayE, NhourE, NminuteE, and NsecondE! Synta+# let P8ewF;ate @ dateadd(K;ateF=ar L F'+pM, K;ateF2nitFLit L F=ar L F'+pM, K8umFLit L F=ar L F'+pM) '+ample# let P'nd;ate @ dateadd(CStart;ate, NdayE, HQ) ,add'?@'da*-'to'%tartDate0

+atedi,,

"he datedi.. function returns the difference between two dates based upon a specified date unit type! =alid date units are NyearE, NquarterE, Nwee,E, NmonthE, NdayE, NhourE, NminuteE, and NsecondE! <nly whole numbers are returned! Synta+# let 8umF=ar @ datediff(K;ateF=arH L F'+pHM, K;ateF=arI L F'+pIM, K;ateF2nitFLit L F=ar L F'+pM) '+ample# EndDate0 let 5Wee,s @ datediff(P'nd;ate, P"oday, Nwee,E) ,return- ' num6er ' o. ' 9ee/- ' 6et9een ' Toda* ' and '

Page 29

+atetostr

"he dateto-tr function returns the alphanumeric representation of a date alue based on a date edit mas,! /f no edit mas, is specified, the date format will default to the sqrFdbFdateFformat specified in pssqr!ini! Synta+# let PStrF=ar @ datetostr(K;ateF=ar L F'+pM >, editFmas,?) '+ample# yyyyE) let P$$';ate @ datetostr(P'nd;ate, N;ay, *onth dd,

Strtodate

"he -trtodate function returns the SQR date representation of an alphanumeric string! "he date edit mas, is used to indicate what format the string is in prior to con ersion! /f no edit mas, is specified, the date format will default to the sqrFdbFdateFformat specified in pssqr!ini! Synta+# let P;ateF=ar @ strtodate(KStrFLit L F=ar L F'+pM >, editFmas,?) '+ample# let P*y6irth;ate @ strtodate(NBT1BX1HRSHE, Nmm1dd1yyyyE)

Page 30

2umeric 84pressions3 7ommands3 and (unctions SQR pro ides a wide ariety of techniques for performing numeric calculations! "he following are some of the more common numeric e+pressions, commands, and functions! o Cet "he let statement is the most common command used for numeric e+pressions! With the let command, you can program most linear equations using the standard operatorsZ NGE, N-N, NVE, and N1E! Synta+# let 8umF=ar @ K8umFLitH L F=arH L F'+pHM ><peratorH K8umFLitI L F=arI L F'+pIM ><peratorI K8umFLitO L F=arO L F'+pOM >A??? '+ample# let 58ew;ays @ CLength;ays G H let 52nit;iscount @ C2nits D IQ!BB let 5(ost<f2nits @ C2nits V UQ!Q let 5) gLength @ (5&ldH G 5&ldI G 5&ldO) 1 O

<dd

SQR also pro ides a set of (<6<L-li,e commands for numeric manipulation! "hese commands include add, -u6tract, multipl*, and di5ide! <f these commands, howe er, only add is still in common usage! <ptionally, you may round the result to a specified precision! /f the resulting number is floating point, the precision may be from B-HQ positions to the right of the decimal point! <therwise, with a decimal number, the precision may be from B to OX positions to the right of the decimal point! Synta+# add K8umFLitH L F=arHM to 8umF=arI >round @ K$recisionFLit L F=arM '+ample# add H to 5/nde+ add C2nit)mt to 5Sales"otal Round@I

/ound

"he round function is used with the let command to round a fractional alue to a specified decimal precision! /f the number is floating point, the precision may be from B-HQ positions to the right of the decimal point! <therwise, with a decimal number, the precision may be from B to the ma+imum si7e defined for the number! Synta+# let 8umF=ar @ round(K8umFLit L F=ar L F'+pM, K$recisionFLit L F=ar L F'+pM) '+ample# let 5basrtI @ round(5basrt, I)

Page 31

let 5trate @ round(5trate, II) o :runc "he trunc function drops all decimal digits beyond a specified position! /f used with a floating-point number, the position may be from B-HQ positions to the right of the decimal point! <therwise, with a decimal number, the precision may be from B to the ma+imum si7e defined for the number! Synta+# let 8umF=ar @ trunc(K8umFLit L F=ar L F'+pM, K$ositionFLit L F=ar L F'+pM) '+ample# o :o12um#er let 5) gLength @ trunc(52nits, B)

"he to_num6er function con erts a te+t string to a numeric alue! "he to_num6er function scans the string from left to right one character at a time! /f a numeric character is found, it is con erted, and scanning continues! %owe er, if a non-numeric character is found the con ersion process stops!

Synta+# let 8umF=ar @ toFnumber(KStrFLit L F=ar L F'+pM) '+ample# let 5Length;ays @ toFnumber(PLength;ays)

Page 32

PeopleSoft SQC Files


$eopleSoft has de eloped se eral con entions to ma,e it easier to manage your SQR en ironment! "o reduce de elopment time and ensure consistency, $eopleSoft has de eloped a library of frequently used procedures! "he members of this library are called SQ( files! SQ( files can contain any type of SQR statement, from a few lines of code to a complete set of procedures! Where you 4include the file depends on what type of code the file contains! /f the SQ( contains one or more complete SQR procedures, by con ention, it is 4included at the end of the SQR program! <therwise, it will be embedded within the section that the SQ( code supports! Some of the most common uses of SQ( files include# o ;efinition of SQR en ironment ariables o ;efinition of the Setup section o ;efinition of the standard heading o ;efinition of the footing section o ;ata formatting and con ersion o Loo,up of descriptions and translate alues "he following SQ(s are common to most SQR programs# (ile 2ame seten !sqc setupOH!sqc ($) setupOI!sqc (L) datetime!sqc +escription ;efines information that is common to your database platform, operating system, and report en ironment! Standard setup sections that define the page layout, printer configuration, and paper orientation! (reates edit mas,s for con ersion of date and time ariables from one format to another! /t also contains procedures to perform the actual con ersion of those ariables! (on erts dates between nati e database format and ;"2 format (yyyy-mm-dd) Retrie es the current date and time from the database! "his SQ( produces four ariables# P)s<f"oday and P)s<f8ow, the date and time in nati e database format, and PReport;ate and PReport"ime, in standard report format! (ontains generali7ed routines to initiali7e currency edit mas,s and to format numbers! Retrie es the long and short names from the "ranslate table for a specified field name, field alue, language, and effecti e date! (ontain print statements used as part of the $eopleSoft standard heading (ontains the re-et procedure standard footing section! and the !rocedure 2ame 81) 81)1 /nit-;ate"ime &ormat-;ate"ime &ormat-8ati e"ime (on ert-"o-;"2-;ate (on ert-&rom-;"2-;ate :et-(urrent-;ate"ime

datemath!sqc curdttim!sqc

number!sqc

read+lat!sqc stdhdgBH!sqc stdhdgtr!sqc fshdgBH!sqc reset!sqc

/nit-8umber &ormat-8umber &ormat-)mt (on ert(urrency Read-"ranslate-"able 81) Reset 6egin-&ooting

Page 33

stdapi!sqc

(ontains the application program interface procedures! "hese procedures allow the SQR program to communicate with the $rocess *onitor and Report *anager inside the $eopleSoft en ironment!

;efine-$rcs-=ars :et-Run-(ontrol-$arms Successful-'<Y

=t*er )eading SE7s )/'SBS< ,ile stdhdgBI!sqc (inancial ,ile fshdgBI!sqc stdhdgBO!sqc stdhdgBT!sqc stdhdgBQ!sqc stdhdgBS!sqc fshdgBS!sqc fshdgBH!sqc fshdgBT!sqc +escription (ompany 6usiness 2nit )s <f ;ate $ay $eriod 'nd (hec, ;ate $ay :roup 6usiness 2nit1Ledger <dditional "aria#les* P(ompany P(ompany8ame P6usinessF2nit P6usinessF2nitF;escr P)s<f;ate P$ay'nd;ate P)s<f;ate P$ay:roup P$ay:roup8ame P6usinessF2nit P6usinessF2nitF;escr PLedgerF8ame PLedgerF;escr P6usinessF2nit P6usinessF2nitF;escr PLedgerF:roupF8ame PLedgerF:roupF;escr PLedgerF8ame PLedgerF;escr P$ay'nd;ate P;ept/; P;ept8ame PSet/; PSet/;F;escr P&rom;ate P"hru;ate P(ompany8ame P(ompany;escr P)s<f;ate P(ompany8ame P(ompany;escr P'mpl/; P8ame P(ompany8ame P(ompany;escr P&rom;ate P"hru;ate PReport"itleI

fshdgBSa!sqc

6usiness 2nit1Ledger :roup1Ledger

stdhdgBU!sqc fshdgBU!sqc stdhdgBX!sqc stdhdgBR!sqc stdhdgHB!sqc fshdgBH!sqc fshdgBQ!sqc

$ay $eriod 'nd1(ost (enter Sed/; &or the $eriod (ompany1)s <f ;ate (ompany1'mpl/;

stdhdgHH!sqc

(ompany1&or "he $eriod

stdhdgIB!sqc

Standard Report (with two title lines)

V "hese ariables are in addition to those identified in stdhdgBH!sqc! -ou use procedures to modulari7e your programs and to ma,e your code reusable! 6y sa ing commonly used procedures as SQ( files, you create libraries of functions that may be called

Page 34

from any SQR program! "o a oid possible conflicts with ariable names, these procedures are often defined as local procedures! Local procedures allow us to create and utili7e local ariables that are hidden from the rest of your program! /n order to use the code in SQ( files that contain procedures, you need to do some up-front analysis! -ou need to determine the following# "he SQ( file name "he procedure name /nput ariable(s), if any, and whether they are required or optional <utput ariable(s), if any <nce you ha e finished your analysis, you can implement the SQ( using these steps# $opulate any necessary input ariable(s)! $erform (Do) the procedure! 2se the output ariable(s) created by the procedure! /nclude the SQ( at the bottom of your program (4include)! SQ( filenames should always be entered in lowercase in the 4include statement! filenames are case sensiti e and $eopleSoft-deli ered SQ(s are always in lowercase! 28/0

Ad anced Printing !ith SQR


!age 7ommands 8'W-$):' "his function sends the current page buffer to the output de ice and begins a new one! ) form feed character is added to the output file after each 8ew-$age occurs, unless you specify &ormfeed@8o in the ;eclare-Layout for this program in the 6egin-Setup section! ) 8ew-$age will automatically occur if page o erflow is detected! Synta+# new-page '+ample# begin-select )!(<2RS' if 5(urrentLine \ SQ new-page end-if

$):'-82*6'R

"his function places the current page number on the page! "he te+t specified in the pre_txt_lit and po-t_txt_lit are printed immediately before and after the number!

Synta+# page-number (position) >preFt+tFlit >postFt+tFlit?? Po-ition Specifies the print position of the page number Pre_txt_lit Specifies a te+t string to be printed before the page number Po-t_txt_lit Specifies a te+t string to be printed after the page number L)S"-$):' "his function places the last page number on each page, as

Page 35

in 3page 8 of 04! 2sing la-t$pa8e causes SQR to delay printing until the last page has been processed so the number of the last page is ,nown! Synta+# last-page (position) >preFt+tFlit >postFt+tFlit?? Po-ition Specifies the position for printing the last page number Pre_txt_lit Specifies a te+t string to be printed before the last page nbr Po-t_txt_lit Specifies a te+t string to be printed after the last page nbr '+ample# begin-footing H page-number (H,OU) N$age N .will appear as last-page ( ) N of N N!E .E$age HI of IQ!E end-footing

7olumn 7ommands 8'0"-L/S"/8: Next$li-tin8 causes a new ertical offset in the page to begin! "his function ends the current set of detail lines and begins another! "he logical top of page is reset to the position of the cursor following the next$li-tin8 command (i7e7, the current line becomes line H of the report body)! Synta+# ne+t-listing >no-ad ance? >s,iplines @ 5? >need @ 5? no$ad5ance Suppresses any line mo ement when no printing has occurred since the pre ious next$li-tin8 or ne9$ pa8e! "he default increments the line position e en when nothing was printed! (auses the specified number of lines to be s,ipped before setting up the new offset! 8egati e alues will be ignored! Specifies the minimum number of lines needed to begin a new listing or set of detail lines! /f this number of lines does not e+ist, a new page will be started! Need can be used to pre ent a group of detail lines from being bro,en across two pages! /f the alue is less than or equal to B, then H is assumed!

-/iplineneed

Page 36

'+ample#

begin-select )!'*$L/; (H, H, B) )!8)*' (B, IB, B) )!<R/:F%/R'F;" (I, H, HB) )!);;R'SSH )!(/")!S")"' )!$<S")L let Paddress @ rtrim(C)!(/"-, N N) D LLE, NLLrtrim(C)!S")"', N N) D LLE NLLrtrim(C)!$<S")L, N N) 6!;'S(R (T, IB, B) ne+t-listing s,iplines@H need@Q &R<* $SF$'RS<8)LF;)") ), $SF(<28"R-F"6L 6 W%'R' )!(<28"R-@6!(<28"R<R;'R 6- )!'*$L/; end-select

(<L2*8S

(olumns are analogous to defining tab stops! "he columncommand defines the left-most position of one or more logical columns (or tab stops) within the current page layout! /t mo es the cursor to the position defined by the first logical column! Synta+# columns >intFlitH L F arH L FcolH >intFlitI L F arI L FcolI >A??? int_lit';'_5ar';'_col column '+ample# columns Specifies the left margin position of each .defines the starting pos for O

columns H IR QU

8'0"-(<L2*8

"his command sets the current position on the page to the ne+t column defined with the column- command! /f at$end is used, 8oto$top is ignored! >at-end @ Knewline L newpageM? >:oto-"op @ numFlit L F ar L Fcol? >'rase-page @ numFlit L F ar L Fcol?

Synta+# ne+t-column

"a,es effect if the current column is the last one defined when next$column is in o,ed 8oto$top (auses the current line in the ne+t column to be set! "his is useful when printing columns down the page! era-e$pa8e Specifies where to begin erasing the page when an at$endAne9pa8e occurs! 2S'-(<L2*8 "his command sets the current position on the page to a specified column defined with the column- command! "he command u-e$column'! turns off column processing! Synta+# use-column numFlit L F ar L Fcol '+ample# column use-column O .mo e cursor to the Ord logical

at$end

Page 37

'+ample# $rints columns across the page begin-procedure $rocess-*ain columns H TQ begin-select )!8)*' )!<R/:F%/R'F;" (B, H, IB) (B, GO, B) .define two columns

ne+t-column at-end@newline .prints names and hire dates .across the page &R<* $SF$'RS<8)LF;)") ) <R;'R 6- )!8)*' end-select end-procedure $rocess-*ain '+ample# $rints columns down the page begin-procedure $rocess-*ain columns H TQ let 56ottomLine @ QQ begin-select )!8)*' )!<R/:F%/R'F;" (B, H, IB) (B, GO, B) .define two columns

.print names and hire dates .down the page

if 5current-line \@ 56ottomLine ne+t-column goto-top@H at-end@newpage else print N N (GH, H) end-if &R<* $SF$'RS<8)LF;)") ) <R;'R 6- )!8)*' end-select end-procedure $rocess-*ain Drap*ic 6<0 Box draws a bo+ of any si7e at any location on the page! 6o+es can be drawn with any si7e rule and can be shaded or left empty! Synta+# graphic (line, column, width) bo+ depth rule-width shading Line'and'column $osition coordinates for the upper left hand corner of the graphic! -ou can specify relati e placement with (G), (-), or numeric ariables, as with regular print positions! "he 9idt1 is the hori7ontal si7e in character columnsZ dept1 is the ertical si7e in lines! "he top left corner of the bo+ is drawn at the line and column specified! "he bottom right corner is calculated using the width and depth!

Widt1'and'dept1

Page 38

3ule$9idt1 %1adin8

"he default rule$9idt1 (thic,ness) is I decipoints! "here are UIB decipoints per inch! Specify B if no border is desired! ) number between B and HBB indicating percentage of gray scale! H is ery light and HBB is blac,! /f no shading is specified, B shading is assumed! graphic (T, Q, HSB) bo+ I Q HB print N<utstanding balance due# N (GH, HB)

'+ample# %<R^-L/8'

)or>$line draws a hori7ontal line from the location specified for the length specified! %ori7ontal lines are drawn Just below the base line! Synta+# graphic (line, column, width) hor7-line rule-width '+ample# graphic (T, H, SS) hor7-line HB (put'line'under'pa8e'1eadin8) graphic (GH, SI, HI) hor7-line (put'line'under'.inal'total)

='R"-L/8'

Vert$line draws a ertical line from the location specified for the length specified! =ertical 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! Synta+# graphic (line, column, depth) '+ample# ert-line rule-width

graphic (H, IU, QT) ert-line (dra9'line-'6et9een'column-) graphic (H, QI, QT) ert-line

+eclare-Image "he declare$ima8e command is used in the Setup section to define default characteristic for images! -ou do'not ha e to declare an image before it can be printed! /mages can be printed in a report with the print$ ima8e command whether or not they are declared in the Setup section! "he only ca eat is that if you donEt use the declare$ima8e to define them, you must supply all three is its attributes as part of the print$ima8e' command! ;ifferent printer types accept different image types! &or e+ample, $;& files only accept Y$': and :/& filesZ S$& only accepts 6*$ files, and %$LaserYets only allow %$L: file! Synta+# declare-image K/mageF8ameM >type @ K/mageF"ypeFLitM? >image-si7e @ KWidthF8umFLit, %eightF8umFLit)? >source @ K&ileF8ameFLitM? end-declare '+ample# begin-setup 5include NptsetBH!sqcE ! !

Page 39

declare-image pslogo type @ bmp-file image-si7e @ (TB!Q) source @ Nc#[temp[pslogo!bmpE end-declare ! ! end-setup !rint-Image "he print$ima8e command is used to print a graphical image! "he print$ima8e command can be placed in any section of a report e+cept the Setup section! "he image file must be one of the supported formats (i7e7, '$S, %$:L, Y$':, :/&, or 6*$)! ;ifferent printer types accept different image types! &or e+ample, $;& files only accept Y$': and :/& filesZ S$& only accepts 6*$ files, and %$LaserYets only allow %$L: file! Synta+# print-image >imageFname? (position) >type @ KimageFtypeFlit L F ar L FcolM? >image-si7e @ (widthFnumFlit L F ar L Fcol, heightFnumFlit L F ar L col)? >source @ KfileFnameFt+tFlit L F ar L FcolM? t*pe'A ima8e$-i>e'A "ype of file for the image! SQR supports files of type# '$S-&/L', %$:L-&/L', Y$':-&/L', :/&-&/L', and 6*$-&/L'! "he width and height of the image using standard printer coordinates (i7e7, columns and lines)! '+ample# a standard U!I-decipoint character width is equi alent to HB characters per inch! "herefore, to print an image that is I inches wide, you would specify a width of IB columns! "he path and file name of the image file! begin-heading HI .adJust si7e to allow for

-ource'A '+ample# image

print-image (ompanyLogo (H,H) position (GS) 5include NstdhdgBH!sqcE A end-heading

Page 40

=n-Brea9 !rocessing On$6rea/ is a ery powerful SQR feature that will allow you to control what happens when alues in a column brea,, or change! Specifically, you will use on$6rea/ to# Suppress duplicate alues $roduce subtotals $roduce subheadings (ontrol the flow of your SQR Synta+# print KfieldM (a, b, c) on-brea, Kprint @ change L print @ change1top-page L print @ always L print @ ne erM before @ procedure_name after @ procedure_name sa e @ Ptext_5ar s,iplines @ nn le el @ nn On$6rea/ uses a number of parameters to control printing and program flow# $rint @ <ption has four possible choices# $rint @ change (default) =alues for the columns specified in the on$6rea/ command are printed only when they change! $rint @ change1top-page =alues are repeated after a page brea, e en when they donEt change $rint @ always "he alues are always repeated (whether they change or not) and one or more additional on$6rea/ options are e+ecuted when the alues change $rint @ ne er =alues are ne er printed, but one or more additional on$6rea/' options are e+ecuted when the alues change 6efore @ Specified procedure to in o,e before the alue changes! /f no rows are selected, will not be processed! (an only be used within a begin-select paragraph! Brea/A is ery useful for subheading! )fter @ Specified procedure to in o,e after the alue changes! /f no rows are selected, will not be processed! (an only be used within a begin-select paragraph! A.terA is ery useful for subtotaling! Note: ;o not use relati e position coordinates with 'print statements that include either a 6e.oreA or a.terA procedure that also includes print statements! "he position of the cursor will be mo ed by the procedure(s) and therefore the relati e coordinates may produce inconsistent results! Sa e @ /ndicates a string stored! ariable where the pre ious alue of a brea, field will be

Page 41

S,iplines @ Specifies how many lines to s,ip when the alue changes! /f you use -/ipline-A, be prepared to e+periment until you get the desired result! /f -/ipline-A is used it should be used on all le els for consistent results! Le el @ <ption specified le el of brea, for report with multiple on$6rea/ options! When one of the brea, field changes alue, all higher le el numbers will be treated as if they bro,e as well! Lowest le el is the outermost or most maJorZ highest le el is the innermost or most minor!

=n-Brea9 !rocessing =rder Le els also affect the order in which on$6rea/ processing occurs! "he sequence of e ents for a query containing on$6rea/ fields is as follows# H! )ny 6e.oreA procedures that ha e been declared are processed in ascending le5el' sequence (current le el to highest) before the first row of the query is processed! I! )ll -a5eA ariables are initiali7ed! When a brea, does occur, the following happens# O! "he detail line is printed! T! A.terA procedures are processing in descending sequence from the highest le5el to the le el of the current brea, field (the field triggering the brea,)! Q! %a5eA ariables are set with the new alue! S! /f -/ipline-A was specified, the current line position is ad anced! <nly the -/ipline-A' argument for the current le el is honored! U! Be.oreA procedures are processed in ascending sequence from the current brea, le5el to the highest on$6rea/ le el number! X! )ny brea,s with the same or higher le5el numbers are cleared! "heir alues will print regardless of whether or not their alue changed! R! "he new alue is printed! )fter last detail line is printed, a.terA procedures are processed in descending le el sequence (highest to lowest)! HB! )fter the query finishes (at end-select), any a.terA procedures are processed in descending le el sequence (highest to lowest)! Note: /n order for your SQR program to ma,e appropriate use of the on$6rea/ logic, your SQL statement would need to Order ' 6* on the same fields on which you are brea,ing!

Page 42

"oo#up $ables
) common function within an SQR program is to Join tables in order to get the long description of some data code! &or instance, in a gi en table, you may ha e a (<2RS' or ;'$"F/; but the corresponding description is in another table! "his situation requires the SQR program to retrie e subordinate data and can be done ia a Join, or by performing a procedure that performs a separate S'L'(" from within the main S'L'(" statement! %owe er, for large tables with large amounts of data, a table Join can be a slow process! "here is a more efficient way of retrie ing this data in SQR! -ou can use loo,up tables to sa e static data in a dynamic structure pro iding you more efficient data retrie al during the e+ecution of an SQR program! Loo,up tables are implemented in SQR programs using the load$loo/up and loo/up commands! Coad-loo9up "his command can be used in any SQR section! /t is good practice to place your load$loo/up commands in an initiali7ation procedure, such as /nit-Report! Synta+# load-loo,up name@Kloo,upFtableFnameM table@KdatabaseFtableFnameM ,ey@K,eyFcolumnFnameM returnF alue@KreturnFcolumnFnameM >rows@ KinitialFrowFestimateFintFlit L F arL FcolM? >e+tent@ Ksi7eFtoFgrowFbyFintFlit L F ar L FcolM? >where@ KwhereFclauseFt+tFlit L F ar L FcolM? >sort@ KsortFmodeM? >quiet? Name Ta6le 2e* "he name of the loo,up table! "he array name is referenced in the loo/up command! "he name of the table or iew in the database, where the ,ey and returnF alue columns or e+pressions are stored! "he name of the column that will be used as the 3,ey4 in the array, which is used for loo,ing up the information! 9eys can be character, date, or numeric data types! /f numeric, only integers HI digits or less are permitted for the /e* column! 9eys can be any database-supported e+pression and can be concatenated columns! "he name of the column (or e+pression) that will be returned for each corresponding ,ey! 8ote you can combine se eral columns into an e+pression if you need se eral fields returned for each loo,up! "his is achie ed by concatenating columns! "he initial si7e of the loo,up table! "his is optionalZ if not specified, a alue of HBB will be used! "he amount to increase the array when it becomes full! "his is optionalZ if not specified, a alue of IQ percent of the initial ro9- alue will be used! ) conditional clause used to select a subset of all the rows in the table! /f specified, the selection begins after the word 91ere! When a literal alue is used, the 91ere clause is limited to QHI characters! Specifies the sorting method to be used! "he following alues are permitted# ;( ;atabase sorts data, case-sensiti e sort

3eturn_5alue

3o9Extent W1ere

%ort

Page 43

Buiet

;/ ;atabase sorts data, case-insensiti e sort S( SQR sorts data, case-sensiti e sort S/ SQR sorts data, case-insensiti e sort Suppresses all warning messages generated by the load$ loo/up command (such as 3Loading loo,up array A4) when the command e+ecutes! "he warning message stating the number of duplicate ,eys found is also suppressed! load-loo,up name@/nt-Rooms rows@HI table@$S0L)"/"'* ,ey@&/'L;=)L2' returnF alue@0L)"L<8:8)*' where@&/'L;8)*'@EE(L)SSR<<*EEE and (effecti e dating logic) A GlatCong2ame Room ) Room 6 Room ( Room ; Room ' <ther

'+ample#

:i en the following rows in $S0L)"/"'*# (ieldname (ieldvalue (L)SSR<<* ) (L)SSR<<* 6 (L)SSR<<* ( (L)SSR<<* ; (L)SSR<<* ' (L)SSR<<* 0 "he loo,up table would loo, li,e this# He? /eturn1value ) Room ) 6 Room 6 ( Room ( ; Room ; ' Room ' 0 <ther

Page 44

Coo9up

"he loo/up command searches a loo,up table for a ,ey alue and returns the corresponding returnF alue string!

Synta+# loo,up Kloo,upFtableFnameFlitM K,eyFlit L F arM KreturnF alueF arM loo/up_ta6le_name /e* return_5alue '+ample# Specifies the loo,up table! "his table must be pre iously loaded with a load$loo/up command! "he ,ey used for the loo,up! /t could be a column, ariable, or literal! ) ariable into which the corresponding alue is returned!

loo,up /nt-Rooms CRoom)bbr PRoom8ame

Cimitations /f the report is small and the number of rows to Join is small, a loo,up table is 8<" the way to go! 2sing a loo,up table can be slower because the entire table has to be loaded and sorted for each report run, which represents some processing o erhead! "ypically, the more subordinate data in ol ed and the more table Joins that are done, the more significant the performance boost can be for SQRs that use loo,up tables! Which one is best_ "ry it both ways in your SQR program to find out! "he only limit to the si7e of a loo,up table is the amount of memory a ailable! '+cept for the amount of memory a ailable, there is also no limit to the number of loo,up tables that can be defined!

Page 45

Arra%s and &raphics


)rrays can be defined to store intermediate results or data retrie e from the database! &or e+ample, a S'L'(" paragraph can retrie e data, store it in an array, and gather statistics all at the same time! When the query finishes, a summary could be printed followed by the data pre iously stored in the array! )rrays can also be used when the subordinate data that is associated with a certain code, abbre iation, or /; is more than Just one column! Rather than one data element li,e 8)*' associated with /;, perhaps there are se eral data elements! <r 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! -ou may e en need to integrate information from an e+ternal data source, such as a file, with some table data! "hese scenarios do not lend themsel es to a loo,up table so a common array that stores many data items in each row ma,es more sense! 7reate-arra? (reates an array of fields to store and process data! "he create$ arra* command can be written in any section of the program, howe er, SQR creates arrays at compile time (i7e7, before a program starts to e+ecute)! "herefore, it is recommended that all arrays be created in the setup section of your program! name@arra*_name si7e@nn Kfield@name# type >#occurs? >@initF alueFlit?M >Kfield@name# type >#occurs? >@initF alueFlit?M

Synta+# create-array

A? Name %i>e +ield 8ames the array! "he name is referenced in other array commands! ;efines the number of elements in the array (analogous to table rows)! "his must be either a hard-coded alue or a substitution ariable! ;efines each field or column in the array! 'ach field is defined as type# 8umber uses the de.ault$numeric type (har (or "e+t) character string ;ate same as date ariable ;ecimal >(p)? decimal numbers with an optional precision (p) &loat double precision floating point numbers /nteger whole numbers

&ields can optionally ha e a number of occurrences, that is, they can be repeated occur- times, which gi es the array an apparent third dimension! -ou can also specify an initiali7ation alue for each field! 'ach field is set to this alue when the array is created or when the clear$arra* command is e+ecuted! /f no initiali7ation alue is specified, numeric fields are set to 7ero, character and date fields are set to null! "he ma+imum number of arrays in a single SQR program is HIX! "he ma+imum number of fields per array is IBB!

Page 46

'+ample#

create-array name@6enefits si7e@HI field@'mp8um#number field@8ame#char field@(o erage#char#O@E&ullE field@;ependants#number#O

"hat code would produce a irtual array something li,e this#

Note: Subscripts start at B! "alue assignment (olumns retrie ed from the database and SQR ariables or literals can be mo ed into or retrie ed from an array using the put, 8et, and let commands! "he array must ha e been created pre iously using the create$arra* command! "he let command can be used to reference a alue in an array, copying that alue to a ariable! /t also can be used to copy data to the array from a ariable! Let wor,s as described pre iously! &et and put' wor, in the same fashion as the mo5e command! Cet synta+# let P ariableFname @ arrayFname!arrayFfield (5/) let ar @ arrayFname!field(KrowFnbrFlit L F ar L FcolM >,KfldHFoccFlit L F ar L FcolM?) let arrayFname!field(>rowFnbrFlit L F ar L FcolM >,KfldoccFlit L F ar L FcolM?) @ e+pression let Pname @ 6enefits!name(Q) let 6enefits!name(R) @ N;oe,YaneE put K alueHFlit L F ar L FcolM >K alueIFlit L F ar L FcolM >A?? into arrayFnameFlit (KrownbrFlit L F ar L FcolM)

'+ample# !ut synta+#

Page 47

>fieldH>(KfldHFoccFlit L F ar L FcolM)? >fieldI>(KfldIFoccFlit L F ar L FcolM)? >A??? '+ample# .;ata alues are# .5J @ Q, C'mp8um@SIHOOO, C8ame @ NSmith, YohnE, and .P;ental$lan@E'GOE put C'mp8um C8ame N*ed-)E P;ental$lan into 6enefits(5J) empnum name co erage(B) co erage (H) Det synta+# get alueHF ar > alueIF ar >A?? from arrayFnameFlit(KrowFnbrFlit L F ar L FcolM) >fieldHK(KfldHFoccFlit L F ar L FcolM)? >fieldI K(KfldIFoccFlit L F ar L FcolM)? >A??? :et 5 empno Pname Pmedical from 6enefits(5J) empnum name co erage(B)

'+ample#

7lear-arra? "he clear$arra* command resets each field of the named array to the initial alue specified for that field in the create$arra* command! /f no initial alue was specified, numeric fields are reset to 7ero, te+t fields are reset to null, and date fields are reset to null! Synta+# clear-array '+ample# Kname@arra*_nameM

clear-array name@6enefits

<dditional <rra? 7ommands "he following four commands perform arithmetic on one or more elements in the array! "he array must first be created using the create$arra*' command! "he four array arithmetic commands perform on one or more source numbers, placing the results into the corresponding field in the array! Synta+# array-add KnumericFlit L F ar L FcolM to arrayFname (row) >field>(occurs)?? A array-subtract KnumericFlit L F ar L FcolM from arrayFname (row) >field>(occurs)?? A array-di ide KnumericFlit L F ar L FcolM into arrayFname (row) >field>(occurs)?? A array-multiply KnumericFlit L F ar L FcolM times arrayFname (row) >field>(occurs)?? A /f di ision by 7ero is attempted, a warning message is displayed, the result field is unchanged, and SQR continues e+ecuting!

Page 48

7ommon !rogramming 8rrors Fit* <rra?s o Su#script "alue pro#lems# "he most common programming error to ma,e when wor,ing with arrays is to try accidentally to reference an array element using a subscript alue that is outside the range specified by the array! "he e+act error reads as follows# (SQR HQBB) )rray element out of range (IQ) for array Nre Fbrea,FdownE on line HSQ! "his is typically not detected during compile because the reference to the array element often uses a ariable as a subscript! "herefore, this particular programming error can be difficult to pre ent, but easy to diagnose and correct! o Cooping pro#lems# 6ecause loops are typically used to load and manipulate arrays, another common error is getting stuc, in an endless loop for whate er reason (not incrementing counters properly, referencing the wrong ariable in logic to brea, out of the loop, etc!)! )nother common error also related to looping is the mista,e of using the wrong ariable or counter in the subscript when referencing an array element! "hese code problems would not result in a specific SQR error but would cause the program to run endlessly because it was stuc, in an endless loop! o +ata :?pe issues# )nother common programming error is data type conflicts! "rying to load an in alid data type in an array element or trying to lead an array element alue in a different ariable type are two common errors made when wor,ing with arrays! "hese errors are found during compilation and are easily diagnosed! "he error for data type mismatching is as follows# 'rror on line HSS# (SQR OQHT) $2" and :'" ariables must match array field types! "o help pre ent data type errors, you can use the special characters in array field names! "he special characters used in ariable names to designate data type can be sued in the naming of fields in an array li,e this# create-array name@(lass6rea,;own si7e@IQ field@$roJRoleP#char field@(ount5#number

Page 49

SQR Charts
)rrays are used to create graphics in SQR! SQR pro ides two rather comple+ commands for creating charts in a report# declare$c1art and print$c1art! Se eral different chart types are supported from bar graphs to pie charts to +y-scatter plots! "o add a business chart to an SQR report, there is a basic three-step approach that $eopleSoft outlines in their ;e eloperEs :uides# H) /n the Setup section of your program, create an array and optionally define default chart characteristics# 2se create$arra* to allocate an array! )rrays are used to store the data for charts and are created at compile time (and loaded at run-time)! <ptionally, you may use declare$c1art to define the basic attributes of a chart! -ou can print multiple charts in one program, each of which could ha e unique chart attributes! I) $ut the data into an array! Load the data into an array! (harts used arrays for their data source! O) $rint the chart! 2se the print$c1art command to print the chart! "he attributes that were set in the declare$c1art command may be o erridden in the program with print$c1art' command! Reference the data for the chart with the data$arra* argument! $ro ide certain print attributes, such as position coordinates and chart si7e! +eclare-c*art ;efines the default attributes of a chart that can be printed in an SQR report! "he command may only appear in the Setup section of an SQR report! )mong the a ailable attributes are the following# Synta+# declare-chart KchartFnameFlitM >chart-si7e @ (chartFwidthFintFlit, chartFdepthFintFlit)? >title @ KtitleFt+tFlitM? >sub-title @ KsubtitleFt+tFlitM? >fill @ KfillFlitM? >O;-effects @ KOdFeffectsFlitM? >type @ KbarFtypeFlitM? >legend @ KlegendFlitM? >legend-title @ KlegendFtitleFt+tFlitM? end-declare (hart-si7e is optional, but must be defined in either the declare$c1art or print$ c1art command! (hartFname is the only required field because the other arguments ha e predefined default alues! Some of the other arguments for the declare$c1art command are described in the table below! "he default alues are underlined! &or a complete listing of all command arguments, see the %B3'Lan8ua8e'3e.erence!

Page 50

<rgument chart-si7e title

"alid "alues +e,ault value

+escription "he width and depth of the chart specified in SQR position coordinates! 'nter none for no title <R enter the te+t to be used as a title for the chart immediately after the @ and enclosed in single quotes! 'nter none for no sub-title <R enter the te+t to be used as a subtitle for the chart immediately after the @ and enclosed in single quotes! "he sub-title is placed Just below title! Specifies the type of fill that is applied to the shapes (bars, piesegments, etc!) that represent the data loaded into the chart! Dra?scale aries the density of blac, dots! 7olor sends color instructions to the current printer! /f the current printer does not support color, then it may appear as grayscale! 7ross*atc* uses patters to fill the shapes representing each data set! 2one displays all graph shapes filled with white! O;-effects will gi e your chart depth if set to ?es! /f no, then chart is displayed in a 3flat4 I; mode! Specifies the type of chart!

none "e+t none "e+t

sub-title

fill

grayscale color crosshatch none

O;-effects

yes no line pie bar stac,ed-bar HBB`-bar o erlapped-bar floating-bar histogram area stac,ed-area HBB`-area +y-scatter-plot high-low-close yes no none te+t

type

legend legend-title

Specifies if there will be a legend displayed for this chart! "itle for the chart legend!

Page 51

:eneral 8otes# )ll declare$c1art attributes may be o erridden by the print$c1art' command! Declare$c1art arguments specified more than once will produce a warning! SQR uses the first instance of the argument and ignores all subsequent references! )rguments can be specified in any order!

!rint-c*art

$rints a chart at the designated position within the report buffer! >chartFnameFlit?(position) data-array @ arrayFname data-array-row-count @ K+FnumFlit L F ar L FcolM >chart-si7e @ KchartFwidthFintFlit, chartFdepthFintFlit)?

Synta+# print-chart

C1art_name

Specifies the name of the chart from the declare$c1art command! "his name is not necessary if you specify the c1art$ -i>e and all other pertinent attributes in the print$c1art' command! Po-ition Specifies the position of the upper-left corner of the chart! )s with other print commands, position coordinates may be relati e! )fter e+ecution of the print$c1art command, the cursor is repositioned to this position! Data$arra* Specifies the name of the array containing the data to be plotted! "his must be the name of an array defined with the create$arra* command! Data$arra*$ro9$count Specifies the number of rows or sets of data to be used from the data$arra*! /f the data$arra* has a greater number of rows, only data$arra*$ro9$count will be included in the chart! Data$arra*$column$count Specifies the number of columns to be used from the data$arra*7 /f the data$arra* has a greater number of columns, only data$arra*$column$count will be included in the chart! :eneral 8otes# Print$c1art e+pects the data$arra* to be organi7ed in a particular way! &or e+ample, for pie charts, print$c1art e+pects the data array to be composed of two columns and multiple rows of dataZ the first column should be character and the second column should be numeric! &or a bar chart, print$c1art e+pects multiple rows of data with at least two columns, the first column character and the others numericZ each numeric column would represent another rows of data with at least two columns, the first column character and the others numericZ each numeric column would represent another -a+is alue! Print$c1art will fill the area defined by c1art$-i>e as much as possible while maintaining a suitable ratio of height to width! /n cases where the display area is not well suited to the chart display, the chart will be centered within the specified region, and the dimensions will be scaled to accommodate the region! "herefore, do not be alarmed if

Page 52

the chart does not fit e+actly inside the bo+ you ha e specifiedZ it simply means that SQR has accommodated the shape of the region in order to pro ide the best possible appearing chart! (hart commands used to send output to a line printer will be ignored! <nly $ostScript printers or %$ printers that support %ewlett $ac,ard %$:L (generally, this is %$ LaserYet model O and higher) will render chart output! /f you attempt to print a chart to a LaserYet printer that does not support %$:L, the %$:L command output will li,ely become part of your output, lea ing one or more lines of meaningless data across your report! )ll the attributes defined for declare$c1art are alid for the print$ c1art command! )dditionally, there are fi e other parameters! "he position of the chart is described using the first parameter! "he data that support the chart are defined in the additional attributes# data$ arra*, data$arra*$ro9$count, data$arra*$column$count, and data$ arra*$column$la6el-!

Page 53

Anda mungkin juga menyukai