Вы находитесь на странице: 1из 12

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: 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: Can I set the current page number in an SQR program? A: Yes. Move the desired value to the SQR variable #page-count. Q: Can a .sqt file be "de-compiled" into the original SQR code? A: No. This is not possible. 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

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: 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: 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 #_currentline instead of #current-line . Q: My printer is splitting output from SQR that contains graphics into two pages. Is there anything I can do about it? A: On a Unix host, print the file with: lp -oraw report.lis On a VMS host, print the file with: print/passall report.lis 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: 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: 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: 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 dependant on not having duplicate keys. 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) Graphic (26,1,122) Graphic (29,1,122) Graphic (32,1,122) Graphic (35,1,122) Graphic (38,1,122) Graphic (41,1,122) Do Main End-Report

horz-line horz-line horz-line horz-line horz-line horz-line horz-line

12 12 12 12 12 12 12

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' Print 'Routing/Repair' Print 'Assembly' Print ' # of Avg.Hrs.' Print 'Engines per Engine Print ' # of Avg.Hrs.' Print 'Engines per Engine Print ' # of Avg.Hrs.' Print 'Engines per Engine position (+2) End-Procedure (1,32) (,65) (,100) (3,25) (4,25) (3,59) (4,59) (3,93) (4,93) bold bold bold bold bold bold bold bold bold

Applied%' Applied%' Applied%'

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 (,+3,4) edit 99.9 Print '%' () position (+2) End-Procedure 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' End-Heading

(4,1) bold

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" "whens" Default 100 6 70 2048 200 13515 240 30 900 9000 2500 60 240 4000 10000 100 750 70 Max. Value 65535 6 (SQL Base) 32767 65535 32767 65535 32767 65535 65535 65535 32767 32767 65535 65535 65535 32767 32767 65535

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: y 1) Study carefully the example in SQR Workbench 2.5 User's Guide on p.4-112. y 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 ----CA City ----------Long Beach Zip Code ---------90806-1234 Name -------------------Evans, Edgar King, Marsha Street -------------------14 Apple Way 27 Kings Road

-----------------------------------------------------# of Employees with zip 90806-1234: 2 -----------------------------------------------------90064-5678 Mitchell, Pete O'Brian, Tom 33 Smokey Drive 7 Palmer Street

-----------------------------------------------------# of Employees with zip 90806-5678: 2 ------------------------------------------------------------------------------------------# of Employees in Long Beach: 4 -------------------------------------Los Angeles 90064-1234 Flynn, Erin 19 Will Road

-----------------------------------------------------# of Employees with zip 90o64-1234: 2 ------------------------------------------------------------------------------------------# of Employees in Los Angeles: 1 --------------------------------------------------------------------# of Employees in CA: 1 ----------------------------------------------------------- Example output 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) 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 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 let $newrec = $rec || $pcnt write 2 from $newrec:80 else write 2 from $rec:80 file end-if end-while close 1 close 2 end-procedure ! loop reading records in the lis

! add 1 to page count variable

! test whether the string ! has 'Page' and 'of' ! if so, add the total page to string ! write new line to out file ! otherwise write the line to out

Q: How can I change to the lower paper tray on an HPLaserJet or Postscript printer?
A: Postscript example: HPLaserjet example:

---------------------------- Example code starts 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 --------------------------

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 seperate 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: 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 I have to have the DECLARE-LAYOUT before a DECLARE-REPORT that uses it? A: No, you can have them in any order. 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-PRINTERTYPE PS. Only then the attributed that you have defined in the DECLARE-PRINTER take affect. 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: 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

Вам также может понравиться