Sie sind auf Seite 1von 55

======================================================================= ========= Q: Do I have to relink the SQR executables after installing?

A: On VMS - Yes, since the executables don't exist yet. On UNIX,DOS and Windows - Normally not. Yes, if you created your own functions in UFUNC.C, have your own calls in UCALL.C, want to link SQR with other products, did major database or OS upgrades. ======================================================================= ========= Q: When re-linking the SQR executables on a UNIX host, I get the following error: ld: sqr.a: warning: table of contents for archive is out of date; rerun ranlib() This is then followed by a long list of undefined symbols. What can be done to correct this problem? A: The library's table of contents is out of date (possibly due to copying the file from another directory) and needs to be re-created. On UNIX hosts that support the ranlib command, do the following: ranlib *.a On UNIX hosts that do not support the ranlib command, do the following (and repeat the command for all other .a files also): ar ts sqr.a ======================================================================= ========= Q: How can I suppress display of the SQR banner line when running SQR? A: Use the -XB flag. ======================================================================= ========= Q: Are SQR commands and variables case sensitive? A: No. Commands can be spelled with any case combination. The SQR variable $string is equivalent to $STRING.

======================================================================= ========= Q: Do SQR programs require a .sqr extension? Do SQR runtime files require a .sqt extension? A: SQR programs do not require a .sqr extension. SQR runtime files require a .sqt extension. ======================================================================= ========= Q: Can a .sqt file be "de-compiled" into the original SQR code? A: No. This is not possible. ======================================================================= ========= Q: How can I run SQR so that the database username/password does not show up in the Process Status (ps) listing on a unix machine (like an HP). A: Create an argument file that has the username and password at the top. The command line would be: sqr reportname @file. ======================================================================= ========= Q: What is the limit for SQR command line length on PC/Windows? A: The limit is 128 characters. This is a PC limitation not an SQR limitation. You may want to have the SQR BINW directory on your PATH so that the full pathname to the SQRW executable is not needed. Arguments can be put into a report argument file that is specified with @file on the command line. ======================================================================= ========= Q: How do I reference SQR global variables inside of a local procedure? A: Include an underscore between the # or $ and the variable name. For example, use #_current-line instead of #current-line . ======================================================================= ========= Q: Can I set the current page number in an SQR program?

A: Yes. Move the desired value to the SQR variable #page-count. ======================================================================= ========= Q: How can I bold portions of a background document? A: Create a document marker and use it to print from outside of the document section. ---------------------------- Example code begins here -------------------------begin-report do main end-report begin-procedure main begin-document This text is printed in the background document @boldlocation ! Save the location for the bold text in a document marker end-document position @boldlocation print 'This is the bold text' () bold end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: What determines the file permissions for files that SQR creates? A: On a Unix machine, the operating system variable umask is used. For example, a umask of 022 will create a file with permissions rw-r--r--. If a file already exists, the original file permissions will be retained. On a VMS machine, the default protection flags can be set for system, owner, group and world in the login.com file with the 'set prot' command. For example: set prot=(s:rwed,o:rwed,g:rwed,w:rwed) /default The protection flags are interpreted as follows:

r w e d

= = = =

read write execute delete

======================================================================= ========= Q: What is the maximum record length for the OPEN command? A: The maximum is 32K bytes (32767). ======================================================================= ========= Q: Can I read and write null values from and to an ASCII file? A: No. SQR strings are null terminated. This means that characters after (and including) the first null character would be lost. ======================================================================= ========= Q: How can I read in variable length delimited fields from a sequential file? An example format would look like this: field1|field2|field3|... field11|field22|field33|... field111|field222|field333|... A: Instead of reading a record into individual fields, read the entire record into one field and then use the SQR unstring command to separate the delimited fields. ---------------------------- Example code begins here -------------------------! ! This report shows how to read in a sequential file with variable length ! delimited fields. begin-report open 'test.dat' as 1 for-reading record=80:vary while 1 read 1 into $record:80 if #end-file

break end-if unstring $record by '|' into $field1 $field2 $field3 ... show $field1 ' ' $field2 ' ' $field3 ... end-while close 1 end-report ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I insert a null value into a numeric field in the database? I tried not giving a #variable a value but that did not work, 0 was inserted. A: When doing the insert, list only the fields for which a value is known. All other fields will get the null value. Here is sample code for inserting into the following table: Name ------------------------------name job id deptno Null? -------no yes no yes Type ---varchar2(24) varchar2(24) number number

---------------------------- Example code begins here -------------------------begin-sql insert into table1 (name,id) values ('Jones',1) end-sql ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: If I get a duplicate key warning message when SQR loads a lookup table, will the lookup table still work correctly. A: No. Use of a lookup table is dependent on not having duplicate keys.

======================================================================= ========= Q: How can I find out if rows are selected by a BEGIN-SELECT paragraph? Can I use the SQR variable #sql-count? A: #sql-count indicates the number of rows affected by a DML statement (insert, update, or delete). It cannot be used for a BEGIN-SELECT paragraph. Here are two techniques to determine if data was selected. ---------------------------- Example code begins here -------------------------begin-report do main1 do main2 end-report begin-procedure main1 move 0 to #count ! This is optional unless main1 is called more than once begin-select column1 column2 column3 add 1 to #count from table1 end-select if #count > 0 show 'Number of rows selected was ' #count edit 999 else show 'No rows selected' end-if end-procedure main1 begin-procedure main2 begin-select 'true' &true column1 column2 column3 from table1 end-select if &true = 'true' show 'Selected at least one row' else

show 'No rows selected' end-if end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: What is the value used with -C flag of BEGIN-SELECT? A: BEGIN-SELECT -Cflag (Oracle, Ingres, SQL Base) - sets query buffer size. If the value of the -C flag is up to 256 it is in kilobytes, any number over 256 is in bytes only. For Oracle the default is set by the context_area parameter in the init.ora file - the default is 4096. ======================================================================= ========= Q: What is the maximum value for -M file parameters? A: -Mfile parameters maximums are not all 64K as User's Guides up to version 2.5 seem to suggest. PARAMETER LIMITS OF -Mfile FOR SQR IN BYTES --------------------------------------------------------------Parameter "breaks" "cursors" "dynamicargs" "expressionspace" "forwardrefs" "longspace" "numvariables" "onbreaks" "positions" "proglinepars" "proglines" "queries" "queryargs" "sqlsize" "stringspace" "subvars" "variables" Default 100 6 70 2048 200 13515 240 30 900 9000 2500 60 240 4000 10000 100 750 Max. Value 65535 6 (SQLbase) 32767 65535 32767 65535 32767 65535 65535 65535 32767 32767 65535 65535 65535 32767 32767

"whens"

70

65535

