SQR Questions
SQR Questions
SQR Questions
What is SQR used for ?
Ans: It is a Reporting Tool for creating customised reports to be run from PeopleSoft
panels for formatting reports, data transfer, data uploading/downloading etc.
How SQR identifies where we keep sqr files (Path of SQR files)?
Ans: It is specified in Configuration Manager.
3) Which SQC file is used for From Date and To Date.
Ans: AskEfdt.sqc
How do we Debug SQR ?
Ans: a) by using #Debug, or #Ifdef Debugx #endif.
using Show or Display command.
How do you Optimise SQR ?
Ans: a) You can optimise SQR by breaking big sql statements into simple sql statements.
What are Open & Read functions of file opening in SQR ?
Ans: Open ‘Vendor.dat’ as 1 for-reading record=50:vary
Open ‘C:\sqrtemp\vendor2.txt’ as #1 for-writing record=93:FIXED
If #filestat=0 (file opened successfully)
Write #1 FROM $iSalVCode:3
End-If
How do we Concatenate String in SQR ?
Ans: Using Concat function or || as pipes.
How do we work on Effective dated rows on SQR ?
Ans: Write a subquery to get current effective date & then write an outer query for matching
effective dated rows from a record.
How do I Reference Global variable in a local procedure in SQR ?
Ans: I can access Global variable with #_VariableName from local procedure.
How do you Declare a local procedure in SQR ?
Ans: Using Begin-Procedure <procedurename> local
How do you Place a Date into Heading Section of SQR ?
Ans Use Date-Time function in SQR & Page-Number.
How do you trap Errors in SQR ?
Ans: a) Using BEGIN-SELECT ON-Error=ErrorProcedureName
b) In procedure display #SQL-Error to show ErrorNumber & $SQL-Error to display
message.
What the use of ON-Break in SQR ?
Ans: Syntax: ON-Break Level=1 skiplines= 4 After = ProcedureName vcc
Usage: It is used to group set of records for each level & break at each level.
What is a syntax of LoadLookup ?
Ans: It is declared in Begin-Setup.
Syntax: Load-Lookup Name=<name>
Table = <tablename>
Key = <primarykey>
Return_value = <FieldName>
Where = FIELDNAME= <fieldname>
What are the statements used in Begin-Procedure ?
Ans: Begin-SQL, Begin-Select, Begin-Document etc.
21) What is a difference between Begin-Select & Begin-SQL ?
Ans: BEGIN-SELECT has only one SQL statement.
BEGIN-SQL can have any number of DML statements & it can also have PL-
SQL statements for oracle & each statement should end with double semi colon (;;).
22) Can Multiple Columns be retrieved in LoadLookup command in SQR ?
Ans: Yes, it has to be joined by a double pipe symbol ( || ).
23) Which SQC tells you that some Job is completed ?
Ans: Eoj.sqc tells you about that.
24) Which SQC is responsible for system memory allocations ?
Ans: AllMaxes.max
How do you control the number of iterations or fetch records firing SQL statement in
SQR.
Ans: By using Begin-Select Loops=<number> statement.
What SQC’s you have written while customisation.
Ans:
How do you Enter a line in an SQR ?
Ans: Print ‘-’ (y,x,100) FILL
How do you know in SQR on which cursor position you are residing ?
Ans: #Cursor-pos
How do you Use XLATT table in SQR ?
Ans: a) Include ReadXlat.sqc.
b) Put values into $fieldName, $fieldValue
c) Call procedure read-translate-table
d) Get $XLATLongName & $XLATShortName from XLATTABLE of PeopleSoft
database.
How do you Define arrays in SQR ?
Ans: Syntax: #define array-size 50
Begin-Setup
CREATE-ARRAY NAME=<arrayname> SIZE=<size>
FIELD=<fieldname>:<DataType>:<Size>
End-Setup
How do you differentiate printing a database column & any other variable in a select
statement ?
Ans: Database fields should start with the 1st column.
Indent other print statements with at least one column right.
How do you print a document/letter using SQR ?
Ans: Using Begin-Document, End-Document in a procedure.
Call this procedure before From Clause in Begin-Select to print for each record.
What is a difference between EDIT & Format in SQR ?
Ans: EDIT is used for formatting while printing & Format is used while Input specially
for date.
How do you put a blank line in Begin-Document End-Document ?
Ans: Using .b
What is STOP QUIET used for in SQR ?
Ans: Stops execution of SQR & come out of it.
How do you refer to a Constant in SQR ?
Ans: A constant is referred in curly braces { }.
How do you Execute SQR using Process Scheduler ?
Ans : a) Include some RunControl panel having OperatorID & RunCntlID.
b) This panel includes PRCSRUNCNTRL table & RUNCNTRL table having
OperatorID & RunCntlID.
c) Add your own input fields to this RunControl record & also drag drop it
onto your panel.
Write procedure into SQR code which would have an SQL statement to fetch
you fields from RUNCNTL table. Remark all input fields. Execute this procedure
in else part of If $prcs_process_instance = ‘’ which means that this sqr is to be
executed from Process Scheduler.
How to Avoid double declaration of an SQC file ?
Ans: To check this write all procedure of an SQC in the following :
#Ifdef <constant>
#define <constant>
<write all procedures of an sqc file>
#endif
What Commands are used to show Output on Screen of an SQR at runtime ?
Ans: Display & Show are the commands for that.
Difference between SQR/Crystal/nVision ?
SQR ReportCrystal ReportNVision ReportGUI It does not provide GUI interface to
create reports. It provides GUI Interface for creating reports. It provides GUI Interface
for creating reports. Interface writing. Uploading/Downloading data from flat file to PS
& vis-a-versa.Cannot be used for Interface writing.Cannot be used for Interface
writing.Programming Language SQR language for reporting is a programming language
in which you can create your own SQC’s libraries for reusability & also you can hold
intermediate data for processing etc. You cannot write complex programs, at the most
you can use few If-Else statements based on the data fetched. You cannot hold
intermediate data.Only prints reports based on PSQueries. Excel Specific Output
SQR Report output can be on text file, word document etc. Crystal Report output can be
of any type.It provides output only for Excel spreadsheets.
What are the Common Flags used for SQR’s ?
-A : Causes reporting output to be appended to an existing file of the same name.
-C : Cancel dialog box appears so that user can terminate the program.
-DEBUG: Used in conjunction with #debug command to display additional
information when troubleshooting SQR programs.
-E : Specifies that an error file be created and allows you to specify the filename.
-I : Location of *.SQC or other include program files.
-F : Specifies a file or directory where the *.lis file should be created,
instead of in the default location.
-O : Filename for the log file.
-RS : Creates a runtime version of your SQR. Creates a file with the *.sqt
extention. PeopleSoft does not use runtime SQR programs.
-M :SQR configuration file. Used to modify default SQR
properties(AllMaxes.max)
-PRINTER : Causes printer type to be specified.
-S :Displays the status of the all cursors at the end of the run. This is used for
troubleshooting SQR programs.
-Tnn : Specifies you to run SQR in test mode for the specified(nn) number of
pages.
-CB : Forces communication box.
-XCB :Do not use communication box. Request for input will be made in Windows
dialog boxes.
42) How can I suppress display of the SQR banner line when running SQR ?
Ans: Use the -XB flag.
43) Are SQR commands and variables case sensitive ?
Ans: No. Commands can be spelled with any case combination. The SQR variable $string is
equivalent to $STRING.
44) Do SQR programs require a .sqr extension? Do SQR runtime files require a .sqt
extension ?
Ans: SQR programs do not require a .sqr extension. SQR runtime files require a .sqt
extension.
45) Can a .sqt file be "de-compiled" into the original SQR code ?
Ans: No. This is not possible.
46) What is the limit for SQR command line length on PC/Windows ?
Ans: 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.
47) Can I set the current page number in an SQR program ?
Ans: Yes. Move the desired value to the SQR variable #page-count.
48) What is the maximum record length for the OPEN command ?
Ans: The maximum is 32K bytes (32767).
49) How can I read in variable length delimited fields from a sequential file ? An example
format would look like this: field1|field2|field3|...
Ans: 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 :
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
50) 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.
Ans: When doing the insert, list only the fields for which a value is known. All other fields
will get the null value.
51) If I get a duplicate key warning message when SQR loads a lookup table, will the lookup
table still work correctly.
Ans: No. Use of a lookup table is dependent on not having duplicate keys.
52) How can I find out if rows are selected by a BEGIN-SELECT paragraph? Can I use the
SQR variable #sql-count?
Ans: #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. The solution is here below:
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
53) What is the value used with -C flag of BEGIN-SELECT?
Ans: 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.
54) Can I write a matrix report in SQR ?
Ans: Yes. Example of a SQR cross-tab (matrix) report
Example:
Begin-Setup
Page-Size 60 133
declare printer
type = postscript
orientation = landscape
line-size = 8
char-size = 6
End-Setup
55) Can I use 'dynamic column names' in Begin-Select (versions prior to v3.0)?
Ans: 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:
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
56)How can I prevent the printing of the empty page at the end of every
.LIS file?
Ans: 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.
57) In BEGIN-SELECT do the FROM and WHERE clause have to be aligned to the left
margin ?
Ans: No. Only the selected columns have to be.
58) How to use the -F command line flag for multiple reports ?
Ans: Lets look at the following example. The program "ex20a.sqr" creates 3 reports.
Example:
sqr ex20a tutorial/secret -Flabel.lis -Fletter.lis -Flisting.lis
59) In the above example, what would be the names of the SPF files if we use a -keep
command line flag ?
Ans: The names will be:
label.spf
letter.s01
listing.s02
60) How many DECLARE-PRINTER commands can a program have ?
Ans: 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.
61) Do I have to have the DECLARE-LAYOUT before a DECLARE-REPORT that uses it?
Ans: No, you can have them in any order.
62)How do I have different reports generate output for different printers in the same program
?
Ans: You have to place an appropriate USE-PRINTER-TYPE after the corresponding USE-
REPORT. For example:
Example:
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
63) What's the effect of the -PRINTER command line flag in a multiple report program?
Ans: It overrides the printer type for all the report.
64) How can unique temporary file names be generated in SQR ?
Ans: 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.
65) How can I reset the page number that is printed with the PAGE-NUMBER command?
Ans: Move the desired value to the #PAGE-COUNT reserved variable. For example:
move 1 to #page-count.
66) How do I right justify a text string ?
Ans: Use the LPAD function of the LET command to add blanks to the start to the string.
For example: let $s = lpad($s, 80, ' ')
67) Standard SQCs
Askftd.sqc - This asks from/thru date for reporting of heading
Askaod.sqc - Procedure to call is Ask-As-of-Date
CurDtTim.sqc - Gets the Current Date Time from System
DateTime.sqc - Convert date from system format calling InitDate-Time procedure
to set format.
DateMath.sqc - Converts Native Date format to YYYY-MM-DD.
Eoj.sqc - determines End of job for an SQR report.
FSHdg01.sqc,FSHdg04.sqc - for Standard Headers for PS Financials.
Number.sqc - Provides Number related Functions
Opsys.sqc - Operating system settings.
PrcsApi.Sqc - Used in Process Scheduler SQR Programs, to get Run control
parameters
RDBMS.sqc - Database Settings. These files uses #DEFINE command to set the
variables.
ReadXlat.sqc - Read the Translate Table for the desired values (Very Important)
Reset.sqc - Used for Footing Section that prints ‘End-of-Report’.
SetEnv.sqc - Sets Environment for Country, Printer-Paper, Language, Date,
Platform specific parameters, It also contains Opsys.sqc, RDBMS.sqc
Setup01.sqc - This is generally called from Begin-Setup section for Portrait Size
Setup02.sqc - This is generally called from Begin-Setup section for Landscape Size
STDHDGTR.sqc - Performs Language Conversion
STDHDG01.sqc - Provides Standard heading for language conversion
StdApi.sqc - Gets Std API calls
Trancntrl.sqc - Purpose is to COMMIT, ROLLBACK etc. across DB platforms
Convertcurrency.sqc
AllMaxes.max - It is used for dynamic memory allocations before the execution
of SQR.
68) What is Declare-Layout <layoutname> used for ?
Ans: It is used for defining Page Layout & includes Paper Size, Margins in Begin-Setup.
Such as Left-Margin = 1, Top-Margin=1.
69) What is Master Detail Report ?
Ans: Report where tables with one to many relationships are involved.
Project, Tasks, Resources, Efforts. On-Break Level =1 etc.
70) How do you run SQR Report from DOS Prompt using a Batch File ?
Ans: C:\FDM75SU\sqrbinw\SQRW.EXE c:\sqrtemp\%1.sqr
EPDMO/SYSADM/SYSADM -Ic:\FDM75SU\sqr\ <IncludeFile Path>
-Mc:\FDM75SU\sqr\AllMaxes.max -Oc:\SQRTEMP\sqr.log(LogFile)
-Fc:\sqrtemp\%1.lis(Output File)
-ZIFc:\FDM75SU\sqr\Pssqr.ini -lockrl
REM -XCB (do not display Communication Box)
71) What is a Syntax for using SQC's in SQR ?
Ans: #include 'setenv.sqc'.
72) What is #, $, & used for ?
Ans: #Numeric, $String, and &Database field values.
73) How to print current date in SQR ?
Ans: Print $current-date (1,1) EDIT ‘DD/MM/YYYY’ or use internal function or
DateNow for current date & time.
74) How to Define Constant & its usage in Begin-Select:
Ans: #define MAX_LABEL_LINES 10
75) Functions (Most commonly used)
Ans:
Isnull- Returns a value of 1 if source_val is null, otherwise returns a value of 0.
Instr- Returns the numeric position of sub_value in source_value or 0 if not found.
Length- Returns the number or characters in source_value.
Lpad- Pads the source_value on the left to a length of length_value using pad_value and
returns the result.
Ltrim- Trims characters in source_value from the left until a character is not in set_value
and returns the result.
Nvl- Returns y_value if the x_value is null, otherwise returns x_value.
Example: let $city = nval(&city, ‘-- not city -‘)
Round(#avg_length,0)
Substr- Extracts the specified portion of source_value.
To_char- , To_Number,
String-This creates a string, Opposite of this is Unstring
Extract-Copies a portion of a string into string variables generally used in file
manipulations. Example: EXTRACT $area_code from &home_phone 0 3
Print is most commonly used stmt. Show and Display are also used
Evaluate
Example: EVALUATE<variable>
WHEN = <value>
WHEN = <value>
WHEN-OTHER
<default SQR command(s)>
END-EVALUATE
SQR provides internal, reserved variables with values maintained & updated by SQR.
#Current-Line : Current physical line on a page
$Current-Date : Current date time on the local machine when sqr is running.
#Current-Column : Current column on page.
#Page-Count : Current page number (can be reset).
#End-File : set to 1 if end of file occurs.
#Return-Status : value returned to operating system when sqr exits.
#Sql-Count : The # of rows affected by an SQL DML statement.
#Sql-Status : Status value from database after each query is compiled/executed. This
value is database dependent.
$Sqr-Database: The database type for which SQR was compiled. Valid values are
ORACLE, INGRES, DB2, INFORMIX, SQLBASE,SYBASE and ODBC.
$Sql-Error: Text message of error returned from DBS.
$Sqr-Locale : The name of the current locale being used.
#Sqr-pid: The process ID of the current SQR process.
$sqr-platform: The hardware/operating system type for which SQR was compiled. Valid
values are WINDOWS, VM,MVS,WINDOWS-NT, UNIX, VMS.
$sqr-program: The name of SQR program file.
$sqr-ver: The text string shown with -ID flag.
Mostly used Format commands in SQR:
CENTER: Center text
EDIT: uses masks to control the format of the output
FILL : fills the specified length with characters specified.
ON-BREAK: allows you to specify an action/procedure in tabular reports when break
occurs in the value of the field.
BEGIN-SETUP includes following commands:
Ask : Prompts the user for substitution variable.
BEGIN-SQL : Begins an SQL paragraph.
CREATE-ARRAY: Creates an array of fields to store and process data
DECLARE-CHART: Defines attributes of a chart.
DECLARE-IMAGE: Defines the type, size and source of an image.
DECLARE-LAYOUT: Defines attributes of a report layout.
DECLARE-PRINTER : Overrides the printer defaults.
DECLARE-PROCEDURE
DECLARE-REPORT: Defines reports and their attributes.
DECLARE-VARIABLE : Allows user to explicitly declare a variable name.
LOAD-LOOKUP : Loads columns into an internal array.
USE : Overrides default database (Sybase and MSSQLServer only)
SQR consists of 5 Sections:
Report or program
Setup
Heading
Footing
Procedures
Processing sequence of SQR
Compile Stage
All #Include external source file (SQCs) are inserted into the source.
All #commands are evalueated. The #DEFINE text substitution variables are
placed into the program source.
The SETUP section is processed, including allocation and population of memory
arrays created by the Load-Lookup and Array commands.
Work buffers are allocated.
Optimization of the SQL data access path is determined.
Syntax of SQR source program is checked.
Execution Stage
Processes data for the Body section
Processes HEADING section
Processes FOOTING section
Writes entire page buffer to file.
What is Process Monitor used for ?
Ans: A centralized utility allowing you to monitor the status of process requests that you
have submitted, by displaying a list of currently logged requests waiting to be processed.
From this list you can view the active list of Process Scheduler Servers and stop their
execution depending on your level of security.
What is the only required section of a SQR Program ?
Ans: The only required section of SQR program is BEGIN-PROGRAM with its
corresponding END-PROGRAM.
How does SQR calculate the number of rows available for the body of the page ?
Ans: The rows available to the body of your report are calculated from the rows defined in
PAGE-SIZE minus the number of rows reserved by the BEGIN-HEADING and BEGIN-
FOOTING sections.
How do you make a zero value blank on a report ?
Ans: Print #varname (+1,1,10) EIDT bbb9
What types of SQR variables are “read only” ?
Ans: Database column variables and most internal reserved SQR variables are Read Only.
What is the difference between the parameters for the EXTRACT command versus the
LET/SUBSTR command ?
Ans: The EXTRACT command uses the offset 0 as the first position. The LET/SUBSTR
command uses 1 as the first position.
What is the BREAK command used for within a WHEN clause of the EVALUATE
command ?
Ans: The BREAK command ends the EVALUATE at that point.
What must you remember to program into a WHILE loop ?
Ans: You must increment your WHILE loop counter.
What are the restrictions governing where a GOTO label can be placed ?
Ans: GOTOs and their labels must be in the same Section or Paragraph. Labels must be left
justified and GOTO label must end with Colon(:)
What SQC is found in every PeopleSoft SQR program ?
Ans: SetEnv.sqc
What SQC files are commonly included in almost all PeopleSoft SQR programs?
Ans: CurDtTim.sqc, Number.sqc and Reset.sqc.
Which SQC file should be modified to include your standard company heading ?
Ans: xxHDG01.sqc where xx is for either HR for Human Resource or FN for Financials.
What are the most common uses of SQC files ?
Ans: a) Setup Section
b) Standard Headings
Footing Section
User prompts
Get related data
Process Scheduler processing
Which SQL command is not allowed in the BEGIN-SQL paragraph ?
Ans: SELECT
What will happen if you do not include an ON-ERROR=procedure in a BEGIN-SQL if
your program encounters an SQL error or warning ?
Ans: SQR program will abort.
Which table stores the translated static report values ?
Ans: The Strings Table.
How does SQR provide you the ability to verify that a file was opened successfully ?
Ans: f you assign a numeric variable to the STATUS=in a file OPEN, you may check the
numeric variable after the OPEN. If the OPEN fails, this variable will contain -1.
What restricts the size of LOAD-LOOKUP memory arrays ?
Ans: Available memory.
What PeopleCode must be on all Run Control Records ?
Ans: On the PRCSRUNCNTL record, the RowInit on OPRID and the SaveEdit on
RUN_CNTL_ID.
What type of variable does the INPUT command use ?
Ans: The INPUT command always inputs into a TEXT variable.
Where should you place user prompts for non-Process Scheduler execution ?
Ans: In the Init-Report procedure, in the following code:
If $prcs_process_instance=’’
!prompts go here
End-If
What PeopleSoft tool is used to change the value of your SQR environment variables ?
Ans: The Configuration Manager.
What procedures are defined in PRCSAPI.SQC & PRCSDEF.SQC ?
Ans: PRCSAPI.SQC : Get-Run-Control-Parms(), Get-Process-Language(), Update-Prcs-
Run-Status().
PRCSDEF.SQC: Define-Prcs-Vars() This procedure will define and initialize the various
process scheduler variables.