======================================================================= ========= Q: Can I write a matrix report in SQR? A: Yes. Example of a SQR cross-tab (matrix) report ---------------------------- Example code begins here -------------------------Begin-Setup Page-Size 60 133 declare printer type = postscript orientation = landscape line-size = 8 char-size = 6 End-Setup Begin-Report Graphic (5,1,122) box 59 12 Graphic (1,20,103) box 63 12 Graphic (1,55,33) box 63 12 Graphic (8,1,122) horz-line 12 Graphic (11,1,122) horz-line 12 Graphic (14,1,122) horz-line 12 Graphic (17,1,122) horz-line 12 Graphic (20,1,122) horz-line 12 Graphic (23,1,122) horz-line 12 Graphic (26,1,122) horz-line 12 Graphic (29,1,122) horz-line 12 Graphic (32,1,122) horz-line 12 Graphic (35,1,122) horz-line 12 Graphic (38,1,122) horz-line 12 Graphic (41,1,122) horz-line 12 Do Main End-Report Begin-Procedure Main let #count = 0 do DRA_HEADER Begin-Select iin_descr (+1,3,15) on-break print=change/top-page after=PRINT_DETAIL so_code decode(so_code,'D',count(esn_nbr)) &d_count_esn_nbr decode(so_code,'D',nvl(sum(lbr_hrs),0)) &d_lbr_hrs

decode(so_code,'R',count(esn_nbr)) &r_count_esn_nbr decode(so_code,'R',nvl(sum(lbr_hrs),0)) &r_lbr_hrs decode(so_code,'A',count(esn_nbr)) &a_count_esn_nbr decode(so_code,'A',nvl(sum(lbr_hrs),0)) &a_lbr_hrs do GET_ESN_COUNT_2 if &so_code = 'D' Move &d_count_esn_nbr to #d_count_esn_nbr Move &d_lbr_hrs to #d_lbr_hrs Divide #count_esn_nbr_2 into #d_lbr_hrs add 1 to #count end-if if &so_code = 'R' Move &r_count_esn_nbr to #r_count_esn_nbr Move &r_lbr_hrs to #r_lbr_hrs Divide #count_esn_nbr_2 into #r_lbr_hrs add 1 to #count end-if if &so_code = 'A' Move &a_count_esn_nbr to #a_count_esn_nbr Move &a_lbr_hrs to #a_lbr_hrs Divide #count_esn_nbr_2 into #a_lbr_hrs add 1 to #count end-if from so, lbr_usage where so.so_nbr = lbr_usage.so_nbr and lbr_usage.eng_mdl_nbr = '06' and so_code in ('D', 'R', 'A') group by iin_descr, so_code End-Select End-Procedure Begin-Procedure GET_ESN_COUNT_2 Begin-Select count(esn_nbr) &count_esn_nbr_2 Move &count_esn_nbr_2 to #count_esn_nbr_2 from so, lbr_usage where so.so_nbr = lbr_usage.so_nbr and lbr_usage.iin_descr = &iin_descr and lbr_usage.eng_mdl_nbr = '06' group by iin_nbr End-Select End-Procedure Begin-Procedure DRA_HEADER Print 'Disassembly'

(1,32)

bold Print 'Routing/Repair' bold Print 'Assembly' bold Print ' # of Avg.Hrs.' bold Print 'Engines per Engine bold Print ' # of Avg.Hrs.' bold Print 'Engines per Engine bold Print ' # of Avg.Hrs.' bold Print 'Engines per Engine bold position (+2) End-Procedure

(,65) (,100) (3,25) Applied%' (4,25) (3,59) Applied%' (4,59) (3,93) Applied%' (4,93)

Begin-Procedure PRINT_DETAIL if #count = 3 position (-2) else if #count = 2 position (-1) end-if end-if let #count = 0 Print #d_count_esn_nbr (,+7,4) edit 9999 Print #d_lbr_hrs (,+4,8) edit 999999.9 Let #d_tot_hrs = #d_lbr_hrs / (#d_lbr_hrs + #r_lbr_hrs + #a_lbr_hrs) * 100 Print #d_tot_hrs (,+3,4) edit 99.9 Print '%' () Print #r_count_esn_nbr (,+10,4) edit 9999 Print #r_lbr_hrs (,+4,8) edit 999999.9 Let #r_tot_hrs = #r_lbr_hrs / (#d_lbr_hrs + #r_lbr_hrs + #a_lbr_hrs) * 100 Print #r_tot_hrs (,+3,4) edit 99.9 Print '%' () Print #a_count_esn_nbr (,+10,4) edit 9999 Print #a_lbr_hrs (,+4,8) edit 999999.9 Let #a_tot_hrs = #a_lbr_hrs / (#d_lbr_hrs + #r_lbr_hrs + #a_lbr_hrs) * 100

Print #a_tot_hrs Print '%' () position (+2) End-Procedure

(,+3,4)

edit 99.9

Begin-Procedure HORZ_LINE Graphic (#line_no,1,122) horz-line 12 End-Procedure Begin-Heading 6 Print 'Applied Time Ratio Summary' (1,1) bold Move 2 to #line_no do HORZ_LINE Print 'Summarized Average Applied Time and Applied Percent' bold End-Heading

(4,1)

---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Can I use 'dynamic column names' in Begin-Select (versions prior to v3.0)? A: Yes, see following workaround. This SQR report will actually write another SQR code with column names supplied by the user and execute it. Note that in SQR Version 3.0, dynamic columns are directly supported. ---------------------------- Example code begins here -------------------------begin-report do main end-report begin-procedure main move 'DEPTNO' to $col1 ! You might use INPUT here to prompt the user move 'ENAME' to $col2 ! to enter the column and table names instead. move 'EMP' to $tab move 'sqrout.sqr' to $sqrpgmnam let $syscmd = 'sqr '||$sqrpgmnam||' user/password' move 100 to #flatfileid open $sqrpgmnam as #flatfileid for-writing record=132

write #flatfileid from 'BEGIN-REPORT' write #flatfileid from ' DO MAIN' write #flatfileid from 'END-REPORT' write #flatfileid from 'BEGIN-PROCEDURE MAIN' write #flatfileid from 'BEGIN-SELECT' write #flatfileid from $col1 ' (+1,1)' write #flatfileid from $col2 ' (,30)' write #flatfileid from 'from ' $tab write #flatfileid from 'END-SELECT' write #flatfileid from 'END-PROCEDURE MAIN' close #flatfileid call system using $syscmd #status display 'Status of call is ' noline display #status end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I get page 'x of y' on my output (versions prior to v3.0.x)? A: See following sample report. Note that SQR Version 3.0 directly support printing the page number of the last page. ---------------------------- Example code begins here -------------------------begin-report do main end-report begin-setup page-size 10 80 end-setup begin-footing 2 page-number (2,32) 'Page ' print ' of ' () add 1 to #pcnt end-footing begin-procedure main begin-select deptno (+1,1)

! add 1 to page count variable

empno (,10) ename (,20) from emp order by deptno end-select new-report 'junk.lis' ! close the lis file open 'pagetest.lis' as 1 for-reading record=80 ! open the lis file open 'pagetest.out' as 2 for-writing record=80 ! open another output file move #pcnt to $pcnt 99 while 1 lis file read 1 into $rec:80 if #end-file break end-if let #pos1 = instr($rec,'Page',1) let #pos2 = instr($rec,'of',1) if #pos1 != 0 and #pos2 != 0 string let $newrec = $rec || $pcnt write 2 from $newrec:80 else write 2 from $rec:80 out file end-if end-while close 1 close 2 end-procedure ! loop reading records in the

! test whether the string ! has 'Page' and 'of' ! if so, add the total page to

! write new line to out file ! otherwise write the line to

---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I prevent the printing of the empty page at the end of every .LIS file? A: Delete the last line in the .LIS file through an editor or this can be automated with CALL SYSTEM USING command which would execute the following

SQR code. This program reads an ASCII file, removes the last line (the line having the Form Feed) from it and writes the output to another ASCII file. ---------------------------- Example code begins here -------------------------#define record-length 400 begin-report input $finp type=char input $foutp type=char open $finp as 1 for-reading record={record-length} status=#stat if #stat != 0 stop end-if open $foutp as 2 for-writing record={record-length} status=#stat if #stat != 0 stop end-if read 1 into $record:{record-length} while 1 move $record to $previous_record read 1 into $record:{record-length} if #end-file break end-if write 2 from $previous_record end-while close 1 close 2 end-report ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: In BEGIN-SELECT do the FROM and WHERE clause have to be aligned to the left margin? A: No. Only the selected columns have to be. ======================================================================= ========= Q: My ON-BREAK is not working as I am expecting it to work. Why? A: Many novice users of SQR have problems with ON-BREAK format command

and its parameters. We suggest the following: 1) Study carefully the example in SQR Workbench 2.5 User's Guide on p.4-112. 2) Most important - experiment in a similar way shown in this example: ---------------------------- Example code begins here -------------------------! ! This report shows how multiple ON-BREAK's AFTER, BEFORE and LEVEL parameters ! interact. ! begin-report do main do main2 do main3 end-report begin-setup page-size 55 75 end-setup begin-heading 1 date-time (2,55) mm/dd/yy date-time (2,64) hh24:mi end-heading begin-footing 1 page-number (1,60) 'Page ' end-footing begin-procedure main print 'In procedure main1' (+1,1) begin-select soc_sec_num &ssn1 (+1,1) on-break after=ss1_break level=1 psgr_lname &lname1 (+1,1) on-break before=lname1_break level=1 psgr_fname &fname1 (+1,1) on-break after=fname1_break level=2 address &address1 (+1,1) on-break before=address1_break level=2 city &city1 ! (+1,1) state &state1 ! (+1,1) let $new=&city1||' '||&state1 print $new (+1,1) on-break after=new_break let #page-count=33

display #page-count from passenger end-select new-page end-procedure begin-procedure main2 print 'In procedure main2' (+1,1) begin-select soc_sec_num &ssn2 (+1,1) psgr_lname &lname2 (+1,1) psgr_fname &fname2 (+1,1) address &address2 (+1,1) city &city2 (+1,1) state &state2 (+1,1) from passenger end-select new-page end-procedure begin-procedure main3 print 'In procedure main3' (+1,1) begin-select soc_sec_num &ssn3 (+1,1) psgr_lname &lname3 (+1,1) psgr_fname &fname3 (+1,1) address &address3 (+1,1) city &city3 (+1,1) state &state3 (+1,1) from passenger end-select new-page end-procedure begin-procedure ss1_break print 'In ss1_break - this is an after proc. - level1' (+2,10) end-procedure begin-procedure lname1_break print 'In lname1_break - this is a before proc. - level1' (+2,10) end-procedure begin-procedure fname1_break print 'In fname1_break - this is an after proc. - level2' (+2,10) end-procedure

begin-procedure address1_break print 'In address1_break - this is a before proc. - level2' (+2,10) end-procedure begin-procedure new_break print 'In new_break - this is a after proc.' (+2,10) end-procedure ---------------------------- Example code ends here ---------------------------Follows an example of using multiple breaks with output: ---------------------------- Example code begins here -------------------------begin-report do get-employees end-report ... ! page setup and heading section begin-procedure get-employees begin-select emp_state (0,1) on-break print=change/top-page skiplines=2 after=print-tot-for-state save=$old_state level=1 emp_city (,9) on-break print=change/top-page skiplines=2 after=print-tot-for-city save=$old_city level=2 emp_zip move &emp_zip to $edit_zip xxxxx-xxxx print $edit_zip (,27) on-break print=change/top-page skiplines=2 after=print-tot-for-zip save=$old_zip level=2 emp_lname emp_fname ... ! concatenate first and last name with comma to format for report and print ! concatenated field emp_street (,62) add 1 to #zip_emp_count

! variables to track number of

add 1 to #city_emp_count ! employees within each address add 1 to #state_emp_count ! breakdown add 1 to #emp_count from employee order by emp_state, emp_city, emp_zip, emp_lname end-select do print-grand-total end-procedure ... ! procedures to print totals for state, city, zip to be called on breaks ! and grand totals using count variables listed above ---------------------------- Example code ends here ------------------------------------------------------- Example output begins here -----------------------EMPLOYEES BY CITY, STATE, AND ZIP CODE State City ----- -----------------------------CA Long Beach Zip Code ---------90806-1234 Name -------------------Evans, Edgar King, Marsha Street

14 Apple Way 27 Kings Road

-----------------------------------------------------# of Employees with zip 90806-1234: -----------------------------------------------------90064-5678 Mitchell, Pete O'Brian, Tom

33 Smokey Drive 7 Palmer Street

-----------------------------------------------------# of Employees with zip 90806-5678: ------------------------------------------------------------------------------------------# of Employees in Long Beach: 4 --------------------------------------

Los Angeles

90064-1234

Flynn, Erin

19 Will Road

-----------------------------------------------------# of Employees with zip 90o64-1234: ------------------------------------------------------------------------------------------# of Employees in Los Angeles: 1 --------------------------------------------------------------------# of Employees in CA: 1 --------------------------------

---------------------------- Example output ends here -------------------------======================================================================= ========= THE FOLLOWING QUESTIONS PERTAIN ONLY TO EASY SQR ======================================================================= ========= Q: I added a new column to a table and then loaded a stored session (.ESQ) file. The new column is not present in the list of accessible columns. A: When loading the session, use the Full Load option instead of the Quick Load option. This causes Easy SQR to re-read the table and column definitions from the database. ======================================================================= ========= Q: I get the following error when attempting to use the menu options 'Report->Queue Run' and 'Options->Queue Run SQR' in Easy SQR on a UNIX host. (Error 3200) Not allowed to submit a job to the batch queue A: All Easy SQR users must have the ability to use the 'at' command in order to use these menu options. See your system Command Reference Manual for details on how to provide users access to the 'at' command. In addition, Easy SQR

requires that all users have read access to the 'at' control files: 'at.deny' and 'at.allow'. ======================================================================= ========= END OF QUESTIONS PERTAINING ONLY TO EASY SQR ======================================================================= ========= THE FOLLOWING QUESTIONS PERTAIN ONLY TO SQR VERSION 3 ======================================================================= ========= Q: How to use the -F command line flag for multiple reports? A: Lets look at the following example. The program "ex20a.sqr" creates 3 reports. sqr ex20a tutorial/secret -Flabel.lis -Fletter.lis -Flisting.lis ======================================================================= ========= Q: In the above example, what would be the names of the SPF files if we use a -keep command line flag? A: The names will be: label.spf letter.s01 listing.s02 ======================================================================= ========= Q: I ran a program with SQR Version 3 and did not specify either -keep or -nolis. During the running of my program a file with the extension .s01 was present, after the report finished it was gone. Why was this file created. A: The program either created multiple reports or used the last-page command. In both these cases, an SQR Print File (SPF) is created. If neither -keep or -nolis is used, the SPF file is deleted upon completion of the program. ======================================================================= =========

Q: How many DECLARE-PRINTER commands can a program have? A: At the most, one for each printer type (lp, hp, ps) for each report plus one declaration for 'default-lp', one for 'default-ps' and one for 'default-hp'. SQR will produce an error message if you declare two hp printers for the same report (or two ps printers, etc.). SQR will issue an error if you define 'default-ps' twice, etc. ======================================================================= ========= Q: Is a name required in a DECLARE-PRINTER commands? Where is the name used in the program? A: A name is required although the name serves no particular purpose and is not used in the report. SQR checks that you didn't use the same name twice. When you declare 'default-lp', 'default-ps' or 'default-hp', you cannot specify for-reports and you cannot specify the type. ======================================================================= ========= Q: Does DECLARE-PRINTER by itself do anything? A: No, it is only activated by a USE-PRINTER-TYPE command or -PRINTER flag for the type that it defines. This means that if you have a DECLARE-PRINTER for PostScript, the output will not automatically change to PostScript. You need the -PRINTER:PS or USE-PRINTER-TYPE PS. Only then the attributed that you have defined in the DECLARE-PRINTER take affect. ======================================================================= ========= Q: Do I have to have the DECLARE-LAYOUT before a DECLARE-REPORT that uses it? A: No, you can have them in any order. ======================================================================= ========= Q: How do I have different reports generate output for different

printers in the same program? A: You have to place an appropriate USE-PRINTER-TYPE after the corresponding USE-REPORT. For example: ---------------------------- Example code begins here -------------------------begin-program use-report listing use-printer-type ps use-report labels use-printer-type hp use-report form_letter use-printer-type lp do main end-program ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: What's the effect of the -PRINTER command line flag in a multiple report program? A: It overrides the printer type for all the report. ======================================================================= ========= END OF QUESTIONS PERTAINING ONLY TO SQR VERSION 3 ======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 4, NUMBER 2 ======================================================================= ========= Q: When running an SQR report that uses Postscript output (type=POSTSCRIPT in the Declare Printer section), I received the following message: Error: dictful: offending command def A: The solution is to increase the SQRDICT value in the postscri.str file from 50 to 100. This has been done for the postscri.str file that has been

distributed since V2.5. ======================================================================= ========= Q: How do I put single quotes around a column in Easy SQR for Oracle? A: Create the following expression: ''''||column_name||''''. This will only work if the length of the string is at least one character less than the declared width for the database column. ======================================================================= ========= Q: Can I incorporate a logo into my SQR output (versions prior to v3.0.x)? A: Yes, see 2 following examples, the first for PCL, the second for POSTSCRIPT This example is for PCL (it assumes the knowledge of PCL): ---------------------------- Example code begins here -------------------------begin-setup #define record-length 800 declare printer type=HPLASERJET left-margin=.60 top-margin=.75 font=5 line-size=12 point-size=12 char-size=7.2 orientation=portrait end-setup begin-report date-time (1,60) DD-MM-YYYY graphic (20,10,50) horz-line 20 graphic (20,40,5) vert-line 50 graphic (30,10,10) box 20 20 90 graphic (30,22,20) box 20 20 0 print 'SQRIBE' (5,1) print 'Support' (6,1) print 'SQR Supports PCL LOGO !! ' (12,1) do logo do pr-data end-report

begin-procedure c4($new) ! Concatenating the final PCL image. let $_image = $_image || $_ESC || '*b4W' || $new end-procedure begin-procedure c3($new) ! Concatenating the final PCL image. let $_image = $_image || $_ESC || '*b3W' || $new end-procedure begin-procedure pr-data print 'MY TABLES ' (29,22) position (+1) begin-select table_name (+1,23) from user_tables where rownum < 18 end-select end-procedure begin-procedure logo ! Encoding PCL escape sequences that will form the image. encode '<27>' into $esc encode '<27>*p160x40Y' into $image move '*c440H' to $str ! placements let $image = $image || $esc || $str move '*c400V' to $str let $image = $image || $esc || $str move '*c3G' to $str let $image = $image || $esc || $str move '*c2T' to $str let $image = $image || $esc || $str move '*c3P' to $str let $image = $image || $esc || $str print-direct $image move '' to $image encode '<27>*p175x60Y<27>*t75R<27>*r0F<27>*r1A' into $image encode '<7><1><128>' into $str do c3($str) encode '<7><1><192>' into $str do c3($str) encode '<7><1><224>' into $str do c3($str) encode '<7><1><240>' into $str do c3($str)

encode '<7><1><252>' into $str do c3($str) encode '<7><1><254>' into $str do c3($str) encode '<7><1><255>' into $str do c3($str) encode '<7><1><255><128>' into $str do c4($str) encode '<255><255><255><192>' into $str do c4($str) encode '<255><255><255><224>' into $str do c4($str) encode '<255><255><255><240>' into $str do c4($str) encode '<255><255><255><248>' into $str do c4($str) encode '<255><255><255><252>' into $str do c4($str) encode '<255><255><255><254>' into $str do c4($str) encode '<255><255><255><255>' into $str do c4($str) encode '<255><255><255><255>' into $str do c4($str) encode '<255><255><255><254>' into $str do c4($str) encode '<255><255><255><252>' into $str do c4($str) encode '<255><255><255><248>' into $str do c4($str) encode '<255><255><255><240>' into $str do c4($str) encode '<255><255><255><224>' into $str do c4($str) encode '<255><255><255><192>' into $str do c4($str) encode '<7><1><255><128>' into $str do c4($str) encode '<7><1><255>' into $str do c3($str) encode '<7><1><254>' into $str do c3($str) encode '<7><1><252>' into $str do c3($str) encode '<7><1><248>' into $str

do c3($str) encode '<7><1><240>' into $str do c3($str) encode '<7><1><224>' into $str do c3($str) encode '<7><1><192>' into $str do c3($str) encode '<7><1><128>' into $str do c3($str) encode '<27>*rC' into $str let $image = $image || $str print-direct $image ! Printing the concatenated image. end-procedure ---------------------------- Example code ends here ---------------------------This program demonstrates how to include a logo into your SQR POSTSCRIPT document. It assumes POSTSCRIPT syntax knowledge. Steps: 1. Prepare a POSTSCRIPT file drawing the logo. 2. Read that file into your SQR program. 3. Invoke the logo using PRINT-DIRECT command. ---------------------------- Example code begins here -------------------------begin-setup #define record-length 400 declare printer type=POSTSCRIPT left-margin=.60 top-margin=.75 font=3 line-size=12 point-size=12 char-size=7.2 orientation=portrait page-size 66 80 end-setup begin-report do read-logo date-time (1,60) DD-MM-YYYY print 'POSTSCRIPT OUTPUT' (2,60) graphic (20,10,50) horz-line 20

graphic (20,40,5) vert-line 50 graphic (30,10,10) box 20 20 90 graphic (30,22,20) box 20 20 0 print-direct '30 50 10 9 2.00 0.03 box' print 'SQRIBE Support' (5,1) print-direct '50 700 0.3 OurLogo' do pr-data end-report begin-procedure read-logo ! Opening, reading and closing the file input $psfile type=char ! containing the PS logo code. open $psfile as 1 for-reading record={record-length} status=#stat if #stat != 0 stop end-if while not #end-file read 1 into $record:{record-length} print-direct $record ! Printing LOGO. end-while close 1 end-procedure begin-procedure pr-data ! Procedure getting data from database. print 'MY TABLES ' (29,22) position (+1) begin-select table_name (+1,23) from user_tables where rownum < 18 end-select end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 4, NUMBER 3 ======================================================================= ========= Q: How do I pass a negative number as a command line argument to SQR? A: Use double minus sign. For example: sqr report username/password --123

======================================================================= ========= Q: Are ORACLE OPS$ accounts supported in a connect string for SQR? A: Yes. After login as an OPS$ user, the SQR command is: sqr report /@t:machine:database ======================================================================= ========= Q: How can I get the system date into SQR when not running the report against a database? A: Do the following (unix example): ---------------------------- Example code begins here -------------------------begin-report call system using 'date > date.out' #status open 'date.out' as 1 for-reading record=80 read 1 into $date:80 print $date (,70) close 1 call system using 'rm date.out' #status end-report ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How do I use 'Call System Using' to run a DOS command in SQR for Windows? A: Prior to SQR version 2.5 you needed to know the value for the COMSPEC environment variable (e.g. C:\DOS\COMMAND.COM). The command would be: call system using 'C:\DOS\COMMAND.COM /C doscommand' #status

In version 2.5, make use of the getenv function of the let command to read the value of COMSPEC. The steps would be: let $CMD = getenv('COMSPEC') || ' /C doscommand' call system using $CMD #status

======================================================================= ========= Q: How can I use an environment variable as part of the path in a #INCLUDE statement? A: Pass the environment variable as a command line argument and utilize it as a substituion variable in the report. For example: 1) set the environment variable (Bourne or Korn shell): INCLUDEDIR=/directory_path;export INCLUDEDIR 2) run SQR report: sqr report username/password $INCLUDEDIR ---------------------------- Example code begins here -------------------------begin-report do main end-report begin-setup ask includedir end-setup begin-procedure main #include '{includedir}/file.inc' end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Does SQR support use of ORACLE PL/SQL blocks and stored functions and procedures? A: PL/SQL blocks have been supported since version 2.26 within Begin-SQL paragraphs. The syntax for PL/SQL statements within SQR is identical to that which is used in both PRO*C and the ORACLE Call Interfaces with the following exception: SQR requires any statement within the PL/SQL block that is normally terminated with a semi-colon (;) to end in two semi-colons (;;). SQR will not attempt to validate PL/SQL syntax. If the PL/SQL block

contains errors, ORACLE will respond with the appropriate error message. SQR versions 2.4 and beyond have the capability to run stored procedures in ORACLE version 7. If the following function exists in the database: create function get_dept_no (dept_name in varchar) return number is dept_num number; begin select deptno into dept_num from dept where dname = dept_name; return(dept_num); exception when no_data_found then return(0); end; It can be accessed from SQR by running it in a Begin-SQL paragraph. ... move 'ACCOUNTING' to $dept_name begin-sql begin #dept_number := get_dept_no($dept_name);; end;; end-sql if #dept_number = 0 show 'Department not found' else do upd_emp_sal end-if ... ======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 5, NUMBER 1 ======================================================================= ========= Q: How can I print the output file from inside my SQR program on DOS, Windows,

Unix, and VMS platforms? A: Close the existing output file with the new-report command and then call the system command processor to print the file. The version 3 SQR variable $sqr-platform is tested to determine what platform the program is running on. ---------------------------- Example code begins here -------------------------begin-program do main move $sqr-report to $orig_report new-report 'junk.lis' evaluate $sqr-platform when = 'DOS' let $cmd = 'print ' || $orig_report when = 'UNIX' let $cmd = 'lp ' || $orig_report when = 'VMS' let $cmd = 'print ' || $orig_report when = 'WINDOWS' let $cmd = getenv('COMSPEC') || ' /C print ' || $orig_report when-other show beep 'Printing not supported for platform ' $sqr-platform end-evaluate call system using $cmd #status end-program ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Does SQR support the use of optimizer hints for the ORACLE database? A: SQR now supports optimizer hints in version 3. The hint must be on the first line of the Begin-Select or Begin-SQL paragraph. For example: ---------------------------- Example code begins here -------------------------begin-select /*+ ALL_ROWS */ empno

ename sal job from emp end-select ---------------------------- Example code ends here ---------------------------For more information about Oracle hints, see Chapter 5 - Tuning SQL Statements of the ORACLE Application Developers Guide. ======================================================================= ========= Q: How do I print subscript and superscript characters for chemical equations and footnote indicators? A: The technique is to double the page length value of the page-size parameter from 60 to 120 and and also double the lines-inch value from 6 to 12. ---------------------------- Example code begins here -------------------------begin-report do main end-report begin-setup page-size 120 80 declare printer type=hplaserjet lines-inch = 12 end-setup begin-procedure main graphic () font 0 16 print 'Footnote' (+1,1) graphic () font 0 8.5 print '1' (1,14) graphic () font 0 16 print 'H O' (+4,1) graphic () font 0 8.5 print '2' (+1,3) end-procedure

! Output will be:

Footnote1

! Output will be:

H2O

---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I change to the lower paper tray on an HPLaserJet or Postscript printer? A: Postscript example: HPLaserjet example: ---------------------------- Example code begins here -------------------------begin-report | begin-report print-direct 'statusdict begin' | encode '<27>' into $esc print-direct '1 setpapertray ' | let $printstr = $esc || '&l2G' print-direct 'end' | print-direct $printstr do main | do main end-report | end-report | begin-setup | begin-setup declare printer | declare printer type = postscript | type = hplaserjet end-setup | end-setup ---------------------------- Example code ends here ---------------------------======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 5, NUMBER 2 ======================================================================= ========= Q: Can a procedure that executes a SQL statement to grant table priveledges be executed from within a select loop? A: A procedure that does a database grant statement cannot be executed from inside of a select loop. This will not work because the grant command is a Data Control Language (DCL) command in ORACLE 6 and a Data Manipulation Language (DDL) command in ORACLE 7. DCL and DDL commands cause a database

commit to occur. This means that the select statement's cursor is closed and the next row context is lost. Using an SQR array to hold the selected data and processing the array after all rows have been selected is how to accomplish this. For example: ---------------------------- Example code begins here -------------------------begin-program do main end-program begin-procedure main create-array name=tables size=1000 field=table_name:char begin-select table_name let tables.table_name(#table_total) = &table_name add 1 to #table_total from user_tables end-select while #current_table < #table_total let $table_name = tables.table_name(#current_table) do grant_privs($table_name) add 1 to #current_table end-while end-procedure begin-procedure grant_privs($table_name) let $grant_string = 'grant all on '||$table_name||' to public' show 'Executing SQL statement: ' $grant_string begin-sql [$grant_string] end-sql end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can unique temporary file names be generated in SQR? A: One technique is to combine the report name (minus the extension)

with the system process ID. The SQR pre-defined variables $sqr-report and #sqr-pid are used. The following example will create a temporary file named techtip1234.tmp for program techtip.sqr ran as process ID 1234. The temporary file is deleted at the end of the procedure. ---------------------------- Example code begins here -------------------------begin-procedure open_tmp_file let $tmpfile = substr($sqr-program,1,instr($sqr-program,'.',1) - 1) || ltrim(edit(#sqr-pid,'999999999999'),' ') || '.tmp' open $tmpfile as 1 for-writing record=80 status = #openstatus if #openstatus != 0 show 'Error opening temporary file: name=' $tmpfile ' status=' #openstatus edit 9999 stop quiet end-if write 1 from 'temporary file data' ... close 1 let #delstatus = delete($tmpfile) if #delstatus != 0 show 'Warning: problem deleting temporary file: name=' $tmpfile ' status=' #delstatus edit 9999 end-if end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 5, NUMBER 3 ======================================================================= ========= Q: How can a 3-Dimensional array be implememted in SQR? A: The following sample program demonstrates how a 3-Dimensional array can be implemented as a 2-Dimensional array. ---------------------------- Example code begins here -------------------------! Sample program to insert values into a 3-Dimensional Array

! and remove values from the Array ! usage: ! insert_a (#value_to_insert, #dimension_1, #dimension_2, #dimension_3) ! retrieve_a (#value_to_remove, #dimension_1, #dimension_2, #dimension_3) ! #define dim_1 3 #define dim_2 3 #define dim_3 3 #define dim_2&3 9 begin-setup create-array name=3_dimensional_array size={dim_1} field=item:number:{dim_2&3} end-setup begin-program do main end-program begin-procedure main move 0 to #count move 0 to #D1 while #D1 < {dim_1} move 0 to #D2 while #D2 < {dim_2} move 0 to #D3 while #D3 < {dim_3} do insert_a (#count,#D1,#D2,#D3) add 1 to #count add 1 to #D3 end-while add 1 to #D2 end-while add 1 to #D1 end-while while 1 input $D1 'Dimension 1' input $D2 'Dimension 2' input $D3 'Dimension 3' move $D1 to #D1 move $D2 to #D2 move $D3 to #D3

if (#D1 >= {dim_1}) or (#D2 >= {dim_2}) or (#D3 >= {dim_3}) display 'Out of Array Range' break end-if do retrieve_a (#value,#D1, #D2, #D3) display #value end-while end-procedure begin-procedure insert_a (#value, #D1, #D2, #D3) let #t = ({dim_3} * #D2) + #D3 let 3_dimensional_array.item(#D1,#t) = #value end-procedure begin-procedure retrieve_a (:#value,#D1, #D2, #D3) let #t= ({dim_3} * #D2) + #D3 let #value = 3_dimensional_array.item(#D1,#t) end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can the return status from running an SQR program be checked in a Unix script to determine if the program finished successfully? A: This script demonstrates checking return status. The : is required at the top of the script so that it will run in any Unix shell. ---------------------------- Example code begins here -------------------------: sqr program1 username/password -xb if [ $? = 0 ]; then echo 'First SQR program worked' > sqrscript.log sqr program2 username/password -xb if [ $? = 0 ]; then echo 'Second SQR program worked' >> sqrscript.log sqr program3 scott/tiger -xb if [ $? = 0 ]; then echo 'Third SQR program worked' >> sqrscript.log else echo 'Third SQR program failed' >> sqrscript.log fi

else echo 'Second SQR program failed' >> sqrscript.log fi else echo 'First SQR program failed' >> sqrscript.log fi ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can Oracle Trace files be created for an SQR program? A: Oracle Trace files will be created if an Alter Session command is performed to set sql_trace to true. The command should be done in the Begin-Setup section, otherwise the Explain Plan function of TKPROF will produce all desired information. ---------------------------- Example code begins here -------------------------begin-setup begin-sql alter session set sql_trace true end-sql ... end-setup ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Printed output from an SQR program is splitting over two pages. What can be done to prevent this? A: On a Unix host, print the output file with the command: lp -oraw filename.lis On a VMS host, print the output file with the command: print/passall filename.lis ======================================================================= ========= Q: How can the first character of a string be changed to uppercase?

A: Do the following: let $string = upper(substr($string,1,1)) || substr($string,2,length($string) - 1)

Q: How do I convert an SQR version 2.5 layout to a version 3.0 layout? A: SQR3 (version 3.0) maintains full upward compatibility for reports that were developed using earlier versions of SQR. However, to take advantage of the new printer-independent and multiple reports features of SQR3, you need to stop the use of certain commands that are becoming obsolete and use new commands, instead. This document provides the details to help you migrate old commands to new ones. Old Ccommand ----------------PAGE-SIZE DECLARE PRINTER Equivalent New Command ------------------------------------DECLARE-LAYOUT paper-size and margins DECLARE-PRINTER, USE-PRINTER-TYPE and ALTER-PRINTER ALTER-PRINTER font DECLARE-PROCEDURE and USE-PROCEDURE DECLARE-PRINTER init-string DECLARE-PRINTER reset-string BEGIN-PROGRAM

GRAPHIC FONT DECLARE PROCEDURE PRINTER-INIT PRINTER-DEINIT BEGIN-REPORT

If you used the command Page-Size the following maintains the same formatting in SQR3. This will enable you to do multiple reports etc. ---------------------------- Version 2.5 code begins here ---------------------Begin-Setup Page-Size 60 120 End-Setup

Begin-Procedure declare_hp Declare Printer type = hplaserjet lines-inch = 8 chars-inch = 12 font = 5 orientation = landscape End-Procedure Begin-Procedure main your report commands End-Procedure Begin-Report Do declare_hp Do main End-Report ---------------------------- Version 2.5 code ends here --------------------------------------------------- Version 3.0 code begins here ---------------------Begin-Setup Declare-Printer Printer1 for-reports = (report1, report2) type = hplaserjet font= 5 End-Declare !declare-printer Declare-Report report1 layout= layout1 printer-type= hplaserjet End-Declare !declare-report Declare-Report report2 layout=layout1 printer-type=hplaserjet End-Declare !declare report Declare-Layout layout1 paper-size = (11, 8.5) char-width = 6 ! 12 chars per inch line-height = 9 ! 8 lines per inch

orientation = landscape End-Declare !declare layout End-Setup Begin-Procedure main your report commands End-Procedure Begin-Program Do main End-Program ---------------------------- Version 3.0 code ends here -----------------------To convert page-size to char-width and line-height do the following: If you accept the default margins in the example above, the physical page width will be 10 inches. If you modify the Right or Left Margins you must account for this to figure the characters per inch. Divide the cols per page from your page-size defined in version 2.5 by the physical page width as follows: 120/10 = 12 This equals characters (or columns) per inch. We need points for char-width so you need to divide points per inch (72 is the default) by the cols per inch as follows: 72/12 = 6 The point size of char-width

Line height is similar. The default for Top and Bottom Margin is .5 which is why the physical size is 7.5. If you modify the Top or Bottom margins you must account for this here to get the correct lines per inch: 60/7.5 = 8 The lines per inch

Follow the same procedure for calculating the line-height: 72/8 = 9 The point size of line-height

======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM VOLUME 6, NUMBER 1 ======================================================================= ========= Q: How can array sorting be done? A: The following program demonstrates a quick sort. ---------------------------- Example code begins here -------------------------begin-setup create-array name=Array Size=100 field=Field1:char field=Field2:char field=Field3:char ! ! The following array is used by the sort create-array name=QSort size=100 field=n:number field=j:number end-setup begin-program do Main end-program begin-procedure main ! ! Code that fills the array with data goes here. ! #i is the number of rows in the array. ! ... do SortArrayByField1(#i) end-procedure main begin-procedure SortArrayByField1(#rows) do QuickSortArrayByField1(0, 0, #rows) end-procedure SortArrayByField1 !

! QuickSortArrayByField1 ! ! Purpose: Implement Sort of an array this is a recusive function. ! Since SQR does not allocate ! local variables on the stack (they are all static, the ! recursive behavior employs a helper array) ! ! #level - Recursion level (used as a subscript to the helper array) ! #m - The "m" argument of the classical Quick Sort ! #n - The "n" argument of the classical Quick Sort ! begin-procedure QuickSortArrayByField1(#level, #m, #n) if #m < #n let #i = #m let #j = #n + 1 let $key = Array.Field1(#m) while 1 add 1 to #i while #i <= #j and Array.Field1(#i) < $key add 1 to #i end-while subtract 1 from #j while #j >= 0 and Array.Field1(#j) > $key subtract 1 from #j end-while if #i < #j do QSortInterchange(#i, #j) else break end-if end-while do QSortInterchange(#m, #j) add 1 to #level ! Save #j and #n let QSort.j(#level - 1) = #j let QSort.n(#level - 1) = #n subtract 1 from #j do QuickSortArrayByField1(#level, #m, #j) ! restore #j and #n let #j = QSort.j(#level - 1) let #n = QSort.n(#level - 1) add 1 to #j do QuickSortArrayByField1(#level, #j, #n) subtract 1 from #level end-if

end-procedure QuickSortArrayByField1 ! ! QSortInterchange ! ! Purpose: Swaps records #i and #j ! ! #i - Array subscript ! #j - Array subscript ! begin-procedure QSortInterchange(#i, #j) get $Field1 $Field2 $Field3 from Array(#i) let Array.Field1(#i) = Array.Field1(#j) let Array.Field2(#i) = Array.Field2(#j) let Array.Field3(#i) = Array.Field3(#j) put $Field1 $Field2 $Field3 into Array(#j) end-procedure QSortInterchange ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I automatically e-mail SPF files from a Unix host to a PC client so that the SQR Viewer can be used to view the output. A: The following program demonstrates using the Unix uuencode and mail commands to e-mail SPF files. Associating the extensions .SPF and .S01 with the SQR Viewer application on the PC, allows invoking the Viewer from within a mail package such as cc:MAIL. ---------------------------- Example code begins here -------------------------begin-setup declare-report report1 end-declare declare-report report2 end-declare end-setup begin-program use-report report1 print 'test1' (1,1) unstring $sqr-report by '.' into $filename1 $extension1

new-report 'junk1.lis' use-report report2 print 'test2' (1,1) unstring $sqr-report by '.' into $filename2 $extension2 new-report 'junk2.lis' let $spf1 = $filename1 || '.spf' let $spf2 = $filename2 || '.s01' let $cmd = 'uuencode ' || $spf1 || ' ' || $spf1 || ' > mailfile' call system using $cmd #status let $cmd = 'uuencode ' || $spf2 || ' ' || $spf2 || ' >> mailfile' call system using $cmd #status call system using 'mail -s "SPF Files" johnk@sqribe.com < mailfile' #status end-program ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: How can I perform date arithmetic for databases that SQR supports? A: The following program demonstrates calculating the difference between the current date and an input date for the Informix, Ingres, Oracle, SQLbase and Sybase databases. ---------------------------- Example code begins here -------------------------begin-report ! ! Formats are: ! Informix MM-DD-YYYY ! Ingres DD-MON-YYYY [HH:MI:SS] ! Oracle DD-MON-YY ! SQLbase DD-MON-YY or DD-MON-YYYY ! Sybase MON DD YYYY ! input $date 'Please enter date in proper DB format' type=date do main end-report begin-procedure main let $sqlbase_expression = 'sysdate - ' || $date

begin-select loops=1 #if {sqr-database} = 'INFORMIX' today - date($date) &result from table #endif #if {sqr-database} = 'INGRES' date('today') - $date &result #endif #if {sqr-database} = 'ORACLE' to_date(sysdate) - to_date($date,'dd-mon-yy') from table #endif #if {sqr-database} = 'SQLBASE' [$sqlbase_expression] &result=number from table #endif #if {sqr-database} = 'SYBASE' datediff(day, $date, getdate()) #endif end-select

&result

&result

if $sqr-database = 'INGRES' show 'The result is: ' &result else show 'The result is: ' &result ' days' end-if end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: I get the error: "tar: tape input or output error" when attempting to read the SQR installation tape on my IBM RS6000. What is the problem? A: The default block size for tape devices on the platform is 1024 bytes. The default on most Unix platforms is 512 bytes. SQRIBE creates installation tapes with block size of 512. To change the block size on your IBM

RS6000, run the System Management Interface Tool (smit) utility as a user with appropriate privileges and change Block Size from 1024 to 512 in the menu selection path: Devices-->Tape Drive-->Change or Show Characteristics of a Tape Drive Or, manually run the command: '512' chdev -l device_name -a block_size=

======================================================================= ========= Q: How can I reset the page number that is printed with the PAGE-NUMBER command? A: Move the desired value to the #PAGE-COUNT reserved variable. For example: move 1 to #page-count. ======================================================================= ========= Q: How do I right justify a text string? A: Use the LPAD function of the LET command to add blanks to the start to the string. For example: let $s = lpad($s, 80, ' ') ======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM FROM SUMMER 1997 ======================================================================= ========= Q: Is there a document with Frequently Asked Questions for SQR? A: The file is called FAQ.TXT and resides in the README directory when SQR is installed. ======================================================================= ========= Q: Is there a way to replace every occurrence of a word in a character string with another word?

A: The following procedure demonstrates how this can be done: ---------------------------- Example code begins here -------------------------begin-procedure replace_word_in_string (:$string, $oldword, $newword) move 1 to #pos let #oldlen = length($oldword) while instr($string, $oldword, #pos) let #pos = instr($string, $oldword, #pos) let #newpos = #pos + #oldlen let $string = substr($string, 1, #pos - 1) || $newword || substr($string, #newpos, length($string) - (#newpos 1)) move #newpos to #pos end-while end-procedure ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Can dynamic SQL be used in a GROUP BY clause? A: Before version 3, the GROUP BY clause below gave an error. It will work in version 3 by using the FROM clause shown below: ---------------------------- Example code begins here -------------------------let $table = 'table' let $col1 = 'col1' begin-select col1 sum(col2) &sumcol2 from [$table] group by [$col1] end-select ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Is there a function for checking if a number is an integer? A: This can be accomplished as follows:

---------------------------- Example code begins here -------------------------if (#number - floor(#number) = 0) display 'The number is an integer' else display 'The number is not an integer' end-if ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Is there a way for SQR to pause when running a program? A: The CALL SYSTEM USING command can be used to accomplish this. The following code demonstrates how to pause for 10 seconds on UNIX and VMS platforms: ---------------------------- Example code begins here -------------------------evaluate $sqr-platform when = 'UNIX' call system using 'sleep 10' #status ! Parameter is seconds break when = 'VMS' call system using 'wait 00:00:10' #status ! Parameter is hours:minutes:seconds break end-evaluate ---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Is it possible to print rotated text when producing Postscript output? The following program demonstrates how to rotate text 90, 180, and 270 degrees: ---------------------------- Example code begins here -------------------------begin-program use-printer-type postscript print '0 degree 1,1' (1,1) ! Print line at 0 rotation

print-direct 'statusdict begin' print-direct '90 rotate' print-direct '0 -792 translate' print '90 degree 1,1' (1,1) degrees print '90 degree 2,1' (2,1) print '90 degree 3,1' (3,1) print '90 degree 4,1' (4,1) print-direct '-90 rotate' print-direct '-792 0 translate' print '0 degree 2,1' (2,1) print-direct '180 rotate' print-direct '-612 -792 translate' print '180 degree 1,1' (1,1) degrees print '180 degree 2,1' (2,1) print '180 degree 3,1' (3,1) print '180 degree 4,1' (4,1) print-direct '180 rotate' print-direct '-612 -792 translate' print '0 degree 3,1' (3,1) print-direct '270 rotate' print-direct '-792 -180 translate' print '270 degree 1,1' (1,1) degrees print '270 degree 2,1' (2,1) print '270 degree 3,1' (3,1) print '270 degree 4,1' (4,1) print-direct '90 rotate' print-direct '180 -792 translate' print '0 degree 4,1' (4,1) print-direct 'end' end-program

! Rotate 90 degrees

! Print four lines rotated 90

! Rotate back to 0

! Print line at 0 rotation ! Rotate 180 degrees ! Print four lines rotated 180

! Rotate back to 0

! Print line at 0 rotation ! Rotate 270 degrees ! Print four lines rotated 270

! Rotate back to 0 ! Print line at 0 rotation

---------------------------- Example code ends here ---------------------------======================================================================= ========= Q: Does SQR support HTML output? A: SQR version 4 added the ability to generate HTML output with the -PRINTER:HT flag.

======================================================================= ========= Q: Is SQR year 2000 compliant? A: SQR version 4 now supports a new class of variables: DATE. This variable class can support dates from 4713BC to 9999AD. SQR provides the following functions to manipulate and manage this variable class: dateadd, datediff, datenow, datetostr, and strtodate. ======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM FROM WINTER 1997 ======================================================================= ========= Q: Why does the SQR Workbench use ODBC to connect to a database? Is all database access done via ODBC? A: The SQR Workbench uses Open DataBase Connectivity to display users, tables and columns, and to validate the syntax of queries and expressions. When a report is run, the Workbench invokes an SQR language engine that uses a native database connection instead of the ODBC connection. This allows one SQR Workbench to work with many SQR engines. When software corrections are made to an SQR engine, no changes are necessary in the Workbench. ODBC drivers for DB2, Informix, OpenIngres, Oracle7, SQLBase, SQLServer and Sybase are provided with the Workbench installation. We strongly recommend using the provided ODBC drivers instead of drivers from other sources. ======================================================================= ========= Q: How can you disconnect from the database and reconnect with a different data source? A: Close all existing editor and layout windows; then choose the 'Logon To Database' option of the File menu and walk through

selection of a new data source. ======================================================================= ========= Q: How can a run-time file (.SQT) be saved in the Workbench? A: Select 'Report Run' and enter the -RS flag in the Parameters box. The Workbench will display a message box stating that the report ran successfully, but no output was generated. This is normal because only a .SQT file was created and no output is expected. ======================================================================= ========= Q: How can syntax such as HAVING, INTERSECT, GROUP BY, MINUS and UNION be used in a query? A: The 'Exploded Where-List' is used to enter free form text that can include the above SQL commands. The 'Exploded Where-List' is accessible via the Exploded button of the Where Clause box in the Query Builder. ======================================================================= ========= Q: How can data be sorted in descending order? A: Use the 'Sort Mode' button in the Order By List to toggle between ascending and descending order after choosing one or more database columns to sort by. ======================================================================= ========= Q: How can an aggregate function be added to a report? A: Aggregate functions such as MAX, MIN and SUM are added via the 'Create Expression' box in the Layout window. Click on the 'X+Z' radio button and then 'New' to add the expression. Give it a name and an expression definition, such as 'sum(salary)'. After clicking on OK, the expression will be added to the query tree and can be dragged into place on the layout screen. Use of aggregate functions also requires definition of a GROUP BY clause in the Exploded Where-List.

======================================================================= ========= Q: How can DISPLAY and SHOW commands be directed to the screen instead of to the SQR.LOG file? A: Enter the -CB flag in the Parameters box when running the report to tell the Workbench to send output to the Communication Box. ======================================================================= ========= THE FOLLOWING QUESTIONS APPEARED IN THE SQRIBE FORUM ON-LINE JULY 1998 ======================================================================= ========= Q: How can an outer join be specified in PowerSQRIBE? A: Outer joins are defined by editing the SQL statement using "View or modify the SQL command for your query" in the SQL Editor step. The proper outer join syntax for the target database must be used. ======================================================================= ========= Q: How can the OR operator be used instead of AND when creating query conditions? A: After creating two or more conditions, highlight the desired AND in the condition box and then use the AND/OR toggle selection below. ======================================================================= ========= Q: What are the different ways to create expressions in the Expression Builder? A: Any of the following methods can be used: - Type the function and column name in the Expression field - Drag a function and drop it on the target column - Drag and drop a function or column to the Expression field - Double-click a function or column to enter it into the Expression field ======================================================================= ========= Q: How can PowerSQRIBE Unplugged be configured to use the Oracle Thin

JDBC driver? A: Follow these steps: - Unzip the driver classes file (classes111.zip) starting at the PowerSQRBE\lib directory - Add an entry for the driver in the file drivers.dat. Currently, the file only has following entry: sun.jdbc.odbc.JdbcOdbcDriver. Add the main class name for the driver: oracle.jdbc.driver.OracleDriver - Create a new database in PowerSQRIBE Unplugged with the following JDBC Driver: "oracle.jdbc.driver.OracleDriver" and the following URL: "jdbc:oracle:thin:@hostname:port:SID" For example if you want to connect to the database on host "myhost" that has a TCP/IP listener up on port 1521, and the SID is "orcl", use URL statement such as: "jdbc:oracle:thin:@myhost:1521:orcl". ======================================================================= ========= Q: How can a DOS command be called on Windows NT so that SQR waits until the command completes? A: The CMD.EXE utility should be used in the following manner (command is the desired DOS command): call system using #status wait 'cmd /c @start /min /wait cmd /c "command"'

======================================================================= ========= Q: How can an SQR string variable ($variable) be determined to contain a numeric value? A: Use the TRANSLATE function of the LET command as follows: if translate($string, '0123456789.', '') = '' show 'The string contains a numeric value' end-if To test for an integer value, don't include the period in the translation string. ======================================================================= ========= Q: What should be done for SQR if the default date format for a database is changed? A: The database date format can be specified using the SQR_DB_DATE_FORMAT environment variable or SQR.INI setting. Environment variables are set via the OS. The following is an example for Unix: SQR_DB_DATE_FORMAT='MM-DD-YYYY' export SQR_DB_DATE_FORMAT To use an SQR.INI entry, put it in the environment section for the database. For example: [Environment:Oracle] SQR_DB_DATE_FORMAT='MM-DD-YYYY'