Sie sind auf Seite 1von 31

SQR Introduction

1. What are the Reporting tools available in


Introduction PeopleSoft?
Advantages of SQR Structured Query Reports (BRIO 3rd party), XML Publisher,
Crystal Reports (Seagate 3rd party), PS/nVision, Cube
Performance Tuning Manager, Tree Manager.
2. About SQR?
SQR is a Programming Language can be useful to Create
Sections Reports, Interface Files and perform Data Manipulations.
It enables us to generate a wide variety of Reports like
Paragraphs Tabular Reports, Multiple Reports, Form Letters, and Mailing
Labels.
3. About all other Reporting Tools?
Compile stage & Execution stage
XML Publisher:
Execution of SQR Crystal Reports:
PS/nVision: Runs only on Windows NT Operating System.
Testing and Debugging
Cube Manager:
Tree Manager:
SQR Data Elements 4. Difference between SQR, Crystal and nVision?
SQR Crystal nVision
Loops GUI No Yes Yes
Interface Yes No No
SQR Commands Programming Can write Complex
Cannot, at the most
supports few If-Else No
Logic Programs.
statements.
Operators Can be of any type. Can be of any type.
XLS,
Output PDF, LIS, SPF, CSV, XLS, DOC, LIS, RTF, TXT,
HTML
Built-in Functions HTM RPT, HTM

Reserved Variables or Predefined Variables 5. Difference between SQR and AE?


Application Engine SQR
SQR is a 3rd party
Arrays AE is PeopleTools Object.
Application.
AE Stores in Database
Load Lookup Server.
SQR Stores in File Server.

Break Logic No Editors are there to


PeopleCode and SQL editors
validate. We have to run the
are available to validate the
Print Command syntax.
SQR to check for syntax
errors.

Supports Restart facility. Doesn’t supports.


Report Types
We can make some code
Flat Files Active/Inactive from a Cannot.
particular date.
Supports Meta SQLs. Doesn’t support Meta SQLs.
SQCs
Doesn’t support Precompiled SQR supports Precompiled
Command-Line Flags version of Application versions by using -RS. It
Engines. creates .SQT files.
HTML Procedures Complex reports can be
Cannot
generated easily.
Generates reports which
General - SQR include Charts, Graphics,
Cannot
Images and HTML Output
SQR Errors easily.
Sample Code Difficult to find out particular
code. We should know the Easily navigate to a
exact Section / Step / particular code.
Action.
SQL written in the SQL
Action will get automatically
formatted. Sometimes SQR will not format the
because of this option SQL SQLs.
becomes difficult to
understand.

Section and Steps names are There is no restriction to the


restricted. Procedure Names.

Supports PeopleCode
Doesn’t Support.
Commands.

6. What is the difference between SQR Report and


SQR Process?
Create SQR Process - When there is a requirement to
Validation and do the background SQL Process. increase the count of rows to be fetched from database.
Create SQR Reports – When there is a requirement to Create  Ex: -B100 fetches 100 rows from database at
Reports. once.
We can also create Reports with SQR Process too, but it’s 3. Execute programs on the database server: To
not recommended. reduce network traffic and improve performance, run
SQR programs directly on the database server machine.
7. What are the databases can SQR Supports?
4. Create Multiple Reports in one pass:
Oracle Centura SQLBase
When different SQRs are generating different layout
Microsoft SQL Server Ingress
reports on the same Data. Better option is, put them
IBM DB2 Red Brick together and fetch the data and generate the multiple
Informix Rdb reports with different layouts in one pass.
Sybase All base 5. Avoid using Show and Display:
8. What are the Operating Systems can SQR  Use when debugging program only.
Supports?  Execute below 2 programs and find the
difference.
MS DOS OS/2
BEGIN-PROGRAM
WIN 95/98/XP/NT AS/400 BEGIN-SELECT LOOPS = 1000
UNIIX VAX/VMS EMPLID
MVS PRINT &EMPLID (+1,1)
9. What is the initialization file for SQR? FROM PS_JOB
SQR.INI. This file contains settings and parameters which END-SELECT
are used by SQR during the compile and execution phases. END-PROGRAM
10. What is the naming convention of SQR Program? BEGIN-PROGRAM
Extension Should be .SQR and length of name should be BEGIN-SELECT LOOPS = 1000
<=8 as Process Scheduler allows only 8 Characters of
Process Definition Name. EMPLID
There is no limitations to the name length If we run SQR PRINT &EMPLID (+1,1)
thru SQRW.exe SHOW &EMPLID
11. What are the file types available with SQR? FROM PS_JOB
 SQR - Actual Source file. END-SELECT
 SQC - Used as Functional Libraries. END-PROGRAM
 LIS - Line Printer Output file. 6. Avoid Temporary Database Tables:
 SPF - Portable format file.  Creating, updating, and deleting temporary
 SQT - Pre-Complied File. tables are a resource-consuming task, however, and can
slow the program’s performance.
 INI - Used to set the default Environment for
7. Simplify a complex SELECT statement:
our SQR Report.
 Having joins on multiple tables will slow down
 MAX - Used to increase the memory size.
the performance of the query.
 ERR - LOG - DAT - Used for Error Handling
 Create multiple select paragraphs and nest
purpose.
them. In this way, you can break a large join into several
simpler selects.
8. Compile SQR programs and Run the Pre-
Advantages of SQR Compiled SQT:
 Compiling once and executing multiple times
12. What are the Advantages of SQR? can improve its performance.
1. Creates Complex Reports.  Program runs faster as it bypasses the
2. Creates various types of reports - Tabular, Cross- compile phase.
Tabular and Master/Detail Reports.  Use –RS Command Line Flag to create Pre-
3. Generates reports which include Charts, Graphics, Compiled files.
and Images and HTML Output.  The compiled program is stored with same
4. Creates interface files between different systems. name of SQR with (.SQT) extension.
5. Complex Calculations can be done easily.  Use –RT Command Line Flag to execute .SQT.
6. Format dates, numbers, and money according to 9. Improve SQL performance with Dynamic SQL:
local preferences. Assume a scenario; SQR generates employee details
7. Supports Dynamic SQL Variables. report based on either Company or pay Group. So SQR
8. Supports Recompilation. code would be.
9. Runs on Multiple platforms. If $Run_Option = ‘P’
Begin-Select

A.EMPLID (+1, 1)

Performance Tuning A.NAME (, +5)


FROM ABC A
WHERE A.PAYGROUP IN (‘PG1’)
13. How to improve the Performance of SQR
End-Select
Program?
Else
1. Use LOAD-LOOKUP to simplify joins: With
LOAD-LOOKUP, we can reduce the number of tables that Begin-Select
are joined in one select. B.EMPLID (+1, 1)
2. Increase buffering of rows in SELECT B.NAME (, +5)

statements with the -B flag: FROM ABC B


WHERE B.COMPANY IN (‘IBM’)
 We can reduce the trips to database. End-Select
 By default SQR fetch 10 rows from database
End-If
and inserts into buffer.
 Using –B Command Line Argument we can Above code can be tuned by Create dynamic SQL.
If $Run_Option = ‘P’ use Select and Document Paragraphs.
LET $WHERE = 'WHERE A.PAYGROUP IN (' || '''' || 'PG1' || '''' || ')'
 We can create Table, Drop Table, Update, and
END-IF
Insert rows in Setup Section.
IF $Run_Option = ‘C’
LET $WHERE = 'WHERE A.COMPANY IN (' || '''' || 'IBM' || '''' || ')' BEGIN-SETUP
End-If BEGIN-SQL ON-ERROR = STOP/WARN/SKIP
INSERT INTO PS_JOB VALUES ('ABC')
Begin-Select
END-SQL
EMPLID (+1, 1)
END-SETUP
NAME (, +5)
FROM ABC A 20. What are the useful Commands in Setup Section?
[$where] Ask, Begin-SQL, Create-Array,
End-Select Declare-Chart, Declare-Image, Declare-Layout
If run option is not P and C then there won’t be any where Declare-Printer, Declare-Procedure, Declare-Report
condition. SQR will not give any error. It runs without the
Declare-variable, Load-lookup, Use.
Where condition, so all the rows from ABC table will be
Selected. 21. Syntax of Declare-Variable?
BEGIN-SETUP
10. Tune SQR numeric: Selecting the numeric type
DECLARE-VARIABLE
for variables enables you to fine-tune the precision of
DEFAULT-NUMERIC=FLOAT/DECIMAL/INTEGER
numbers in your program.
DECIMAL #DECIMAL(10)
 SQR for PeopleSoft provides three types of INTEGER #COUNTER
numeric values: Best option is Decimal. DATE $DATE
1. Integers: TEXT $DESCR
END-DECLARE
2. Machine floating point
END-SETUP
numbers: (Default Type). Allowed Up to 15 digits of
precision. Faster but Accuracy can be lost while 22. Is it required to declare the Variables?
converting. No it’s not mandatory but recommended to declare.
3. Decimal numbers: Allowed Up to Sample Example1:
38 digits of precision. Most Accurate method but bit
slower. Let $Date1 = ‘JAN 01 2000’
11. Set processing limits: Make sure SQR is not Let $Date2 = ‘Srinivas’
reaching default processing limits. If SQR is exceeding Since we have not declared $Date1 and $Date2 as date
Processing limits increase the corresponding setting in fields, these 2 fields can accept date values as well as
Start up File (PSSQR.INI). Use –M Command line to Strings.
override the processing Settings. BEGIN-SETUP
12. Examine SQL Cursor status: It is important to DELCARE-VARIABLE
know which cursor is maintained for which SQL and the DATE $DATE1
status of each cursor. Use –S command line flag to see DATE $DATE2
the SQL Cursor status. END-DECLARE
END-SETUP
BEGIN-PROGRAM
LET $DATE1 = ‘JAN 01 2000’

Sections LET $DATE2 = ‘Srinivas’


END-PROGRAM
14. What are the Sections Available in SQR? This program will give an error. Now $DATE2 field will not
1. Setup Section. accept Strings.
2. Heading Section. Sample Example2:
3. Footing Section. BEGIN-PROGRAM
4. Program Section. LET $DT1 = 'JAN 01 2010'
5. Procedure Section. SHOW $DT1
LET $DT2 = DATEADD($DT1, 'YEAR', 2)
Setup Section SHOW $DT2
END-PROGRAM
15. What is the use of Setup Section?
This program gives an error stating that ‘Function or
 This is the place where we keep all
Operator ‘date add’ requires date argument’.
declarations like Declare-Reports, Declare layouts,
Declare-variable, Declare-Printer, Declare-Chart, Declare- BEGIN-SETUP
Image, Declare-Procedure, DECLARE-VARIABLE
DATE $DT1
 Useful to Setup Printer and Page
DATE $DT2
environment.
END-DECLARE
 To define Substitution Variables. END-SETUP
 To Define Arrays and Load Lookups. BEGIN-PROGRAM
16. Is it required to have Setup Section in every LET $DT1 = 'JAN 01 2010'

SQR? SHOW $DT1


LET $DT2 = DATEADD($DT1, 'YEAR', 2)
No, it’s optional.
SHOW $DT2
It’s only required When there is a change in Setup. END-PROGRAM
And if included must be placed at the beginning of the
Since the Fields are defined as Date Type. Output Would be,
program.
17. When the Setup Section will be get processed? In Jan 01 2010
Compile Stage or Execution Stage? Jan 01 2012
In Compile Stage. 23. Syntax of Declare-Layout?
18. Can we use Show / Display / Print Commands in DECLARE-LAYOUT DEFAULT
Setup Section? ORIENTATION=PORTRAIT
PAPER-SIZE=(8.5,11.0)
No.
LEFT-MARGIN=1.85
19. Can we use all the 3 Paragraphs in Setup TOP-MARGIN=1.63
Section? BOTTOM-MARGIN=1.0
 Only SQL Paragraph can be allowed. We can’t RIGHT-MARGIN=1.0
CHAR-WIDTH=5 page?
LINE-HIGHT = 10
132 Columns. (#sqr-max-columns gives the Max Count)
END-DECLARE
32. What happens if there is a print statement like
24. Syntax of Declare-Report?
Print ‘Srinivas’ (63,1)
DECLARE-REPORT DEFAULT
LAYOUT=DEFAULT
SQR will throw and error message.
PRINTER-TYPE=PD String cannot be placed on page: Srinivas
END-DECLARE Placement specified is out of range. (63,1,0)
END-SETUP
33. If 3 Lines are allocated for Heading and Footing
25. Syntax of Declare-Image? then how many Lines of data cane be printed in Body
BEGIN-SETUP for a default size page?
DECLARE-IMAGE GOOGLE_LOGO
56 Lines. The rows available to the body of your report are
TYPE=BMP-FILE
calculated from the rows defined in PAGE-SIZE minus the
SOURCE='C:\DOCUMENTS AND
SETTINGS\ADMINISTRATOR\DESKTOP\GOOGLE.BMP' number of rows reserved by the BEGIN-HEADING and
IMAGE-SIZE=(7,6) BEGIN-FOOTING sections.
END-DECLARE 34. Where and how can we change the Page Size?
END-SETUP
Using the Declare-Layout command in the Setup Section.
Image Type: GIF-FILE, JPEG-FILE, or BMP-FILE, EPS-FILE, We have to specify the Paper Size, Left/Right/Top/Bottom
HPGL-FILE Margins.
BEGIN-SETUP
26. Syntax of Declare-Printer? DECLARE-LAYOUT DEFAULT
BEGIN-SETUP ORIENTATION=PORTRAIT
DECLARE-PRINTER HPLASERJET PAPER-SIZE=(8.5,11.0)
FOR-REPORTS = <REPORT-NAME> LEFT-MARGIN=1.85
COLOUR = YES TOP-MARGIN=1.63
POINT-SIZE = 10 BOTTOM-MARGIN=1.0
FONT-TYPE = FIXED RIGHT-MARGIN=1.0
PITCH = 10 CHAR-WIDTH=5
FONT = 5 END-DECLARE
END-DECLARE
END-SETUP DECLARE-REPORT DEFAULT
LAYOUT=DEFAULT
27. Sample Program of Alter-Printer?
PRINTER-TYPE=PD
BEGIN-PROGRAM END-DECLARE
PRINT 'SRINIVAS' (+1,1) END-SETUP
PRINT 'SRINIVAS' (+1,1) 35. What’s the procedure to print Image thru SQR?
PRINT 'SRINIVAS' (+1,1)
 Declare image in Setup Section. Mention
ALTER-PRINTER Image Name, Type, Source, Size.
POINT-SIZE = 20 BEGIN-SETUP
FONT = 3 !Courier DECLARE-IMAGE GOOGLE_LOGO
FONT-TYPE = FIXED TYPE=BMP-FILE
PITCH = 2 SOURCE='C:\DOCUMENTS AND
PRINT 'SRINIVAS' (+3,1) SETTINGS\ADMINISTRATOR\DESKTOP\GOOGLE.BMP'
PRINT 'SRINIVAS' (+1,1) IMAGE-SIZE=(7,6)
PRINT 'SRINIVAS' (+1,1) END-DECLARE
END-SETUP
ALTER-PRINTER
POINT-SIZE = 30  In Program / Procedure section print the
FONT = 4 !Helvetica image using Print-Image command.
FONT-TYPE = PROPORTIONAL BEGIN-PROGRAM
PITCH = 37 PRINT-IMAGE GOOGLE_LOGO (1, 1)
PRINT 'SRINIVAS' (+3,1) END-PROGRAM
PRINT 'SRINIVAS' (+1,1)
PRINT 'SRINIVAS' (+1,1) Heading Section
END-PROGRAM
36. What is the use of Heading Section?
Output Would be:  Useful to create Page Headings.
 The BEGIN-HEADING command is followed by
a number, which indicates the number of lines reserved for
the Heading.
37. What are the main Arguments we can pass thru
Heading Section?
For-Reports: By default Heading Section will be applicable
to all the reports. By using the Declare-Report and For-
Report we can assign separate headings for each report.
38. Can we use Paragraphs in Heading Section?
No We can’t.
39. Can we use Show and Display commands in
Heading section?
Yes. We can use.
40. Can we call Procedure Section in heading
Section?
28. Syntax of Declare-Chart? Yes.
41. Can a SQR Program have more than one
Heading/ Footing Sections?
29. What is the default Page Size?
Yes. When there is a requirement to create multiple reports
8 1/2 by 11 inches
with different layouts and Headings/Footings we can create
30. How many lines we can print in a default page? multiple Heading / Footing Sections.
62 lines. (#sqr-max-lines gives the Max Count)
For-Reports Command specifies which Heading / Footing is
31. How many Columns we can print in a default
Let $Line_NBR_Program = 'Line Number in Program Section: '
belongs to which Report.
CONCAT #Current-Line WITH $Line_NBR_Program
BEGIN-HEADING 5 FOR-REPORTS = REPORT1 PRINT $Line_NBR_Program (+1,1)
BEGIN-HEADING 5 FOR-REPORTS = REPORT2 END-PROGRAM

BEGIN-FOOTING 3
Footing Section Let $Line_NBR_Footing = 'Line Number in Footing Section: '
42. What is the use of Footing Section? CONCAT #Current-Line WITH $Line_NBR_Footing
 Useful to create Page Footings. PRINT $Line_NBR_Footing (3,1)
 The BEGIN-FOOTING command is followed by END-FOOTING
a number, which indicates the number of lines reserved for 'Line Number in Heading Section: ' 13
the Footing.
Srinivas – at 10th Line and 1st Column
43. What are the main Arguments we can pass thru
'Line Number in Program Section: ' 12
Footing Section?
'Line Number in Footing Section: ' 2
For-Reports: By default Footing Section will be applicable
to all the reports. By using the Declare-Report and For- Program Section
Report we can assign separate Footings for each report.
44. Can we use Paragraphs in Footing Section? 53. Is Program Section mandatory in every SQR?
No We can’t. Yes, every program should have Program Section. Otherwise
45. Can we use Show and Display commands in it will be called as SQC so we can’t run as standalone
Footing section? program.
Yes. We can use. 54. What is the use of Program Section?
46. Can we call Procedure Section in Footing It’s the mandatory Section useful to identify the Beginning
Section? and Ending of the Program.
Yes. 55. What is the other name of Program Section
47. How many areas can a page divided into? In earlier SQR versions the Program Section used to call as
Report section.
A page can be subdivided into 3 logical areas.
56. Can we use Paragraphs in Program Section?
 The Top area of the page is the Heading,
which is the place where we normally print the Report Document Paragraph can’t be allowed in Program Section.
Title and the Date. Other 2 Paragraphs Select and SQL are allowed.
 The Bottom area of the page is the Footing, Procedure Section
which is the place where we normally print the Page
Numbers. 57. What is the use of Procedure Section?
 The Middle part of the page is called the Useful to break the program into modules, So that we can
Body, which is the place where we print the Report Data. easily debug and maintain.
48. What is the use of the PAGE-NUMBER command? 58. Is Procedure Section mandatory?
The PAGE-NUMBER command prints the Current Page No. If the program logic is not complex we can write the
number. code in Begin-Program it self.
49. What is the use of the LAST-PAGE command? 59. Can we have multiple Procedure Sections in a
The LAST-PAGE command prints the Last Page Number. single SQR?
50. Code to print Page Number? Yes, but each procedure should be with unique name.
PAGE-NUMBER (1,1) 'PAGE ' 60. Can we use Paragraphs in Procedure Section?
LAST-PAGE () ' OF ' All the 3 Paragraphs are allowed in Procedure Section.
Print Command is not necessary for these 2 Commands. We 61. What are the commands used to call a
can also get the page number thru #page-count command Procedure?
but print command is required for this.  DO is the command to call the procedure.
BEGIN-HEADING 1
 And thru On-Error, We can specify the
PRINT 'VALUE OF I #PAGE-COUNT PAGE-NUMBER' (1,1) Procedure Name.
END-HEADING  And thru On-Break. Before and After we can
BEGIN-PROGRAM
specify the Procedure Name.
LET #I = 1  By declaring the Procedures thru Declare-
WHILE #I <= 200 Procedure.
PRINT #I (,1) edit 999 BEFORE-REPROT, AFTER-REPROT, BEFORE-PAGE, AFTER-PAGE.
LET #I = #I + 1 62. How to declare Procedures?
PRINT #PAGE-COUNT (,+15) edit 9
BEGIN-SETUP
PAGE-NUMBER (,+12) 'PAGE '
DECLARE-PROCEDURE
LAST-PAGE () ' OF '
FOR-REPORTS = REPORT_NAME
POSITION (+1)
BEFORE-REPORT = PROCEDURE_NAME
END-WHILE
AFTER-REPORT = PROCEDURE_NAME
END-PROGRAM
BEFORE-PAGE = PROCEDURE_NAME
51. Assume there is no data to be printed in AFTER-PAGE = PROCEDURE_NAME
Procedure or Program section then will be heading END-DECLARE
and footing sections get processed? END-SETUP
No, if there is no data to be printed in Procedure and 63. How many types of Procedures can SQR
Program Sections then Heading and Footing sections will not Supports?
be executed.
Local and Global.
52. What would be the output to the below Program? 64. What is the by default scope set to Procedures?
BEGIN-HEADING 2 By defaults all the Procedures are Global which are visible
Let $Line_NBR_Heading = 'Line Number in Heading Section: ' through out the program.
CONCAT #Current-Line WITH $Line_NBR_Heading 65. How to make the Procedures as Local?
PRINT $Line_NBR_Heading (2,1) We have to explicitly declare it as local using the LOCAL
END-HEADING keyword.
BEGIN-PROGRAM 66. Assume a Select Query is defined in a Local
PRINT 'Srinivas – at 10th Line and 1st Column' (10,1) Procedure. Can we access all selected Columns in
other procedures? defined.’
No, When a query is defined in a Local Procedure, all And No Commas required between the Columns. If we use
selected column names are considered as Local and can't be also SQR will not give any error.
used in any other Procedures. Ex:
67. How to call Global Variables in Local Procedures? BEGIN-PROGRAM
To call Global Variables in Local Procedures we have to add BEGIN-SELECT LOOPS = 10

an underscore to the variable name after its special EMPLID


SHOW &EMPLID
character ($, #, &).
EFFDT
Ex: &_Emplid, #_Total SHOW &EFFDT
We should specify underscore for Reserved Variables also. FROM PS_JOB
Ex: $_SQL-Error, #_SQL-Status. END-SELECT
END-PROGRAM
68. What is Modular Programming and the use of it?
76. In BEGIN-SELECT do the FROM and WHERE
Modular programming is nothing but dividing the complex
clause have to be aligned to the left margin?
program into different procedures. It makes the program
easier to debug and maintain. No, only the columns should have to be.
77. Suppose if we want to select all the fields from a
Record PS_JOB, Can we use SELECT * FROM PS_JOB
statement?
Paragraphs No, we have to mention all the field names.
69. How many Paragraphs can SQR supports? 78. What are the main Arguments we can pass thru
Select Paragraph?
1. Begin-Select.
 Distinct: It eliminates the duplicate Rows.
2. Begin-SQL.
 Loops = nn: SQR exists from the Select paragraph
3. Begin-Document.
after specified no of rows has been processed.
SETUP HEADING FOOTING PROGRAM PROCEDURE
SELECT For Example: If we mention Begin-Select Loops = 10
SQL then SQR exists from the Select Paragraph after 10 rows
DOCUMENT has been processed.
 -Bnn: It retrieves specified no of rows of data from the
Begin-Select database to buffer.
70. What is the use of Begin-Select Paragraph?  -DB database: Specifies the default database name
for this SELECT paragraph only.
Useful to Select the Data from the Database.
 -DB connection String: Specifies the ODBC
71. In which Sections Begin-Select Paragraph is
connection string for this SELECT paragraph only.
allowed?
 On-Error = Procedure Name: When there is an SQL
Only in Program and Procedure Sections.
Error then mentioned procedure will be called.
72. Can a Procedure have more than one Select
79. How do you fetch first 100 rows from a table
Paragraph?
which is having 10000 rows?
Yes, Multiple Select Paragraphs are allowed in a Procedure.
1) Exit-Select: Is the function useful to come out from the
BEGIN-PROGRAM Select Paragraph.
DO A BEGIN-PROGRAM
END-PROGRAM BEGIN-SELECT
EMPLID
BEGIN-PROCEDURE A
LET #COUNT = #COUNT + 1
BEGIN-SELECT LOOPS = 10
SHOW #COUNT
EMPLID
IF #COUNT = 100
SHOW &EMPLID
EXIT-SELECT
FROM PS_JOB
END-IF
END-SELECT
DO GET_PERSONAL_DETILS
BEGIN-SELECT LOOPS = 10 FROM PS_JOB
EFFDT END-SELECT
SHOW &EFFDT END-PROGRAM
FROM PS_JOB;
2) Loops:
END-SELECT
BEGIN-PROGRAM
END-PROCEDURE
BEGIN-SELECT LOOPS = 100
73. Can we include expressions while selecting the EMPLID
data? SHOW #EMPLID
Yes. FROM PS_JOB
BEGIN-SELECT END-SELECT
EMPLID END-PROGRAM
(SALARY + 10000) ! It’s an expression, adding 10000 to the database 3) Stop: Issues ROLLBACK and Comes out from the SQR
column.
with the Error Message "Program Stopped by User
FROM ABC
Request".
END-SELECT
With the QUIET Argument - Issues ROLLBACK and comes
74. Can we insert SQR Commands between the
out from the SQR with the "SQR: End Of Run" message,
Column Names?
instead of aborting with an error message.
Yes, But should be start with 2nd position. BEGIN-PROGRAM
BEGIN-SELECT BEGIN-SELECT
EMPLID EMPLID
COMPRATE LET #COUNT = #COUNT + 1
MOVE &EMPLID = $ID !it’s a SQR Command, started with 2 nd
SHOW #COUNT
column.
IF #COUNT = 100
LET #SALARY = &COMPRATE + 5000 !it’s a SQR Command
STOP OR STOP QUIET
DO GET_EMP_DETAILS !it’s a SQR Command
END-IF
END-SELECT
FROM PS_JOB
75. Is it required to start the SQR Columns from 1st END-SELECT
position? END-PROGRAM
Yes, then only SQR Columns will be identified. Otherwise 80. What’s the SQL to fetch first 10 rows in Oracle,
SQR will throw an error stating that ‘Referenced Variable Not
SQL Server and DB2? including all spaces allocated for the records are removed
DB2:  COMMENT - add comments to the data dictionary
FETCH FIRST 10 ROWS ONLY  RENAME - rename an object
SELECT * FROM PS_JOB FETCH FIRST 10 ROWS ONLY; 90. Data Manipulation Language (DML):
Oracle: DML Statements are used for managing data within schema
ROWNUM <= 10 objects.
SELECT * FROM PS_JOB WHERE ROWNUM <= 10;  SELECT - retrieve data from the a database
SQL Server:  INSERT - insert data into a table
TOP 10  UPDATE - updates existing data within a table
SELECT TOP 10 * FROM PS_JOB;
 DELETE - deletes all records from a table, the space
Begin-SQL for the records remain
 MERGE - UPSERT operation (insert or update)
81. What is the use of Begin-SQL Paragraph?  CALL - call a PL/SQL or Java subprogram
Useful to Manipulate the data.  EXPLAIN PLAN - explain access path to data
82. In which Sections Begin-SQL Paragraph is  LOCK TABLE - control concurrency
allowed?
91. Data Control Language (DCL) statements:
SQL Paragraph can be allowed only in
Program/Procedure/Setup Sections.  GRANT - gives user's access privileges to database
83. Can a Procedure have more than one SQL  REVOKE - withdraw access privileges given with the
Paragraph? GRANT
Yes, Multiple SQL Paragraphs are allowed in a Procedure. 92. Transaction Control (TCL):
84. Can we write multiple SQLs in a SQL Paragraph? TCL Statements are used to manage the changes made by
DML statements. It allows statements to be grouped
Yes, but should be separated by Semicolon (;)
together into logical transactions.
Begin-SQL
 COMMIT - save work done
UPDATE ABC SET NAME = ‘Srinivas’;
 SAVEPOINT - identify a point in a transaction to
DELETE FROM ABC WHERE NAME <> ‘Srinivas’;
which you can later roll back
End-SQL
 ROLLBACK - restore database to original since the
85. What are the Options available with On-Error
last COMMIT
Clause in Setup Section?
 SET TRANSACTION - Change transaction options like
Stop: Stops the program.
isolation level and what rollback segment to use.
Warn: Display a warning message and continue the process.
Skip: Ignores all errors and continue the program Example:

BEGIN-SETUP DROP TABLE ABC;


CREATE TABLE ABC (EMPLID CHAR(11));
BEGIN-SQL ON-ERROR = STOP/WARN/SKIP INSERT INTO ABC VALUES ('1');
INSERT INTO PS_JOB VALUES ('ABC') INSERT INTO ABC VALUES ('2');
END-SQL INSERT INTO ABC VALUES ('3');
INSERT INTO ABC VALUES ('4');
END-SETUP
INSERT INTO ABC VALUES ('5');
BEGIN-PROGRAM SELECT * FROM ABC;
DELETE FROM ABC WHERE EMPLID = '1';
SHOW 'PROGRAM SECTION'
SELECT * FROM ABC;
SHOW $SQL-ERROR BEGIN TRAN
END-PROGRAM DELETE FROM ABC WHERE EMPLID = '2';
SELECT * FROM ABC;
86. What are the Options available with On-Error ROLLBACK;
Clause in Non Setup Section? SELECT * FROM ABC;
BEGIN TRAN
On-Error = Procedure. DELETE FROM ABC WHERE EMPLID = '3';
SELECT * FROM ABC;
BEGIN-PROGRAM COMMIT;
DO A ROLLBACK;
SELECT * FROM ABC;
END-PROGRAM
UPDATE ABC SET EMPLID = 'FFF' WHERE EMPLID = '5';
BEGIN-PROCEDURE A DELETE FROM ABC WHERE EMPLID = '4';
SELECT * FROM ABC;
BEGIN-SQL ON-ERROR = B TRUNCATE TABLE ABC;
INSERT INTO PS_JOB VALUES ('ABC') SELECT * FROM ABC;
END-SQL
END-PROCEDURE Begin-Document
BEGIN-PROCEDURE B
93. What is the use of Begin-Document Paragraph?
SHOW $SQL-ERROR
END-PROCEDURE
Useful to print the Static Text with Database Values.
87. Can we write Select SQL in Begin-SQL 94. Is Print Command required to print the data?
Paragraph? No need to write any Print Commands as it has Implicit
No, We can’t. Except Select all DDL, DML, DCL are allowed. Print.
88. How can we execute the stored procedures in 95. In which Sections Begin-Document Paragraph is
SQR? allowed?
 In Oracle stored procedures are maintained by PL/SQL Document Paragraph can be allowed only in Procedure
in Begin-SQL Paragraph. Each statement should end with Section.
(;;). 96. Can a Procedure have more than one Document
 In other databases stored procedures are maintained Paragraph?
by EXECUTE Command. Yes, Multiple Document paragraphs are allowed in a single
89. About Data Definition Language (DDL): Procedure.
DDL Statements are used to define the database structure 97. What is Arguments we can pass thru Begin
or schema. Document?
 CREATE - to create objects in the database Position.
 ALTER - alters the structure of the database 98. What are the rules we should be followed while
writing Document Paragraph?
 DROP - delete objects from the database
 Use .b to indicate blank lines.
 TRUNCATE - remove all records from a table,
 SQR commands or not allowed in Document
paragraph. BEGIN-SETUP
 A Document paragraph must fit within a ASK COMPANY 'ENTER COMPANY NAME (IBM/CSC)'
single report page. ASK DATE 'ENTER DATE IN YYYY-MM-DD FORMAT'
ASK SALARY 'ENTER SALARY'
END-SETUP

Compile stage & Execution stage


BEGIN-PROGRAM
BEGIN-SELECT
EMPLID (+1, 1,)
99. Program flow of SQR in Compile Stage? NAME (, +3)
Setup, Heading, Footing, Program, Procedure. SALARY (, +3)
100. Program flow of SQR in Execution Stage? PAY_END_DT (, +3)
FROM ABC
Program, Procedure, Heading, Footing.
WHERE COMPANY = '{COMPANY}'
101. What happens at Compile Stage? AND SALARY > '{SALARY}'
1. Reads and Validates the Program. AND PAY_END_DT = '{DATE}'
2. Checks for the Syntax of the Program. END-SELECT
END-PROGRAM
3. Performs the SETUP Section.
4. Executes all ASK Commands. 107. Sample Program about Input Command?
5. All Substitution Variables will be determined. BEGIN-PROGRAM
6. Memory will be allocated for Arrays. TRY_AGAIN:
INPUT $COMPANY 'ENTER COMPANY NAME (IBM/CSC)' TYPE = CHAR
7. Load Lookups will be created and data will be
populated. IF $COMPANY <> 'IBM' AND $COMPANY <> 'CSC'
SHOW 'COMPANY SHOULD BE EITHER IBM OR CSC' BEEP
8. All #include - external Source Files will be inserted into
SHOW ''
the program.
GOTO TRY_AGAIN
9. Program memory and work buffers will be allocated. END-IF
10. Validates SQL Statements.
INPUT $DATE 'ENTER DATE IN YYYY-MM-DD FORMAT' TYPE = DATE FORMAT
11. At the end SQT file will be created when there is –RS = ‘YYYY-MM-DD’
Command line parameter. INPUT #SALARY 'ENTER SALARY' TYPE = INTEGER
102. What happens at Execution Stage? BEGIN-SELECT
EMPLID (+1, 1,)
1. Starts executing SQR when no errors found in Compile
NAME (, +3)
Stage. SALARY (, +3)
2. Executes Begin-Program and stops at End-Program. PAY_END_DT (, +3)
3. Calculates the size of the report-working page. FROM ABC
WHERE COMPANY = $COMPANY
4. Process the Report Body.
AND SALARY > #SALARY
5. Process the Heading. AND PAY_END_DT = $DATE
6. Process the Footing. END-SELECT
7. Writes entire page to output file and gets ready for the END-PROGRAM
next page.
108. How to validate whether the input value is
103. About Substitution Variables? correct or not with Input Command?
 Substitution Variables are Compile Time Variables.  Declare GOTO label (should be end with : )
 Values will be assigned during the Compile Stage. before INPUT Command.
 We can’t change the value once the value been  Write INPUT Command.
assigned to Substitution Variable.  Validate entered input value using IF
 Main advantage is, define once and use multiple times. Condition or any other logic.
 Useful to assign heading and footing section  If the condition is false, Use GOTO command
parameters to move the cursor to the mentioned GOTO label.
 Also to modify the array Name and Size.  So again it executes the INPUT.
 #define and Ask are useful to define Substitution  Process will continue till the Input value is
Variables. correct.
104. Sample Program About #define? 109. Difference between Ask and Input?
#DEFINE COMPANY 'CSC'
ASK INPUT
#DEFINE SALARY 10000
It is a Compile-Time
#DEFINE DATE 2000-01-01 It is Run-Time variable.
variable.
#DEFINE COL1 1 Allowed only in Setup Allowed in any section
#DEFINE COL2 5
section. except Setup section.
#DEFINE COL3 10
#DEFINE COL4 20
No Need to Specify data We Should specify the data
type. type.
BEGIN-PROGRAM
Array name and size can be
BEGIN-SELECT Can’t.
changed.
EMPLID (+1,{COL1})
NAME (,{COL2}) Heading and Footing
SALARY (,{COL3}) sections parameters can be Can’t.
PAY_END_DT (,{COL4}) changed.
FROM ABC
We can't Validate and re-
WHERE COMPANY = {COMPANY} Can.
AND SALARY > {SALARY}
enter if it is not valid.
AND PAY_END_DT = ‘{DATE}’
We can prompt the user We can prompt the user
END-SELECT
only once as it is executes at more than once as it
END-PROGRAM
compile-time. executes at run-time.
105. How do you refer a Constant which are defined 110. About Bind Variables?
by #define And ASK in SQR?  SQR Bind Variables are Runtime Variables.
A constant is referred in curly braces { }, ‘{}’.  These values are assigned and changed during the
106. Sample Program About Ask? program execution stage.
 Used when a query includes parameters define outside
of this query.  Specify the Database Name.
111. Sample Program about Bind Variables?  Specify User Name and Password.
BEGIN-PROGRAM  Specify the required Report Arguments.
DO GET_EMPLIDS
 Then Click on OK.
END-PROGRAM
BEGIN-PROCEDURE GET_EMPLIDS 116. What are the SQR executable files for Windows
BEGIN-SELECT LOOPS = 10 and UNIX?
EMPLID Use SQRW.exe to run SQR in Windows System.
MOVE &EMPLID TO $EMPLID
Use SQR.exe to run SQR in UNIX.
DO GET_NAMES
FROM PS_JOB
117. Where the output file will be generated and what
END-SELECT
would be the output file name?
END-PROCEDURE By default SQR creates an Output file with the same name
BEGIN-PROCEDURE GET_NAMES of the SQR program in the Same SQR Directory.
BEGIN-SELECT 118. Can we override the Output Directory and File
NAME Name?
PRINT &EMPLID (+1,1)
Yes, we can. We have to use –F Command line Argument.
PRINT &NAME (,+5)
FROM PS_NAMES WHERE EMPLID = $EMPLID 119. If no Command Line Argument is mentioned then
END-SELECT what would be output file type?
END-PROCEDURE By default .LIS files will be generated. But LIS file will not
Here $EMPLID is the Bind variable used in Select Statement. be invoked automatically. We have to go to the output
112. About Dynamic Query Variables? path and open it manually.
 Dynamic Query Variables are Runtime Variables. And SQR generates SQR.LOG file.
 Useful to build the Dynamic SQL code. 120. About LIS Files?
 We can refer these variables in SQL statement by LIS files are printer dependent files and are default.
enclosing the Square brackets [$WhereClause] and 121. About SPF Files?
forward slash in MVS, AS/400 \&by\.  SPF files are SQR portable files and are printer
113. Sample Program about Dynamic Query independent.
Variables?  It allows all the SQR Graphical features, such as
Fonts, Lines, Boxes, Shaded Areas, Charts, Bar Codes,
 Dynamic variables are useful to pass the Where Clause
and Images.
dynamically and Table names Dynamically.
 .SPF or .SNN (for multiple reports) are the default
BEGIN-PROGRAM
extension to the SQR portable files.
INPUT $EMPLID 'ENTER ANY EMPLOYEE ID' TYPE = CHAR
LET $WHERE = ' WHERE EMPLID = ' || '''' || $EMPLID || ''''
 -ZIV, -KEEP, -NOLIS are useful to create .SPF files.
 -KEEP: It creates both SPF & LIS files. But it will
BEGIN-SELECT
not invoke SPF files automatically.
EMPLID (+1,1)
EFFDT (,+5)  -NOLIS: It will not create LIS Files. It simply
COMPRATE (,+5) creates SPF file but will not invoke automatically.
FROM PS_JOB  -ZIV: it internally calls –KEEP. Means it generates
[$WHERE] SPF and LIS and then It invokes the SPF automatically.
END-SELECT
 If we mention 2 arguments –ZIV and –NOLIS then
END-PROGRAM
only SPF file will be created and invoked automatically.
 And also useful to pass Select Clause dynamically. 122. How PDF files will be created?
BEGIN-PROGRAM When we use ‘Print’ Command, By Default PDF files will be
LET $RUN_OPTION = 'C' created.
IF $RUN_OPTION = 'C' 123. What are the possible files we can generate
LET $DYNAMICFIELD = 'COMPANY'
ELSE
with SQR?
LET $DYNAMICFIELD = 'PAYGROUP' .PDF Adobe Acrobat
END-IF .CSV Delimited
BEGIN-SELECT DISTINCT .PS Post Script
[$DYNAMICFIELD] &A=CHAR .HTM HTML
SHOW &A .LIS HP
FROM PS_JOB .LIS Line Printer
END-SELECT
.SPF SQR Portable
END-PROGRAM

Process Scheduler
124. What's the Process to run SQR thru Process
Execution of SQR Scheduler?
114. How many ways we can run the SQR Program?  Create SQR.
1. SQRW.  Make it as API Aware by including all 3
Mandatory SQCs and two procedures STDAPI-INIT at the
2. Process Scheduler.
beginning, STDAPI-TERM at the ending of the program.
3. Command Line.
 Place the SQR in SQR Directory mentioned in
4. Thru PeopleCode – Create Process Request. the Configuration Manager.
5. Call System  Create Run Control Record / Page /
6. Push Button. Component if required.
 Create New Process: Go to PeopleTools –
SQRW Process Scheduler – Process.
115. What are the Steps required to run SQR thru  Specify the Run Control Component Name.
SQRW? Save.
 Open SQRW executable file  If required we can also give the Command
C:\PT8.45\bin\sqr\MSS\BINW\sqrw.exe Line Parameters in Override tab.
 Specify the SQR Name.  Navigate thru the Run Control Component –
You can see the attached SQR. Select and Run. 133. Is it required to Create a Process Definition to
125. How to pass Run Control Values while running run SQR thru CreateProcessRequest Function?
SQR thru Process Scheduler? Yes, We have to create a Process Definition otherwise it
 Create Run Control Record. will throw an error stating that ‘An entry must be provided
in the process definition table before this process can be
 Create Run Control Page by including Run
scheduled to run.’
Control Sub page ().
 Create Run Control Component. Call System
 Create Process Definition. And assign the Run
control Component Name. 134. Sample Programs about Call System?
126. What type of files will be generated when we run Create a SQR in C drive and name it as 2.SQR.
SQR thru Process Scheduler? BEGIN-PROGRAM
SHOW 'PROGRAM 2 STARTED'
Log file and Out File.
SHOW 'SRINIVAS'

Command Line SHOW 'PROGRAM 2 ENDED'


END-PROGRAM

127. What are the commands used to run SQR thru Create another SQR in C drive and name it as 1.SQR.
Command Line? BEGIN-PROGRAM
SHOW 'PROGRAM 1 STARTED'
We have to mention the
LET $CMD = 'C:\PT8.45\BIN\SQR\MSS\BINW\SQRW.EXE C:\2.SQR A/SA/SA'
SQRW executable file path , CALL SYSTEM USING $CMD #STATUS
SQR name with full path, SHOW 'PROGRAM 1 ENDED'
Database name, END-PROGRAM

UserID, Run 1.SQR thru SQRW, which calls the 2.SQR too.
Password,
Push Button
EX: C:\PT8.45\bin\sqr\MSS\BINW\sqrw.exe
c:\Program1.sqr HC/sa/sa –ZIV 135. Procedure to run SQR thru Push Button?
If required Command Line Flags. Insert a Push Button in page.
-F<Output File Path> Go to Push Button Properties, Select the Destination –
Process. Then Process Options will be enabled.
-S
Select Type as either SQR Process or SQR Report
128. Assume a Program Runs based on Run Control
Input Value. When you run the Same SQR thru Select the SQR name.
Command Line, How can we pass the Input Value? Navigate to the Particular Page in PIA.
Thru ASK and INPUT. Click on Push Button.
129. What steps needs to be followed in order to run 136. Can we run Application Engine Programs thru
the Same SQR Program which requires input values SQR?
thru Process Scheduler as well as SQRW?

PeopleCode – Create Process Request


Testing and Debugging
130. How to Run SQR thru PeopleCode?
Thru Create Process Request. 137. What are the commands useful to Debug SQR
Program?
131. What is the procedure to run SQR thru
CreateProcessRequest? 1. Command Line Flags: -Tnn, -S, -C, -E
 Create SQR. 2. Show and Display:
 Place the SQR in SQR Directory mentioned in 3. Conditional Debugging: - #IF, #ELSE, #END-IF or
the Configuration Manager. #ENDIF, #IFDEF, #IFNDEF.
 Create a New Process Definition in Process
Command Line Flags
Scheduler.
 In PeopleCode Event – call the 1. -Tnn:
CreateProcessRequest() function and specify Attributes  It stops the process after printing n number
ProcessType, ProcessName, and RunControlID. of pages;
 Call the Schedule() method.  It ignores BEGIN-SELECT ORDER BY clause.
 Schedule() method will schedules the Process  For example: -T6, it stops the program after
and then executes the rest of PeopleCode. It will not wait 6 pages of output has been created.
till the process gets completed. 2. -S:
 In Process Monitor we can see the Program  It shows the Status of the program cursors.
Status whether it ran to Success or not. –
 After completion of the program it will display
RUNSTATUSDESCR field from PS_PMN_PRCSLIST Table.
the information about.
132. What is the code to run SQR thru
 Text of each SQL statement.
CreateProcessRequest PeopleCode Command?
 Number of Compiled and Executed SQL statements.
Local ProcessRequest &RQST;
 Total number of rows fetched.
&RQST = CreateProcessRequest(); 3. -C:
&RQST.ProcessType = "SQR Report";  It creates the Cancel Dialog Box during the
&RQST.ProcessName = "Program1 "; program run, So that we can cancel the execution of the
&RQST.RunControlID = "Srinivas"; program when it’s necessary.
4. -E:
&RQST.Schedule();
 It creates Error file with the extension .err.
If &RQST.Status = 0 Then  By default error file name would be the same
WinMessage("SQR Successfully Scheduled", 0); name of SQR.
Else  We can also change the name of error file by
WinMessage("There is a problem while Scheduling SQR", specifying the file name along with –E Command line
0); argument.
End-If;
 Ex: -Eabc. It creates an error file with the #DEBUGy show ‘Y’
name abc.err #DEBUGz show ‘Z’
 If there are no errors in the program, no error #DEBUGa show ‘A’
file will be created. #DEBUGb show ‘B’
SQR Commands – Show and Display Then What would be output?
X
 Both are useful to display the variables.
Y
 Display command useful to display only one value at a Z
time
Because #DEBUGxyzab flag has not been specified.
 Show command useful to show more than one value at
a time. Conditional Debugging
Show &EMPLID &NAME &SALARY
144. What are the Commands can SQR supports for
Output: 100 Srinivas 1000000
Conditional Debugging purpose?
Display &EMPLID Display &EMPLID NO LINE #IF, #ELSE, #END-IF or #ENDIF, #IFDEF, #IFNDEF.
Display &NAME Display &NAME NO LINE 145. Sample Program on #IF, #ELSE and #END-IF.
Display &SALARY Display &SALARY
No need to use any –DEBUG Flags.
Output: Output:
100 100 Srinivas 10000 #DEFINE DEBUG_IT Y
BEGIN-SETUP
Srinivas
Ask $Company 'Enter Company Name'
10000 END-SETUP
BEGIN-PROGRAM
 We can use these commands anywhere in the program
#IF DEBUG_IT = ‘Y’
except the Setup Section.
#IF $Company = 'Hewitt'
 We can also use the EDIT Mask with Show and Display. LET $EMPLID = '55849'
Display '123456789' xxx-xx-xxxx #ELSE
123-45-6789 #IF $Company = 'IBM'
LET $EMPLID = '062910'
Display 1234567.89 999,999,999.99
#ELSE
1,234,567.89 #IF $Company = 'CSC'
 Other advantages with the Show command: LET $EMPLID = '1496334'
 Controls the cursor position on screen. #ELSE
LET $EMPLID = 'No Employee ID Found..'
 Sends beeping signals.
#END-IF
 Make the screen fields blinks, bold, and underline #END-IF
138. What would be the output of below program? #END-IF
BEGIN-PROGRAM #END-IF
SHOW '12345'
PRINT $EMPLID (1,1)
SHOW '6789' CLEAR-LINE
SHOW 'ABCDEFGHI' END-PROGRAM
END-PROGRAM 146. Sample Program on #IFDEF.
Output Would be: BEGIN-PROGRAM
12345
#IFDEF DEBUGH
6789ABCDEFGHI
PRINT 'Employee ID in Hewitt: 55849' (+1,1)
139. What would be the output of below program?
#ENDIF
BEGIN-PROGRAM
SHOW '12345' #IFDEF DEBUGI
SHOW '6789' CLEAR-LINE
PRINT 'Employee ID in IBM: 062910' (+1,1)
SHOW 'ABCDEFGHI'
SHOW '123456789' CLEAR-SCREEN
#ENDIF
SHOW 'ABCDEFGHI' #IFDEF DEBUGC
END-PROGRAM
PRINT 'Employee ID in CSC: 1496334' (+1,1)
Output Would be:
#ENDIF
ABCDEFGHI
First 3 show statements will be processed then clears the END-PROGRAM
screen then 4th show will be processed, so Output would
If the Command Line Flag is –DEBUGH Output would be:
be only the last Show Statement.
Employee ID in Hewitt: 55849.
#Debug: If the Command Line Flag is –DEBUGI Output would be:
'Employee ID in IBM: 062910
140. About #Debug Command?
Statements which are proceeding with #debug will If the Command Line Flag is –DEBUGC Output would be:
execute when we pass –DEBUG command line argument. 'Employee ID in CSC: 1496334
141. Assume there is a Statement in the SQR. If the Command Line Flag is –DEBUGHIC Output would
#DEBUGx Show ' Program Ended’. be:
What happen if we not specify the -DEBUGx
Employee ID in Hewitt: 55849
command line flag?
Employee ID in IBM: 062910
The statement will not be processed during the Compile
stage, and therefore will not be executed. Employee ID in CSC: 149633
142. Assume -DEBUGxyz is a command line flag. Then 147. Sample Program on #IFNDEF.
how many substitution variables will be created in
the SQR?
SQR automatically creates four substitution variables.
DEBUG, DEBUGx, DEBUGy, and DEBUGz.
143. Assume– DEBUGxyz is command line flag and the
SQR Data Elements
following are debug statements in the SQR. 148. How many types of Data Elements are there in
#DEBUGx show ‘X’ SQR?
1. SQR Columns 160. How to declare Global Variables?
2. Variables No need to declare, by default all the variables are Global.
3. Literals 161. How to declare Local Variables in SQR?
There are 2 two ways to make variables Local.
SQR Columns 1) Begin-Procedure <Procedure-Name> (List of Variables)
149. About SQR Column Variables? Mention Variable Names next to the Procedure name in
 Column variables are the Fields defined in the Begin-Procedure Section, then the list of variables will be
database. local to the particular procedure. We cannot access in other
 It can be any type – Character, Number, or Date. procedure.
2) Begin-Procedure <Procedure-Name> Local
150. How can we identify SQR Columns?
SQR database Column Variables are prefixed with (&). Since the procedure is local, all the variables used in this
procedure become Local. If any variable there with initial
151. Can we make any changes to SQR Columns? underscore (#_Amount) indicates a Global Variable.
No, we can’t as SQR Columns are Read-Only Variables. Local procedure can return a value to a global variable by
152. Is it required to declare SQR Columns? specifying an initial colon (:#amount) within its parameter
No need to declare explicitly. list.
153. Sample Program about Column Variables? Example:
BEGIN-PROGRAM
BEGIN-PROGRAM
SHOW ' DEMO OF LOCAL/GLOBAL VARIABLES'
BEGIN-SELECT LOOPS = 2
DO PROCEDURE1
EMPLID
DO PROCEDURE2 (#LOCAL_NUMBER2)
EFFDT
DO PROCEDURE3 (#LOCAL_NUMBER3)
COMPANY &Company_Name
DO PROCEDURE4 (#LOCAL_NUMBER4, #LOCAL_NUMBER5)
COMPRATE
DO PROCEDURE6
SHOW &EMPLID DO PROCEDURE7
SHOW &EFFDT END-PROGRAM
SHOW &Company_Name
SHOW &COMPRATE BEGIN-PROCEDURE PROCEDURE1 LOCAL

! ADD 100 TO &COMPRATE ! This Statement will give an error as Column LET #LOCAL_NUMBER1 = 1
Variables are Read-Only, we can’t perform any operations. Move it to any user SHOW 'IN PROCEDURE1 - #LOCAL_NUMBER1: ' #LOCAL_NUMBER1
defined variables and perform any operations. END-PROCEDURE

MOVE &COMPRATE TO #Salary


ADD 100 TO #Salary BEGIN-PROCEDURE PROCEDURE2 (#LOCAL_NUMBER2)

SHOW #Salary LET #LOCAL_NUMBER2 = 2


SHOW 'IN PROCEDURE2 - #LOCAL_NUMBER2: ' #LOCAL_NUMBER2
FROM PS_JOB END-PROCEDURE
END-SELECT
END-PROGRAM BEGIN-PROCEDURE PROCEDURE3 (:#LOCAL_NUMBER3)
LET #LOCAL_NUMBER3 = 3
Variables SHOW 'IN PROCEDURE3 - #LOCAL_NUMBER3: ' #LOCAL_NUMBER3
END-PROCEDURE
154. How many types of Variables can SQR support?
1. String Variables ($): BEGIN-PROCEDURE PROCEDURE4 (:#LOCAL_NUMBER4, #LOCAL_NUMBER5)
2. Numeric Variables(#): LET #LOCAL_NUMBER4 = 4
Integers, Float, and Decimal numbers. LET #LOCAL_NUMBER5 = 5
SHOW 'IN PROCEDURE4 - #LOCAL_NUMBER4: ' #LOCAL_NUMBER4
Difference between float, decimal, integer
SHOW 'IN PROCEDURE4 - #LOCAL_NUMBER5: ' #LOCAL_NUMBER5
3. Date Variables ($): END-PROCEDURE
4. List Variables (%):
List Variables contain ordered collections of sqr variables. BEGIN-PROCEDURE PROCEDURE6
LET #GLOBAL_NUMBER = 6
List Variable to hold multiple rows of information. SHOW 'IN PROCEDURE6 - #GLOBAL_NUMBER: ' #GLOBAL_NUMBER
List Variables are not nested; we can not include one list END-PROCEDURE
variables with in another.
List Variables cannot be passed as parameters to locale BEGIN-PROCEDURE PROCEDURE7
functions. SHOW 'IN PROCEDURE7 - #LOCAL_NUMBER1: ' #LOCAL_NUMBER1
SHOW 'IN PROCEDURE7 - #LOCAL_NUMBER2: ' #LOCAL_NUMBER2
List Variables cannot be declared via Declare-Variable
SHOW 'IN PROCEDURE7 - #LOCAL_NUMBER3: ' #LOCAL_NUMBER3
command.
SHOW 'IN PROCEDURE7 - #LOCAL_NUMBER4: ' #LOCAL_NUMBER4
List Variables are created and manipulated using let SHOW 'IN PROCEDURE7 - #LOCAL_NUMBER5: ' #LOCAL_NUMBER5
command. SHOW 'IN PROCEDURE7 - #GLOBAL_NUMBER: ' #GLOBAL_NUMBER
5. Document Marker (@): END-PROCEDURE

Useful to mix the static text with the database values. OUTPUT:
155. Are SQR Variables Case Sensitive?
DEMO OF LOCAL/GLOBAL VARIABLES
No. $name is same as $NAME. IN PROCEDURE1 - #LOCAL_NUMBER1: 1.000000
And there are no restrictions on Variable name length. It IN PROCEDURE2 - #LOCAL_NUMBER2: 2.000000
can be of any length. IN PROCEDURE3 - #LOCAL_NUMBER3: 3.000000
IN PROCEDURE4 - #LOCAL_NUMBER4: 4.000000
156. What would be the default values assigned to
IN PROCEDURE4 - #LOCAL_NUMBER5: 5.000000
Numeric Variables?
IN PROCEDURE6 - #GLOBAL_NUMBER: 6.000000
Zero. IN PROCEDURE7 - #LOCAL_NUMBER1: 0.000000
157. What would be the default values assigned to IN PROCEDURE7 - #LOCAL_NUMBER2: 0.000000
String and Date Variables? IN PROCEDURE7 - #LOCAL_NUMBER3: 3.000000
NULL. IN PROCEDURE7 - #LOCAL_NUMBER4: 4.000000
158. How to pass an argument value back to its IN PROCEDURE7 - #LOCAL_NUMBER5: 0.000000

calling Procedure? IN PROCEDURE7 - #GLOBAL_NUMBER: 6.000000


SQR for PeopleSoft: End of Run.
Prefix with a Colon :
159. What is the command to declare Variables? Literals
Using DECLARE-VARIABLE.
162. How many types of Literals can SQR support?
String Literals, Numeric Literals, Data Constants. WHEN = 'HEWITT'
LET $EMPLID = '55849'
String Literals must be enclosed with single quotes. For
BREAK
example: ‘Srinivas’.
WHEN = 'IBM'
LET $EMPLID = '062910'
BREAK

Loops WHEN = 'CSC'


LET $EMPLID = '1496334'
BREAK
163. How many types of Looping and Conditional
WHEN-OTHER
Statements are available in SQR? LET $EMPLID = 'EMPLOYEE ID NOT FOUND..'
1. While END-EVALUATE
2. If PRINT $EMPLID (1,1)

3. Evaluate 169. About BREAK?


164. When the code inside While Statement will  Useful to come out from Evaluate and while
execute? Statements.
When the While Condition is true.  Can’t be used with IF Loop alone.
BEGIN-PROGRAM
Inside code will execute till the condition gets failed.
LET #I = 10
165. When the Code inside IF Statement will execute? IF 1
When the IF condition is True. SHOW #I
When IF condition is True it returns Non Zero. When False BREAK
returns Zero. END-IF
END-PROGRAM
166. Sample Program about While?
Above Program gives an error stating that ‘BREAK found
Ex1:
outside 'WHILE' or 'EVALUATE' statement.’
LET #I = 1
WHILE #I <= 10
PRINT #I (1,+5)
LET #I = #I +1 SQR Commands
END-WHILE
It Returns: 1 2 3 4 5 6 7 8 9 10 170. What are the Arithmetic Commands available in
Ex2: Break – Exits from the while condition then SQR?
continues with the process. 1. Add:
LET #I = 1
Add 1 to #A
WHILE 1 Add #A to #B
IF #I = 10 Add #B to #C Round = 2
BREAK
2. Subtract – Subtract 1 from #a
END-IF
PRINT #I (1,+5) 3. Multiple – Multiply 5 Times #a
LET #I = #I +1 4. Divide – Divide 5 into #a
END-WHILE 171. What is the difference between Let and Move?
PRINT ‘AFTER WHILE LOOP.’ (+1,1)
It Returns: 1 2 3 4 5 6 7 8 9 Both are useful to assign values.
AFTER WHILE LOOP. Let Move
167. Sample Program about IF? We can assign expressions We can’t assign expressions.
to a variable. EX: Move #Num + 1 to
Ex1:
EX: Let #Num = #Num + 1 #Num
IF $COMPANY = 'HEWITT' Source and destination fields Source and destination fields
LET $EMPLID = '55849' should be of Same type. can be different type.
END-IF
Can’t convert the data type
IF $COMPANY = 'IBM' as Source and Destination Converts the data type.
LET $EMPLID = '062910' fields should same type.
END-IF Can Edit the value. Can Edit the Value.
LET $NUM1 = '123456789' LET $NUM1 = '123456789'
IF $COMPANY = 'CSC'
LET $NUM2 = EDIT($NUM1, ‘XXX- MOVE $NUM1 TO $NUM2 XXX-XXX-
LET $EMPLID = '1496334' XXX-XXXX’) XXXX
END-IF
172. What are the String Manipulation Commands
PRINT $EMPLID (+1,1) available in SQR?
IF $COMPANY <> 'HEWITT' AND $COMPANY <> 'IBM' AND $COMPANY <> Find, Concat, Extract, String, Unstring, Uppercase and
'CSC' Lowercase, Encode.
PRINT 'EMPLOYEE ID NOT FOUND..' (+1,1)
END-IF 1. Find: Finds for the Specified value in the given
string. If value found then returns the position number
Ex2: otherwise returns -1.
IF $COMPANY = 'HEWITT'
FIND 'R' IN 'SRINIVAS' 0 #POS1 !Returns 1
LET $EMPLID = '55849'
FIND 'R' IN 'SRINIVAS' 1 #POS2 !Returns 1
ELSE
FIND 'R' IN 'SRINIVAS' 2 #POS3 !Returns -1
IF $COMPANY = 'IBM'
FIND 'A' IN 'SRINIVAS' 3 #POS4 !Returns 6
LET $EMPLID = '062910'
FIND 'Z' IN 'SRINIVAS' 0 #POS5 !Returns -1
ELSE
FIND 'I' IN 'SRINIVAS' 1 #POS6 !Returns 2
IF $COMPANY = 'CSC'
FIND 'I' IN 'SRINIVAS' 3 #POS7 !Returns 4
LET $EMPLID = '1496334'
ELSE 2. Concat: It joins two values together and result will
PRINT 'EMPLOYEE ID NOT FOUND..' (+1,1) be stored in second field.
END-IF
BEGIN-PROGRAM
END-IF
LET $A = 'A'
END-IF
LET $B = 'B'
PRINT $EMPLID (+1,1) SHOW $A !RETURNS A
168. Sample Program about Evaluate? SHOW $B !RETURNS B
EVALUATE $COMPANY CONCAT $A WITH $B
SHOW $A !RETURNS A USE HR80DEV
SHOW $B !RETURNS BA END-SETUP
END-PROGRAM

3. ||: Using || symbol, we can also Concat two Strings


or two dates. But both the arguments should be same
type.
Operators
BEGIN-PROGRAM 176. How many types of Operators are there in SQR?
LET $A = 'A' String and Arithmetic Operators: ||, +, -, ^, *, /, %, +,
LET $B = 'B' -
SHOW $A !RETURNS A Relational Operators: >, <, >=, <=, <>, !=, =, And, Or,
SHOW $B !RETURNS B
Not.
LET $C = $A || $B
SHOW $A !RETURNS A
SHOW $B !RETURNS B
SHOW $C
END-PROGRAM
!RETURNS AB
Built-in Functions
4. Extract: Copies a portion of String into other. First 177. How many types of Built in Functions are there in
position starts with Zero. SQR?
BEGIN-PROGRAM
1. File-Related Functions.
LET $INPUT_DATA = 'Srinivas,55849,Hewitt,Gurgaon,India' 2. Date Functions.
EXTRACT $NAME from $INPUT_DATA 0 8 !Returns Srinivas
3. Numeric Functions.
EXTRACT $EMPLID FROM $INPUT_DATA 9 5 !Returns 55849
EXTRACT $COMPANY FROM $INPUT_DATA 15 6 !Returns Hewitt 4. String Functions.
EXTRACT $LOCATION FROM $INPUT_DATA 22 7 !Returns Gurgaon
5. Miscellaneous Functions.
EXTRACT $COUNTRY FROM $INPUT_DATA 30 5 !Returns India
END-PROGRAM
File-Related Functions
5. String: Concatenates all the variables with the
mentioned delimiter and assigns into destination variable. 178. What are the File Related Functions available in
SQR?
BEGIN-PROGRAM
Delete, Rename, Exists.
LET $NAME = 'SRINIVAS'
LET $EMPLID = '55849' 1. Delete – It Delete the file and returns 0 when
LET $COMPANY = 'HEWITT' success otherwise returns Non Zero.
LET $LOCATION = 'GURGAON' Ex:
LET $COUNTRY = 'INDIA' BEGIN-PROGRAM
STRING $NAME $EMPLID $COMPANY $LOCATION $COUNTRY BY ',' INTO LET $FILE1 = 'C:\TEMP\IBM.TXT'
$DATA LET #STATUS = DELETE($FILE1)
SHOW $DATA !RETURNS SRINIVAS,55849,HEWITT,GURGAON,INDIA SHOW #STATUS
END-PROGRAM END-PROGRAM

6. Unstring: Useful to copy some portion of a string 2. Rename – It rename the old file name with New
into one of more variables. file name and returns 0 when success otherwise returns non
Zero.
BEGIN-PROGRAM
LET $INPUT_DATA = 'SRINIVAS,55849,HEWITT,GURGAON,INDIA' Ex:
UNSTRING $INPUT_DATA BY ',' INTO $NAME $EMPLID $COMPANY $LOCATION $COUNTRY BEGIN-PROGRAM
SHOW 'NAME: ' $NAME !RETURNS SRINIVAS LET $FILE1 = 'C:\TEMP\IBM.TXT'
SHOW 'EMPL ID: '$EMPLID !RETURNS 55849 LET $FILE2 = 'C:\TEMP\CSC.TXT'
SHOW 'COMPANY: ' $COMPANY !RETURNS HEWITT LET #STATUS = RENAME($FILE1, $FILE2)
SHOW 'LOCATION: ' $LOCATION !RETURNS GURGAON SHOW #STATUS
SHOW 'COUNTRY: ' $COUNTRY !RETURNS INDIA END-PROGRAM
END-PROGRAM If no file Path mentioned then new file will be created in the
SQR Directory.
7. Uppercase: Converts a String variable to
Uppercase. 3. Exists – Returns 0 if the file exists in the specified
location otherwise returns non Zero.
LET $NAME = 'srinivas'
Ex:
UPPERCASE $NAME
BEGIN-PROGRAM
SHOW $NAME !Returns SRINIVAS
LET $FILE1 = 'C:\TEMP\IBM.TXT'
8. LowerCase: Converts a String variable to LET #STATUS = EXISTS($FILE1)
Lowercase. SHOW #STATUS
END-PROGRAM
LET $NAME = ‘SRINIVAS’
LOWERCASE $NAME
179. Sample Code to delete a file?
SHOW $NAME !Returns srinivas LET $FILE = C:\TEMP\TEMP.TXT
LET #FILE_EXISTS = EXISTS($FILE)
9. Encode: Encodes the value. Only values <001> to
IF #FILE_EXISTS = 0
<255> may be encoded.
SHOW 'DELETING EXISTING FILE (' $FILE ')....'
Ex: LET #DEL_FILE = DELETE($FILE)
IF #DEL_FILE != 0
183 is for Bullet
SHOW 'ERROR IN DELETING EXISTING DAT FILE ... '
124 is for Dash STOP QUIET
33 is for Exclamation. END-IF
END-IF
ENCODE '<183>SRINIVAS' INTO $NAME1 !RETURNS ·SRINIVAS
ENCODE '<33>SRINIVAS' INTO $NAME2 !RETURNS !SRINIVAS
Date Functions
173. Difference between Extract and Unstring/Let?
The EXTRACT command uses 0 as the first position. The 180. What are the Date Functions Available in SQR?
LET/SUBSTR command uses 1 as the first position. DateAdd, DateDiff, DateNow, DateToStr, StrToDate.
174. DATE-TIME: Gives the current Date and Time of Local 1. DateAdd: Returns the New Data after adding
System. Specified Units.
175. USE: Uses the mentioned database rather using the BEGIN-PROGRAM

default. LET $DATE = DATEADD($CURRENT-DATE, 'YEAR', 1)


SHOW $DATE
BEGIN-SETUP
LET $DATE = DATEADD($CURRENT-DATE, 'QUARTER', 1)
SHOW $DATE ATAN LOG SINH
LET $DATE = DATEADD($CURRENT-DATE, 'MONTH', 1)
CEIL LOG10 SQRT
SHOW $DATE
LET $DATE = DATEADD($CURRENT-DATE, 'WEEK', 1) COS MOD TAN
SHOW $DATE COSH POWER TANH
LET $DATE = DATEADD($CURRENT-DATE, 'DAY', 1)
SHOW $DATE
DEG RAD TRUNC
LET $DATE = DATEADD($CURRENT-DATE, 'HOUR', 1)
SHOW $DATE 1. ABS: Gives the Absolute value.
LET $DATE = DATEADD($CURRENT-DATE, 'MINUTE', 1) LET #NUM1 = ABS(10) !Returns 10.000000
SHOW $DATE LET #NUM2 = ABS(-20) !Returns 20.000000
LET $DATE = DATEADD($CURRENT-DATE, 'SECOND', 1) LET #NUM3 = ABS(30.55) !Returns 30.550000
SHOW $DATE LET #NUM4 = ABS(-40.65) !Returns 40.650000
END-PROGRAM
2. DateDiff: Returns the difference between two 2. EXP: The function EXP returns the exponential
dates in the specified Units. value for the numeric expression. This is like the power
BEGIN-PROGRAM
function with a base e.
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1), LET #NUM1 = EXP(1) !Returns 2.718281828459
$CURRENT-DATE, 'YEAR') LET #NUM2 = EXP(10) !Returns 22026.465794807
SHOW $DIFFERENCE
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1), 3. LOG: Returns the natural logarithm of Given
$CURRENT-DATE, 'QUARTER') Number.
SHOW $DIFFERENCE
LET #NUM1 = LOG(1) !Returns 0
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1),
$CURRENT-DATE, 'MONTH') LET #NUM2 = LOG(10) !Returns 2.302585
SHOW $DIFFERENCE LET #NUM3 = LOG(100) !Returns 4.605170
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1), LET #NUM4 = LOG(1000) !Returns 6.907755
$CURRENT-DATE, 'WEEK') LET #NUM5 = LOG(10000) !Returns 9.210340
SHOW $DIFFERENCE
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1), 4. log10: Returns the base-10 logarithm of given
$CURRENT-DATE, 'HOUR') value.
SHOW $DIFFERENCE
LET #NUM1 = LOG10(1) !Returns 0
LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1),
$CURRENT-DATE, 'MINUTE') LET #NUM2 = LOG10(10) !Returns 1

SHOW $DIFFERENCE LET #NUM3 = LOG10(100) !Returns 2

LET $DIFFERENCE = DATEDIFF(DATEADD($CURRENT-DATE, 'YEAR', 1), LET #NUM4 = LOG10(1000) !Returns 3


$CURRENT-DATE, 'SECOND') LET #NUM5 = LOG10(10000) !Returns 4
SHOW $DIFFERENCE
5. MOD: Returns the Remainder value.
END-PROGRAM
3. DateNow: Gives the Client machine Date and LET #NUM1 = MOD(10,5) !Returns 0
Time. LET #NUM2 = MOD(10,3) !Returns 1
BEGIN-PROGRAM LET #NUM3 = MOD(10,4) !Returns 2
LET $LOCAL_DATE = $CURRENT-DATE LET #NUM4 = MOD(10,7) !Returns 3
LET $CLIENT_DATE = DATENOW() LET #NUM5 = MOD(10,9) !Returns 1
SHOW $LOCAL_DATE
6. Power: Returns the value of x_value raised to the
SHOW $CLIENT_DATE
power of y_value.
END-PROGRAM
4. DateToStr: Converts Date value into String. LET #NUM1 = POWER(4,2) !Returns 16
LET #NUM2 = POWER(9,2) !Returns 81
BEGIN-PROGRAM
LET #NUM3 = POWER(10,2) !Returns 100
LET $NEW_DT = DATETOSTR($CURRENT-DATE,'MM/DD/YYYY')
LET #NUM4 = POWER(10,3) !Returns 1000
PRINT $NEW_DT (+1,1)
LET #NUM5 = POWER(10,4) !Returns 10000
LET $NEW_DT = DATETOSTR($CURRENT-DATE,'MM-DD-YYYY')
PRINT $NEW_DT (+1,1) 7. round: used to round a numeric value to the
LET $NEW_DT = DATETOSTR($CURRENT-DATE,'YYYY-MM-DD')
number of decimals specified
PRINT $NEW_DT (+1,1)
LET $NEW_DT = DATETOSTR($CURRENT-DATE,'MM-YYYY-DD') LET #NUM1 = ROUND(10.0,0) ! RETURNS 10.000000
PRINT $NEW_DT (+1,1) LET #NUM2 = ROUND(10.1,0) ! RETURNS 10.000000
END-PROGRAM LET #NUM3 = ROUND(10.4,0) ! RETURNS 10.000000
LET #NUM4 = ROUND(10.5,0) ! RETURNS 11.000000
Output:
LET #NUM5 = ROUND(10.6,0) ! RETURNS 11.000000
10/03/2010 LET #NUM6 = ROUND(10.9,0) ! RETURNS 11.000000
10-03-2010
2010-10-03 LET #NUM1 = ROUND(10.00,1) ! RETURNS 10.000000
LET #NUM2 = ROUND(10.11,1) ! RETURNS 10.100000
10-2010-03
LET #NUM3 = ROUND(10.44,1) ! RETURNS 10.400000
5. StrToDate: Converts the string into date type. LET #NUM4 = ROUND(10.55,1) ! RETURNS 11.600000
BEGIN-PROGRAM LET #NUM5 = ROUND(10.66,1) ! RETURNS 11.700000
LET $STRING_DATE = '31-12-2000' LET #NUM6 = ROUND(10.99,1) ! RETURNS 11.000000
PRINT $STRING_DATE (+1,1)
LET $DATETYPE_DATE = STRTODATE($STRING_DATE, 'DD-MM-YYYY')
LET #NUM1 = ROUND(10.000,2) ! Returns 10.000000
PRINT $DATETYPE_DATE (1,1)
LET #NUM2 = ROUND(10.111,2) ! Returns 10.110000
END-PROGRAM
LET #NUM3 = ROUND(10.444,2) ! Returns 10.440000
Output: LET #NUM4 = ROUND(10.555,2) ! Returns 10.560000
Dec 31 2000 12:00AM LET #NUM5 = ROUND(10.666,2) ! Returns 10.670000
31-12-2000 LET #NUM6 = ROUND(10.999,2) ! Returns 11.000000

8. SQRT: Returns Square Root of given number.


Numeric Functions
LET #NUM1 = SQRT(4) !Returns 2
181. What are the Numeric Functions available in LET #NUM2 = SQRT(9) !Returns 3
LET #NUM3 = SQRT(16) !Returns 4
SQR? LET #NUM4 = SQRT(25) !Returns 5
ABS E10 ROUND LET #NUM5 = SQRT(35) !Returns 5.916080

ACOS EXP SIGN String Functions


ASIN FLOOR SIN
182. What are the String Functions Available in SQR?
Chr, SubStr, SubStrb, To_Char, To_Number LET #Y = 2
LET #Z = 3
1. Chr: Returns the String for the given ASCII Value. LET #RESULT2 = COND(#X,#Y,#Z)
SHOW #RESULT2 !RETURNS 3
BEGIN-PROGRAM
END-PROGRAM
LET $VALUE1 = CHR(73) !I
LET $VALUE2 = CHR(66) !B 3. EDIT: Edits the given value based on the Edit Mask
LET $VALUE3 = CHR(77) !M And returns String Value.
LET $STRING = $VALUE1 || $VALUE2 || $VALUE3
LET $PHONE = edit(0123456789, '(XXX) XXX-XXXX') !(123) 456-789.
SHOW $STRING
LET $TODAY = EDIT($CURRENT-DATE, 'DD/MM/YYYY') !03/10/2010
END-PROGRAM
LET $PRICE1 = EDIT(1, '999.99') ! 1.00
Output: IBM LET $PRICE2 = EDIT(15, '999.99') ! 15.00
LET $PRICE3 = EDIT(155, '999.99') !155.00
2. SubStr: Extracts the specified portion from the
LET $PRICE4 = EDIT(1555, '999.99') !***.**
String.
BEGIN-PROGRAM Difference between Edit and Format:
LET $NAME = 'SRINIVAS'
Edit will be useful to edit field value while Printing the data.
LET $SUBSTR = SUBSTR($NAME, 1, 1) !S
Format will be useful with
LET $SUBSTR = SUBSTR($NAME, 1, 8) !SRINIVAS
LET $SUBSTR = SUBSTR($NAME, 1, 10) !SRINIVAS Input Command to ask the user to enter the date in
LET $SUBSTR = SUBSTR($NAME, 1, 0) ! WILL NOT RETURN. mentioned format.
LET $SUBSTR = SUBSTR($NAME, LENGTH($NAME)-2, 3) !VAS
END-PROGRAM 4. GETENV: Returns the value of specified
environment variable.
3. SubStrb: It’s same as SubStr but we have to give
the length value in bytes rather than in Characters. LET $Command.exe=getenv('COMSPEC')
LET $Temp_Folder = GETENV('TEMP')
4. To_Char: Converts the Source value to a String LET $Operating_System = GETENV('OS')
Type. LET $PS_Home = GETENV('PS_HOME')
LET $User = GETENV('USER')
BEGIN-PROGRAM
LET #NUM = 10 5. INSTR: It will search for the given string in the
LET #NUM = #NUM + 10 !WE CAN PERFORM THE ARITHMETIC OPERATIONS input string and returns the position number. If the given
SHOW #NUM string not found then returns Zero.
LET $NUM = TO_CHAR(#NUM)
SHOW $NUM LET #RESULT1 = INSTR('SRINIVAS','V',1) !RETURNS 6
!LET $NUM = $NUM + 10 !WE CAN'T PERFORM ARITHMETIC OPERATIONS ON LET #RESULT2 = INSTR('SRINIVAS','V',3) !RETURNS 6
STRINGS LET #RESULT3 = INSTR('SRINIVAS','V',7) !RETURNS 0
END-PROGRAM LET #RESULT4 = INSTR('SRINIVAS','D',1) !RETURNS 0
LET #RESULT5 = INSTR('SRINIVAS','I',1) !RETURNS 3
5. To_Number: Converts the Source value to a LET #RESULT6 = INSTR('SRINIVAS','I',4) !RETURNS 5
Number Type. LET #RESULT7 = INSTR('SRINIVAS','NI',1) !RETURNS 4
BEGIN-PROGRAM LET #RESULT8 = INSTR('SRINIVAS','NI',5) !RETURNS 0
LET $NUM = '10'
6. ISBLANK: Returns 1 if the source value is an
!LET $NUM = $NUM + 10 !WE CAN'T PERFORM ARITHMETIC OPERATIONS ON
STRINGS empty String / Null String / composed of white spaces.
SHOW $NUM Otherwise returns 0.
LET #NUM = TO_NUMBER($NUM) LET $ISBLANK1 = ISBLANK('') !RETURNS 1
SHOW #NUM LET $ISBLANK2 = ISBLANK(' ') !RETURNS 1
LET #NUM = #NUM + 10 !WE CAN PERFORM THE ARITHMETIC OPERATIONS LET $ISBLANK3 = ISBLANK('SRINIVAS') !RETURNS 0
SHOW #NUM
END-PROGRAM 7. ISNULL: Returns 1 if the source value is null
otherwise returns 0.
Miscellaneous Functions LET $ISNULL1 = ISNULL('') !Returns 1
LET $ISNULL2 = ISNULL(' ') !Returns 0
183. What are the Miscellaneous Functions LET $ISNULL3 = ISNULL('SRINIVAS') !Returns 0
available in SQR? 8. Length: Returns the length of the given value. It
ARRAY ISBLANK RPAD always returns number. It can’t find the length of number
ASCII ISNULL RTRIM fields.
ASCIIIC LENGTH SETPROPERTY LET $LEN= LENGTH('SRINIVAS') !RETURNS 8
COND LENGTHB TO_MULTI_BYTE LET $LEN=LENGTH(EDIT($CURRENT-DATE,'YYYY-MM-DD')) !RETURNS 10
EDIT LOWER TO_SINGLE_BYTE !LET $LEN = LENGTH (15) ! IT RETURNS ERROR.
GETENV LPAD TRANSLATE 9. Lengthb: it same as length function but it returns
GETCAPABILITY LTRIM UPPER in Bytes rather than Characters.
GETPROPERTY NVL WRAPDEPTH
INSTR RANGE 10. Lower: It returns the Lower case to the given
INSTRB ROMAN
source value. Source value should be String.
LET $LOWER1 = LOWER('SRINIVAS') !Returns srinivas
1. ASCII: Returns the ASCII value for the first
LET $LOWER2 = LOWER('srinivas') !Returns srinivas
character of input string.
LET $LOWER3 = LOWER('SRINIvas') !Returns srinivas
LET $NAME = ASCII('SRINIVAS') !RETURNS 83
LET $LOWER4 = LOWER('10') !Returns 10
LET $NAME = ASCII('IBM') !RETURNS 73
LET $LOWER5 = LOWER(10) !Returns Error.
LET $NAME = ASCII('CSC') !RETURNS 67
11. LPAD: Pads the value to the left side of the source
2. COND: #Result = cond(#X, #Y, #Z)
value.
If the X value is Zero then returns Z otherwise returns Y. $LPAD1 = LPAD('SRINIVAS',10,'*') !RETURNS **SRINIVAS
BEGIN-PROGRAM $LPAD2 = LPAD('SRINIVAS',5,'*') !RETURNS SRINIVAS
LET #X = 1 $LPAD3 = LPAD('SRINIVAS',15,'.') !RETURNS .......SRINIVAS
LET #Y = 2
LET #Z = 3 12. LTRIM: Trims characters from left side.
LET #RESULT1 = COND(#X,#Y,#Z)
LTRIM(' SRINIVAS', ' ') !'SRINIVAS'
SHOW #RESULT1 !RETURNS 2
LTRIM('000123', '0') !'123'
LTRIM('123123SRINIVAS', '123') !'SRINIVAS'
LET #X = 0
LTRIM('123123SRINIVAS123', '123') !'SRINIVAS123'
LTRIM('XYXZYYYTECH', 'XYZ') !'TECH' Local Procedures.
LTRIM('6372SRINIVAS', '0123456789') !'SRINIVAS'
185. What are the Reserved Variables Available in
13. nvl: Let $Rtn = nvl($X,$Y)
SQR?
Returns Y if X value is null otherwise returns X
#CURRENT-COLUMN {SQR-ENCODING}
let $Phone_NBR = '123456789' $CURRENT-DATE $SQR-HOSTNAME
LET $RtnValue = nvl($Phone_NBR,'Phone Number not #CURRENT-LINE {SQR-HOSTNAME}
found')
#END-FILE $SQR-LOCALE
Output: 123456789 #PAGE-COUNT #SQR-MAX-COLUMNS
let $Phone_NBR = '' #RETURN-STATUS #SQR-MAX-LINES
LET $RtnValue = nvl($Phone_NBR,'Phone Number not #SQL-COUNT #SQR-PID
found')
$SQL-ERROR $SQR-PLATFORM
Output: Phone Number not found. #SQL-STATUS {SQR-PLATFORM}
14. Roman: Returns the roman number. $SQR-DATABASE $SQR-PROGRAM
LET $ROMAN = ROMAN(1) !RETURNS I {SQR-DATABASE} $SQR-REPORT
LET $ROMAN = ROMAN(2) !RETURNS II
$SQR-DBCS $SQR-VER
LET $ROMAN = ROMAN(3) !RETURNS III
LET $ROMAN = ROMAN(4) !RETURNS IV {SQR-DBCS} $USERNAME
LET $ROMAN = ROMAN(5) !RETURNS V $SQR-ENCODING
LET $ROMAN = ROMAN(6) !RETURNS VI
LET $ROMAN = ROMAN(7) !RETURNS VII 1. #current-column: Gives the current Column
LET $ROMAN = ROMAN(8) !RETURNS VIII Number.
LET $ROMAN = ROMAN(9) !RETURNS IX 2. #current-line: Gives the Current Line Number.
LET $ROMAN = ROMAN(10) !RETURNS X 3. #page-count: Gives the Current Page Number. We
15. range: let $result = range(X,Y,Z) can also reset the page numbers. EX: #let #page-count =
10.
returns 1 if X value is between Y and Z otherwise returns 0 4. $current-date: Gives the Local machine Date and
LET $RESULT1 = RANGE(15,10,20) !RETURNS 1 Time. We can also use Edit.
LET $RESULT2 = RANGE(25,10,20) !RETURNS 0
Ex: print $current-date (1,1) Edit 'DD-Mon-YYYY'
16. RPAD: Pads the value to the right side of the 5. #end-file Identifies end of file. At end of file it
source value. returns 1 otherwise it returns 0.
$RPAD1 = RPAD('SRINIVAS',10,'*') !RETURNS **SRINIVAS BEGIN-PROGRAM
$RPAD2 = RPAD('SRINIVAS',5,'*') !RETURNS SRINIVAS OPEN 'C:\TEMP\TEMP1.TXT' AS 10 FOR-READING RECORD = 100
$RPAD3 = RPAD('SRINIVAS',15,'.') !RETURNS .......SRINIVAS WHILE 1
READ 10 INTO $INPUTDATA:100
17. RTRIM: Trims characters from Right side. IF #END-FILE
BREAK
RTRIM('SRINIVAS ', ' ') !'SRINIVAS'
ELSE
RTRIM('123000', '0') !'123'
SHOW $INPUTDATA
RTRIM('SRINIVAS123123', '123') !'SRINIVAS'
END-IF
RTRIM('123SRINIVAS123123', '123') !'123SRINIVAS'
END-WHILE
RTRIM('TECHXYXZYYY', 'XYZ') !'TECH'
END-PROGRAM
RTRIM('SRINIVAS6372', '0123456789') !'SRINIVAS'
6. #sql-count: Gives the Count of Rows affected by a
18. Translate: It will replace the value. DML statement (INSERT, UPDATE, or DELETE). This is
Let $Phone = translate('012-345-6789','-','/') equivalent to ROWCOUNT in Oracle or SYBASE.
Output would be 012/345/6789 Assume ABC table is having 100 Rows.
Begin-Select
19. Upper: It returns the Upper case to the given
EMPLID
source value. Source value should be String.
NAME
LET $UPPER1 = UPPER('SRINIVAS') !RETURNS SRINIVAS
FROM PS_ABC
LET $UPPER2 = UPPER(Srinivas) !RETURNS SRINIVAS
End-Select
LET $UPPER3 = UPPER('srinivas’) !RETURNS SRINIVAS
LET $UPPER4 = UPPER('10') !RETURNS 10 Show #sql-count
It returns 100.
20. wrapdepth
Begin-SQL
UPDATE PS_ABC SET NAME = ‘Srinivas S’ WHERE NAME =
‘Srinivas’
21. wrap
End-SQL
PRINT $TEXT1 (1,1) WRAP 150 5 KEEP-TOP LINE-HEIGHT=1 Show #sql-count
Next-Listing SkipLines=5 Need=10
It returns 1.
PRINT $TEXT2 (+1,1) WRAP 150 5 KEEP-TOP LINE-
HEIGHT=1 7. $sql-error: Gives the SQL Error Message. If there
is no error, $sql-error will not have any message.
8. $sql-status: Gives the SQL Status – Success /
Failure.
Reserved Variables or Pre- 9. $sqr-database: Gives the database type for which
SQR was compiled.
Defined Variables 10. $sqr-hostname: Gives the Computer Name.
184. What is the default scope assigned to Reserved 11. $sqr-locale: Gives the name of the current locale
Variables? 12. #sqr-max-columns: Gives the maximum number
 By Default all the Reserved Variables are of Columns that fits in a page. When there is a change in
Global. Layout accordingly Max column number will change.
 No Need to declare explicitly. 13. #sqr-max-lines: Gives the maximum number of
 Prefix _ when we use Reserved Variables in Lines that fits in a page. When there is a change in Layout
accordingly Max Line number will change.
14. #sqr-pid: Gives the Process ID of the current SQR. 194. About Multiple Occurrence fields?
15. $sqr-platform: Gives the Operating System Type.  An array can also supports the Multiple-
16. $sqr-program: Gives the name of the SQR Occurrence fields.
program.  For one field we can specify the number of
17. $sqr-report: Gives the Path and Name of the occurrences.
output file.  For multiple-occurrence fields, the field
18. $username: Gives the Database User Name. occurrence number starting from occurrence number zero.
195. What are the commands available with an Array?
1. Create-Array: Useful to Create an Array.
Arrays 2. Clear-Array: Useful to clear the data from an Array.
186. What is an Array? 3. Get: Useful to get the data from an Array.
 An Array is a collection of similar group of
 GET $EMP_ID FROM EMP_DETAIL(10)
Fields.
 GET $EMP_ID $EMP_NAME FROM EMP_DETAIL(10)
 An Array is a memory structure that consists
of Rows and Fields.  GET $EMP_ID $EMP_DESIGNATION FROM EMP_DETAIL(#I)
EMP_ID EMP_DESIGNATION
 An Array is a buffer useful to store the data
 GET $PHONE1 $PHONE2 $PHONE3 FROM EMP_DETAIL(#I)
temporarily. PHONE(0) PHONE(1) PHONE(2)
187. What are the Advantages of Array?
4. Put: Useful to insert the data into an array
 To Re-order the output.
 To Generate Cross-Tabular Report.  PUT ‘100’ INTO EMP_DETAILS(10)

 To Generate Multilevel Subtotals.  PUT ‘100’ ‘SRINU’ INTO EMP_DETAILS(#I)

 To Simplify SQL.  PUT &A.EMP_ID &A.EMP_DESIGNATION INTO


EMP_DETAILS(10) EMP_ID EMP_DESIGNATION
 To Group Variables.
 PUT $PHONE1 $PHONE2 $PHONE3 INTO EMP_DETAIL(0)
188. At what Stage Arrays will be created? PHONE(0) PHONE(1) PHONE(2)
Arrays will be created during Compile time.
5. Let: Useful to Get and Put the data into an Array
189. In which Section Arrays can be created?
Arrays can be created in Setup / Program / Procedure  LET EMP_DETAILS.EMP_ID(10) = ‘100’
Sections. But it is better to create in Setup Section as  LET EMP_DETAILS.EMP_ID(#ROW_NUM) = 100
arrays buffer will be created at Compile Time and Setup  LET EMP_DETAILS.PHONE(#I, #J) = &A.PHONE
Section is also processed at Compile Time.  LET $EMP_ID = EMP_DETAIL.EMP_ID(10)
190. What is the Syntax of an Array?
 LET $PHONE= EMP_DETAIL.PHONE(#I, #J)
CREATE-ARRAY
NAME = <NAME OF THE ARRAY> 6. Array-Add:
SIZE= <SIZE OF ARRAY> Array-Subtract:
FIELD=<FIELD NAME1>:<FIELD TYPE> Array-Multiply:
FIELD=<FIELD NAME2>:<FIELD TYPE>[:OCCURS] Array-Divide:
BEGIN-SETUP
Field Types: Decimal, Float, Integer, Number, Char, CREATE-ARRAY
Date. NAME = EMP_DTLS
SIZE= 25
Example: FIELD = EARNS:NUMBER
FIELD = OTH_EARN:NUMBER
CREATE-ARRAY END-SETUP
NAME = EMPLOYEE_DETAILS
BEGIN-PROGRAM
SIZE= 25 LET EMP_DTLS.EARNS(1) = 100
FIELD=EMP_NAME:CHAR LET EMP_DTLS.OTH_EARN(1) = 300
FIELD=EMP_ID:CHAR LET #EARNS1 = EMP_DTLS.EARNS(1)
LET #OTH_EARN1 = EMP_DTLS.OTH_EARN(1)
FIELD=EMP_DESIGNATION:CHAR
FIELD=EMP_DOB:DATE ARRAY-ADD 400 TO EMP_DTLS(1) EARNS
FIELD=EMP_DOJ: DATE
ARRAY-ADD 200 TO EMP_DTLS(1) OTH_EARN
FIELD=EMP_PHONE: NUMBER: 3
FIELD=EMP_SALARY:NUMBER ! Or we can write in Single Statement

 In the above example, An Array will be !ARRAY-ADD 400 200 TO EMP_DTLS(1)


created with the name Employee_Details and with a size of LET #EARNS2 = EMP_DTLS.EARNS(1)
25 rows. LET #OTH_EARN2 = EMP_DTLS.OTH_EARN(1)
 Each row (record) represents the information ARRAY-MULTIPLY 20 10 TIMES EMP_DTLS(1)
of one employee.
LET #EARNS3 = EMP_DTLS.EARNS(1)
 And every row consists of 7 fields. LET #OTH_EARN3 = EMP_DTLS.OTH_EARN(1)
191. Is it possible to increase the array size once ARRAY-SUBTRACT 2000 1000 FROM EMP_DTLS(1)
defined?
LET #EARNS4 = EMP_DTLS.EARNS(1)
No, not possible. We can give the array size dynamically LET #OTH_EARN4 = EMP_DTLS.OTH_EARN(1)
but once it defined we can’t alter it.
ARRAY-DIVIDE 8 4 INTO EMP_DTLS(1)
192. When SQR will throw an error ‘Out of Memory’?
LET #EARNS5 = EMP_DTLS.EARNS(1)
When Array Size exceeds 64K Bytes. LET #OTH_EARN5 = EMP_DTLS.OTH_EARN(1)
193. What are the default values will be assigned to
SHOW #EARNS1 ! RETURNS 100
an Array Fields? SHOW #OTH_EARN1 ! RETURNS 300
 When an array is created all its field values SHOW #EARNS2 ! RETURNS 500
SHOW #OTH_EARN2 ! RETURNS 500
are automatically initialized based on the default values. SHOW #EARNS3 ! RETURNS 10000
 If no initialized value specified for a field, then SHOW #OTH_EARN3 ! RETURNS 5000
SHOW #EARNS4 ! RETURNS 8000
default value will assigned. SHOW #OTH_EARN4 ! RETURNS 4000
 Numeric values (Number, Decimal, Float, SHOW #EARNS5 ! RETURNS 1000
SHOW #OTH_EARN5 ! RETURNS 1000
Integer) are set to 0. END-PROGRAM
 All string fields are set to NULL. 196. Can we use the substitution variables as the size
 All date fields are set to NULL. parameters?
Yes. And it is better way to use the substitution variables
as the size parameters, So that we can easily change the LET #I = 0
size of the Array. WHILE #I < #COUNTER
GET $EMPLID $NAME $COMPANY $COUNTRY $ZIP $PHONE FROM EMP_DTLS(#I)
197. What happened if we enter values more than the
BEGIN-SQL
maximum Array size? INSERT INTO XYZ VALUES ($EMPLID, $NAME, $COMPANY, $COUNTRY, $ZIP,
SQR aborts the program execution and displays the error $PHONE)
message. END-SQL
ADD 1 TO #I
198. Sample Program about Arrays.
END-WHILE
Assume ABC table is having following data. END-PROCEDURE

EMPLID NAME COMPANY COUNTRY POSTAL PHONE


111 AAA IBM IND 500032 123456789
222
333
BBB
CCC
CSC
RBS
IND
IND
600069
600069
123456789
123456789
Load Lookup
444 DDD IBM USA 123456 123456789 199. About Load Lookup Concept?
555 EEE CSC USA 123456 123456789  Useful to improve the performance of the Program.
666 FFF RBS ROI 123456 123456789
 It reduces the number of tables that are joined in one
Below program select.
Will read the data from ABC table. 200. What is the use of Load-Lookup Command?
And inserts into an Array EMP_DTLS. Fetch the data from database and loads into Temporary
And Updates the Array. Memory.
And then Reads from Array and inserts into XYZ table. 201. What is the use of Lookup Command?
Based on the Key Values it will search in the memory and
BEGIN-SETUP
returns the associated value.
Create-Array
Name = EMP_DTLS 202. In which Sections Load Lookups can be created?
Size= 25  We can create Load Lookups in any of the Sections.
FIELD = EMPLID:CHAR  It’s better to create in the SETUP Section.
FIELD = NAME:CHAR
FIELD = COMPANY:CHAR
 If used in the SETUP section, it is processed only once.
FIELD = COUNTRY:CHAR  If used in a procedure, it is processed each time it is
FIELD = ZIP:CHAR encountered.
FIELD = PHONE:CHAR 203. How to retrieve Multiple Columns?
BEGIN-SQL By a double pipe symbol (||) Multiple Columns can be
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME = retrieved.
'ABC')
204. Syntax of Load Lookup?
DROP TABLE ABC;
CREATE TABLE ABC (EMPLID CHAR(5), NAME CHAR(5), COMPANY CHAR(5), Load-Lookup Name = <Name>
COUNTRY CHAR(5), ZIP CHAR(6), PHONE CHAR(10)); Table = <Table Name>
INSERT INTO ABC VALUES ('111','AAA','IBM','IND','500032','123456789');
Rows = <nn>
INSERT INTO ABC VALUES ('222','BBB','CSC','IND','600069','123456789');
INSERT INTO ABC VALUES ('333','CCC','RBS','IND','600069','123456789'); Key = <Primary Key>
INSERT INTO ABC VALUES ('444','DDD','IBM','USA','123456','123456789'); Return_Value = <Field Name>
INSERT INTO ABC VALUES ('555','EEE','CSC','USA','123456','123456789'); Where = <FIELD NAME>=<Field Value>
INSERT INTO ABC VALUES ('666','FFF','RBS','ROI','123456','123456789');
205. Sample Program about Load Lookup?
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME = BEGIN-SETUP
'XYZ')
BEGIN-SQL
DROP TABLE XYZ;
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME = 'ABC')
CREATE TABLE XYZ (EMPLID CHAR(5), NAME CHAR(5), COMPANY CHAR(5),
DROP TABLE ABC;
COUNTRY CHAR(5), ZIP CHAR(6), PHONE CHAR(10));
CREATE TABLE ABC (EMPLID CHAR(5), NAME CHAR(5), COMPANY CHAR(5),
END-SQL
COUNTRY CHAR(5), ZIP CHAR(6), PHONE CHAR(10));
END-SETUP
INSERT INTO ABC VALUES ('111','AAA','IBM','IND','500032','123456789');
BEGIN-PROGRAM INSERT INTO ABC VALUES ('222','BBB','CSC','IND','600069','123456789');
DO SELECT INSERT INTO ABC VALUES ('333','CCC','RBS','IND','600069','123456789');
DO ARRAY_COMMANDS INSERT INTO ABC VALUES ('444','DDD','IBM','USA','123456','123456789');
DO INSERT INSERT INTO ABC VALUES ('555','EEE','CSC','USA','123456','123456789');
END-PROGRAM INSERT INTO ABC VALUES ('666','FFF','RBS','ROI','123456','123456789');
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME = 'XYZ')
BEGIN-PROCEDURE SELECT
DROP TABLE XYZ;
LET #COUNTER = 0
CREATE TABLE XYZ (EMPLID CHAR(5), NAME CHAR(5), COMPANY CHAR(5),
BEGIN-SELECT
COUNTRY CHAR(5), ZIP CHAR(6), PHONE CHAR(10));
EMPLID
END-SQL
NAME
COMPANY
Load-Lookup Name = EMP_DTLS
COUNTRY
Table = ABC
ZIP
Rows = 10
PHONE
Key = EMPLID
PUT &EMPLID &NAME &COMPANY &COUNTRY &ZIP &PHONE INTO
Return_Value = NAME
EMP_DTLS(#COUNTER)
END-SETUP
ADD 1 TO #COUNTER
FROM ABC
BEGIN-PROGRAM
END-SELECT
DO SELECT
END-PROCEDURE
END-PROGRAM
BEGIN-PROCEDURE ARRAY_COMMANDS
LET $PHONE = EMP_DTLS.PHONE(2) BEGIN-PROCEDURE SELECT
SHOW $PHONE BEGIN-SELECT
LET EMP_DTLS.PHONE(2) = '11111' EMPLID
PUT '22222' INTO EMP_DTLS(2) PHONE LOOKUP EMP_DTLS &EMPLID $NAME
GET $PHONE FROM EMP_DTLS(2) PHONE DO INSERT
SHOW $PHONE FROM ABC
END-PROCEDURE END-SELECT

BEGIN-PROCEDURE INSERT END-PROCEDURE


BEGIN-PROCEDURE INSERT Specifies procedures to invoke either after or before the
BEGIN-SQL value changes. These qualifiers can be used only within
INSERT INTO XYZ VALUES (&EMPLID, $NAME, '1','1','1','1') Select paragraph.
END-SQL
218. About SAVE Qualifier?
END-PROCEDURE
206. How load lookup will process when there are Previous value of a break field will be stored.
duplicate rows? 219. About LEVEL Qualifier?
Use Level Qualifier when there is a need to apply On-
break on more than one field.
207. What is the difference between Array and 220. How many Break Levels we can set?
Load Lookup? The maximum number of ON-BREAK levels is determined
Load Lookup Array by the ON-BREAK setting in the [Processing-Limits]
section of the PSSQR.INI file. The default is 30, but you
We can create Load Lookups in
any of 5 Sections. Better to create Arrays can be created only in can increase this setting. Its maximum value is 64K-1
in SETUP Section otherwise it will Setup / Program / Procedure (64*1024 – 1 = 65,535 bytes).
process each time it is Sections. 221. Assume On-Break statements are as below
encountered. BEGIN-SELECT
Buffers will be created at compile Buffers will be created at STATE (+1,1,2) ON-BREAK LEVEL=1 AFTER=STATE-TOT SKIPLINES=2
time. compile time. COUNTRY (,+2,14) ON-BREAK LEVEL=2 AFTER=COUNTRY-TOT
SKIPLINES=1
Data will be populated into CITY (,+2,14) ON-BREAK LEVEL=3 AFTER=CITY-TOT
Data will be populated into Load-
Arrays at Execution Time. We ...
lookup at Compilation Time
have to write the code END-SELECT
automatically.
(Let/Get/Put).
222. What would be order When city breaks?
Arrays size will not be
Size of the load lookup will be The city-tot procedure is executed.
increased. Program will throw
increased dynamically once the
an error once it reaches the 223. What would be order When COUNTRY breaks?
allocated size reached.
max size. First the city-tot procedure is executed, and then the
country-tot procedure is executed.
224. What would be order When state breaks?
Break Logic The city-tot, country-tot, and state-tot procedures are
processed in that sequence.
208. What is Break? 225. Assume On-Break statements are as below
A break is a change in the value of a field. BEGIN-SELECT
STATE (+1,1,2) ON-BREAK LEVEL=1 BEFORE=BEF-STATE AFTER=STATE-
209. What is the Syntax of Break Statement?
TOT
ON-BREAK [ PRINT = { ALWAYS | CHANGE | CHANGE/TOP-PAGE | NEVER } ]
COUNTRY (,+2,14) ON-BREAK LEVEL=2 BEFORE=BEF-CNTY AFTER=CNTY-
[ SKIPLINES = NN ] TOT
[ PROCEDURE = PROCEDURE_NAME ] CITY (,+2,14) ON-BREAK LEVEL=3 BEFORE=BEF-CITY AFTER=CITY-TOT
[ AFTER = PROCEDURE_NAME ] ...
[ BEFORE = PROCEDURE_NAME ] END-SELECT
[ SAVE = TXT_VAR ]
226. What would be order when state breaks?
[ LEVEL = NN ]
[ SET = NN ]
City-tot, Cnty-tot, State-tot, Bef-state, Bef-cnty, Bef-city
210. What is use of Break Logic? 227. What would be order upon entering the query at
BEGIN-SELECT?
1. Avoids printing redundant data.
The three BEFORE procedures are executed in sequence:
2. Skip lines when the value of the Column is changed.
Bef-state, Bef-cnty, Bef-city
3. Print a value only if changed.
228. What would be order After the last row is
4. To add spaces in the report. retrieved, at END-SELECT?
5. Perform conditional processing on variables that The three AFTER procedures are executed in sequence:
change. City-tot, Cnty-tot, State-tot
6. Execute a special procedure before or after the break. 229. What is the use of this statement
7. Print Subtotals. Next-listing Skiplines=1 Need=4?
211. What is the purpose of On-break Qualifiers? The SKIPLINES=1 argument skips one line between
Qualifiers define specific actions to be taken when the records, and then renumbers the current line as line 1.
break occurs. The NEED=4 argument checks for the available row count,
212. What are the Qualifiers available with Break? if 4 rows are not there it will not print in the current page.
PRINT, SKIPLINES, PROCEDURE, BEFORE, AFTER, SAVE, 230. Can we perform Break operations on Numeric
LEVEL. Fields?
213. What is the default Qualifier for On-Break? We cannot use ON-BREAK with SQR numeric variables. To
PRINT is the default Qualifier for the On-break. It can be perform break processing on a numeric variable, you must
used for both Explicit and Implicit printing. first move its value to a string variable and then set ON-
214. What are the Options available with PRINT BREAK on that.
Qualifier? 231. Sample Programs – Break Logic?
1. Always: Break field will be printed for each detail Assume a table ABC is having following data.
group. COMPANY COUNTRY PAY_END_DT EMPLID NAME SALARY
2. Change: Printed only when its value is changed. This IBM USA 01/01/2000 111 AAA 10500
is the default option. IBM USA 01/01/2001 111 AAA 15000
3. Change/Top-Page: prints the value when there is IBM USA 01/01/2000 222 BBB 25000
change in the filed and when there is a page break. IBM IND 01/01/2000 333 CCC 15000
4. Never: Value will not be printed. IBM IND 01/01/2001 333 CCC 20000

215. About SKIPLINES Qualifier? IBM IND 01/01/2002 444 DDD 50000
IBM ROI 01/01/2000 555 EEE 30000
Specifies how many lines to skip when the value changes.
IBM ROI 01/01/2000 666 FFF 75000
216. About PROCEDURE Qualifier?
IBM ROI 01/01/2000 777 GGG 15000
Specifies the procedure to be invoked when the value
CSC USA 01/01/2000 888 HHH 20000
changes.
CSC USA 01/01/2001 888 HHH 25000
217. About AFTER / BEFORE Qualifiers?
CSC USA 01/01/2002 888 HHH 35000
CSC USA 01/01/2000 999 III 100000 234. SKIPLINES & ORDER BY
CSC IND 01/01/2000 123 JJJ 100000 BEGIN-SELECT
CSC IND 01/01/2001 123 JJJ 200000 COMPANY (,1) ON-BREAK SKIPLINES = 1
COUNTRY (,+5)
CSC IND 01/01/2002 123 JJJ 300000
PAY_END_DT (,+5)
IF EXISTS (SELECT 'X' FROM SYSOBJECTS WHERE TYPE = 'U' AND NAME = 'ABC') EMPLID (,+5)
DROP TABLE ABC; NAME (,+5)
CREATE TABLE ABC (COMPANY CHAR(5), COUNTRY CHAR(5), PAY_END_DT SALARY (,+5)
PSDATE, EMPLID CHAR(5), NAME CHAR(5), SALARY DECIMAL(7));
INSERT INTO ABC VALUES ('IBM','USA','01/01/2000','111','AAA',10500 ); POSITION (+1)
INSERT INTO ABC VALUES ('IBM','USA','01/01/2001','111','AAA',15000 ); FROM ABC ORDER BY PAY_END_DT
INSERT INTO ABC VALUES ('IBM','USA','01/01/2000','222','BBB',25000 ); END-SELECT
INSERT INTO ABC VALUES ('IBM','IND','01/01/2000','333','CCC',15000 );
INSERT INTO ABC VALUES ('IBM','IND','01/01/2001','333','CCC',20000 );
INSERT INTO ABC VALUES ('IBM','IND','01/01/2002','444','DDD',50000 ); Output:
INSERT INTO ABC VALUES ('IBM','ROI','01/01/2000','555','EEE',30000 );
INSERT INTO ABC VALUES ('IBM','ROI','01/01/2000','666','FFF',75000 );
INSERT INTO ABC VALUES ('IBM','ROI','01/01/2000','777','GGG',15000 ); IBM USA Jan 01 2000 12:00AM 111 AAA 10500
INSERT INTO ABC VALUES ('CSC','USA','01/01/2000','888','HHH',20000 ); USA Jan 01 2000 12:00AM 222 BBB 25000
INSERT INTO ABC VALUES ('CSC','USA','01/01/2001','888','HHH',25000 ); IND Jan 01 2000 12:00AM 333 CCC 15000
INSERT INTO ABC VALUES ('CSC','USA','01/01/2002','888','HHH',35000 ); ROI Jan 01 2000 12:00AM 555 EEE 30000
INSERT INTO ABC VALUES ('CSC','USA','01/01/2000','999','III',100000); ROI Jan 01 2000 12:00AM 666 FFF 75000
INSERT INTO ABC VALUES ('CSC','IND','01/01/2000','123','JJJ',100000); ROI Jan 01 2000 12:00AM 777 GGG 15000
INSERT INTO ABC VALUES ('CSC','IND','01/01/2001','123','JJJ',200000);
INSERT INTO ABC VALUES ('CSC','IND','01/01/2002','123','JJJ',300000); CSC USA Jan 01 2000 12:00AM 888 HHH 20000
USA Jan 01 2000 12:00AM 999 III 100000
232. SKIPLINES IND Jan 01 2000 12:00AM 123 JJJ 100000
BEGIN-SELECT IND Jan 01 2001 12:00AM 123 JJJ 200000
COMPANY (,1) ON-BREAK SKIPLINES = 1 USA Jan 01 2001 12:00AM 888 HHH 25000
COUNTRY (,+5) IBM IND Jan 01 2001 12:00AM 333 CCC 20000
PAY_END_DT (,+5) USA Jan 01 2001 12:00AM 111 AAA 15000
EMPLID (,+5) IND Jan 01 2002 12:00AM 444 DDD 50000
NAME (,+5)
CSC USA Jan 01 2002 12:00AM 888 HHH 35000
SALARY (,+5)
POSITION (+1) IND Jan 01 2002 12:00AM 123 JJJ 300000
FROM ABC
END-SELECT 235. LEVEL & SKIPLINES & SAVE & AFTER
LET #COMPANY_TOTAL = 0
Company will be printed only once and is not repeated.
LET #COUNTRY_TOTAL = 0
Skiplines argument provides a line break between each break. BEGIN-SELECT
COMPANY (,1) ON-BREAK LEVEL = 1 SKIPLINES = 1 SAVE = $COMPANY
Output: AFTER = COMPANY_TOTAL
COUNTRY (,+5) ON-BREAK LEVEL = 2 SKIPLINES = 1 SAVE = $COUNTRY
AFTER = COUNTRY_TOTAL
IBM USA Jan 01 2000 12:00AM 111 AAA 10500
USA Jan 01 2001 12:00AM 111 AAA 15000 PAY_END_DT (,+5)
USA Jan 01 2000 12:00AM 222 BBB 25000 EMPLID (,+5)
IND Jan 01 2000 12:00AM 333 CCC 15000 NAME (,+5)
IND Jan 01 2001 12:00AM 333 CCC 20000
SALARY (,+5)
IND Jan 01 2002 12:00AM 444 DDD 50000
ROI Jan 01 2000 12:00AM 555 EEE 30000 POSITION (+1)
ROI Jan 01 2000 12:00AM 666 FFF 75000 LET #COUNTRY_TOTAL = #COUNTRY_TOTAL + &SALARY
ROI Jan 01 2000 12:00AM 777 GGG 15000 FROM ABC
END-SELECT
CSC USA Jan 01 2000 12:00AM 888 HHH 20000
USA Jan 01 2001 12:00AM 888 HHH 25000 END-PROCEDURE
USA Jan 01 2002 12:00AM 888 HHH 35000
USA Jan 01 2000 12:00AM 999 III 100000 BEGIN-PROCEDURE COMPANY_TOTAL
IND Jan 01 2000 12:00AM 123 JJJ 100000
IND Jan 01 2001 12:00AM 123 JJJ 200000 LET $COMPANY = ltrim(rtrim($COMPANY,' '),' ')
IND Jan 01 2002 12:00AM 123 JJJ 300000 PRINT 'Total Amount for the Company ' (+1,1)
PRINT $COMPANY (,+1)
233. SKIPLINES & LEVEL PRINT #COMPANY_TOTAL (,+1)
BEGIN-SELECT LET #COMPANY_TOTAL = 0
COMPANY (,1) ON-BREAK SKIPLINES = 2 POSITION (+1,1)
COUNTRY (,+5) ON-BREAK LEVEL = 2 SKIPLINES = 1 END-PROCEDURE
PAY_END_DT (,+5)
EMPLID (,+5) BEGIN-PROCEDURE COUNTRY_TOTAL
NAME (,+5) LET $COMPANY = ltrim(rtrim($COMPANY,' '),' ')
SALARY (,+5) LET $COUNTRY = ltrim(rtrim($COUNTRY,' '),' ')
POSITION (+1) PRINT '-' (,65,9) FILL
FROM ABC LET $DESC = $COMPANY || ' - ' || $COUNTRY || ' Total: '
END-SELECT PRINT $DESC (+1,45)
PRINT #COUNTRY_TOTAL (,65)
Output: POSITION (+1,6)
LET #COMPANY_TOTAL = #COMPANY_TOTAL + #COUNTRY_TOTAL
IBM USA Jan 01 2000 12:00AM 111 AAA 10500 LET #COUNTRY_TOTAL = 0
Jan 01 2001 12:00AM 111 AAA 15000 END-PROCEDURE
Jan 01 2000 12:00AM 222 BBB 25000
Output:
IND Jan 01 2000 12:00AM 333 CCC 15000
Jan 01 2001 12:00AM 333 CCC 20000
Jan 01 2002 12:00AM 444 DDD 50000
IBM USA Jan 01 2000 12:00AM 111 AAA 10500
ROI Jan 01 2000 12:00AM 555 EEE 30000 Jan 01 2001 12:00AM 111 AAA 15000
Jan 01 2000 12:00AM 666 FFF 75000 Jan 01 2000 12:00AM 222 BBB 25000
Jan 01 2000 12:00AM 777 GGG 15000
---------
IBM - USA Total: 50500.00
CSC
USA Jan 01 2000 12:00AM 888 HHH 20000 IND Jan 01 2000 12:00AM 333 CCC 15000
Jan 01 2001 12:00AM 888 HHH 25000
Jan 01 2002 12:00AM 888 HHH 35000 Jan 01 2001 12:00AM 333 CCC 20000
Jan 01 2000 12:00AM 999 III 100000 Jan 01 2002 12:00AM 444 DDD 50000
---------
IND Jan 01 2000 12:00AM 123 JJJ 100000
IBM - IND Total: 85000.00
Jan 01 2001 12:00AM 123 JJJ 200000
Jan 01 2002 12:00AM 123 JJJ 300000
ROI Jan 01 2000 12:00AM 555 EEE 30000 PRINT ‘150000.50’ (1,1) EDIT :$MASK1 !IT RETURNS $1.50.000.50
Jan 01 2000 12:00AM 666 FFF 75000 PRINT ‘SRINIVAS’ (+1,1) EDIT :$MASK2 !IT RETURNS SRI-NI-VAS
Jan 01 2000 12:00AM 777 GGG 15000 242. What are the formatting Commands can be
--------- allowed with Print Command?
IBM - ROI Total: 120000.00
 BOLD: To print the data in Bold.
Total Amount for the Company IBM 255500.00  BOX: To print a graphical box around the printed data.
 CENTER: To print the data from the centre of the
CSC USA Jan 01 2000 12:00AM 888 HHH 20000 page. When we use this command the position qualifier is
Jan 01 2001 12:00AM 888 HHH 25000 ignored.
Jan 01 2002 12:00AM 888 HHH 35000
 UNDERLINE: To print the data with underline
Jan 01 2000 12:00AM 999 III 100000
characters.
---------
CSC - USA Total: 180000.00  FILL: To fill a specified character or string in the page.
EX: print '*' (1,1,79) fill
IND Jan 01 2000 12:00AM 123 JJJ 100000  SHADE: To print shaded graphical box around the
Jan 01 2001 12:00AM 123 JJJ 200000 printed data.
Jan 01 2002 12:00AM 123 JJJ 300000
 NOP: To hide a field temporarily from printing.
---------
CSC - IND Total: 600000.00  DATE: we can’t use this with the numeric columns or
variables.
Total Amount for the Company CSC 780000.00  MATCH: Compares a field to a list of key values and if
a match is found, prints corresponding string at specified
line and column.
236. For the above program add PRINT = NEVER Qualifier  MONEY: indicates that the column or variable is to be
for COMPANY field then output would be same with small formatted using the MONEY-EDIT-MASK from the current
change – COMPANY will not be printed. locale.
 NUMBER: NUMBER indicates that the column or
variable is to be formatted using the NUMBER-EDIT-MASK
from the current locale.
Print Command  ON-BREAK:
237. What is the use of Print Command?  CODE-PRINTER:
Useful to print the data on the page at a specified position.  WRAP: wraps text at word spaces. Additional text is
238. What are the position parameters available with moved to a new line. After a string wraps, the current
Print Command? position is one character to the right of the last character
in the column.
Print <Variable Name> (X, Y, Z).
EX: Print &comment (48,20,0) wrap 50 3
 X: Specifies the Line (Row) Number of the Page.
 EDIT: The field is edited before it is printed.
 Y: Specifies the Column Number of the Page.
Edit Mask Types:
 Z: Specifies the number of positions allocated for the
field. 1. Numeric edit:
239. About Implicit Printing? Special characters available in the Numeric edit mask:
Implicit printing is nothing but printing the data without 8, 9, 0, B, $, V, MI, PR, PS, NA, NU, E, (DOT). , (COMMA).
using the Print command by placing position parameters 8 - Zero fill to the right of the decimal point, trim leading
immediately after the column name. blanks.
Sample Program: 9 - Zero fill to the right of the decimal point, space fill to
Begin-Program the left.
Do Printing 2. Date edit
End-Program Special characters available in the Date edit mask:
Begin-Procedure Printing YYYY, RR, Q, WW, DDD, MONTH, RM, CC, BC or AD, (HH,
MT, SS), NNNNNN, AM or PM, |.
Begin-Select
3. Text edit
EMPLID (1,1)
Special characters available in the Text edit mask:
NAME (1,15)
 X: It place the character in the
FROM ABC
output
End-Select
For example: move ‘123456789’ to $zip
End-Procedure
Print $zip (1,1) edit xxxxx-xxxx
240. About Explicit Printing?
Output: 12345-6789
Explicit Printing is nothing but Print the data using Print
 b: It inserts the blank space in the
Command.
output
Sample Program:
For example: move ‘123456789’ to $zip
Begin-Program
Print $zip (1,1) edit (xxx)bxxx-xxxx
Do Printing
Output: (123) 456-789
End-Program
 ~ (Tilde): It skips a character in the
Begin-Procedure Printing output.
Begin-Select For example: move ‘123456789’ to $zip
EMPLID Print $zip (1,1) edit xxx~~~xxx
NAME Output: 123789
Print 'the Employee Id Is:' $EMPID (1,25) And we can use any character as a text constant in the
Print 'the Employee Name Is:' $NAME (2,25) output.
End-Select For example: move ‘srinu’ to $name
End-Procedure Print $name (1, 1) edit name:bxxxxx
241. Can we use Edit Mask Dynamically? Output: name. srinu
Yes. We can. 243. How do you make a zero value blank on a report?
MOVE '$9,99,999.99' TO $MASK1 BEGIN-PROGRAM
MOVE ‘XXX-XX-XXX’ TO $MASK2 PRINT #A (1,1) EDIT B
SHOW #A EDIT B
END-PROGRAM
244. Sample Program Formatting Commands.
BEGIN-PROGRAM
PRINT 'NOP' (+1,1) NOP
PRINT 'CENTER' (+1,1) CENTER
PRINT 'BOLD' (+1,1) BOLD
PRINT 'UNDERLINE' (+1,1) UNDERLINE
PRINT 'BOX' (+1,1) BOX
PRINT 'SHADE' (+1,1) SHADE
PRINT '*' (+1,1,35) FILL
PRINT '1234567890' (+1,1,35) FILL
PRINT '-' (+1,1,35) FILL
END-PROGRAM

Report Types
248. How many types of Reports we can generate thru
SQR?
1. Cross-Tabular Reports
2. Form Reports
3. Master/Detail Reports
4. Letters or Documents
245. Sample Program on Number Edit Masks 5. Multiple-reports
BEGIN-PROGRAM 6. Mailing Labels
PRINT 'NUMBER EDIT MASKS' (+2,1) BOLD BOX SHADE
PRINT 1570.50 (+1,1) EDIT $9999.99 Cross-Tabular Reports
PRINT 1570.147 (+1,1) EDIT $9999.99
PRINT 1570.143 (+1,1) EDIT $9999.99  Cross-tabular reports are matrix- or
PRINT 123456.7845600 (+1,1) EDIT 999999.9999 spreadsheet-like reports.
PRINT 123456.7845600 (+1,1) EDIT 888888.8888  These reports are useful to display Summary
END-PROGRAM numeric data.
 Mostly Arrays will be useful to generate
Cross-Tabular Reports.

246. Sample Program on Text Edit Mask.


BEGIN-PROGRAM
PRINT 'TEXT EDIT MASKS' (+2,1) BOLD BOX SHADE
PRINT 'SRINIVAS' (+1,1) EDIT 'XXX-XX-XXX' Form Reports
PRINT 'SRINIVAS' (+1,1) EDIT 'XXXBXXBXXX'
PRINT 'SRINIVAS' (+1,1) EDIT 'XXX~XX~XXX'  In Tabular reports we can get the column
PRINT 'SRINIVAS' (+1,1) EDIT NAME:BXXXXXXXX heading at the top of the page.
PRINT 'SRINIVAS' (+1,1) EDIT NAME.BXXXXXXXX
PRINT '9600099986' (+1,1) EDIT '(XX)-(XXX)-(XXX)-(XX)'
END-PROGRAM

 In Form Reports each row information will be


printed in a separate page.

247. Sample Program on Date Edit Mask.


BEGIN-PROGRAM
PRINT 'DATE EDIT MASKS' (+2,1) BOLD BOX SHADE
PRINT $CURRENT-DATE (+1,1)
PRINT $CURRENT-DATE (+1,1) EDIT 'YYYY-MM-DD'
PRINT $CURRENT-DATE (+1,1) EDIT 'MONTH DD, YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MM-DD-YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MONTH-DD-YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MON-DD-YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MM-D-YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MM-DAY-YYYY'
PRINT $CURRENT-DATE (+1,1) EDIT 'MM-DY-YYYY'
 New-Page is the command useful to create
END-PROGRAM
the Form Reports.
Master/Detail Reports
 Master/Detail Reports shows the hierarchal
information.
 Master data will be fetched from one table
thru a Select.
 Detailed data will be fetched from other table New-page
thru other Select. End-Procedure !Write_Letter

 Mostly Bind variables will be useful to Multiple-Reports


generate Master Detailed Reports. 249. What the purpose and situations to create
 Sample Program Multiple Reports?
BEGIN-PROGRAM  When there is a requirement to create more than
DO GET_MASTER_DATA one report simultaneously based on the Common Data.
END-PROGRAM 250. How can we create Multiple Reports?
BEGIN-PROCEDURE GET_MASTER_DATA  Using Declare-Report command.
BEGIN-SELECT DISTINCT  This command is coded in the Setup Section
EMPLID
 It includes Name of the report / Layout / printer.
DO GET_DETAILED_DATA
FROM PS_JOB WHERE COMPANY = 'IBM'  The name of the Layout and the type of the printer
END-SELECT may different that depends on the business requirements.
END-PROCEDURE  If no printer type is specified, the default is
BEGIN-PROCEDURE GET_DETAILED_DATA LINEPRINTER.
BEGIN-SELECT  If no Layout is specified, then the default Layout is
COMPANY used.
GRS_YTD (+1,1)  Valid values for the Printer-Type arguments are HT-
GRS_QTD (+1,1)
HTML, HP- HPLASERJET, PS- POSTSCRIPT, LP-
GRS_MTD (+1,1)
LINEPRINTER
FROM PS_EARNINGS_BAL WHERE EMPLID = &EMPLID
END-SELECT 251. Procedure to Create Multiple Reports?
END-PROCEDURE
 We have to declare Layouts and Reports
in Setup section.
Letters or Documents
BEGIN-SETUP
 Used to create the Letters. DECLARE-LAYOUT REPROT1_LAYOUT
 We can mix the static text with the database PAPER-SIZE = (10, 11)
values. END-DECLARE

 We can also use document markers to mix DECLARE-LAYOUT REPROT2_LAYOUT


data with the letter. PAPER-SIZE = (20, 11)
 .b, Begin-Document, New-Page, Document END-DECLARE

Markers are the command mainly used with Letters. DECLARE-REPORT REPORT1
 Document Marker is used to mix data with the LAYOUT = REPORT1_LAYOUT
letter and Starts with ‘@’ symbol. ...
END-DECLARE
Sample Program
DECLARE-REPORT REPORT2
Begin-Program
LAYOUT = REPORT2_LAYOUT
Do MAIN
...
End-Program
END-DECLARE
Begin-Procedure MAIN END-SETUP
Begin-Select
EMPLID  While writing the heading we have to use
NAME for-reports.
STATE BEGIN-HEADING 10 FOR-REPORTS = (REPORT1)
COUNTRY ...
POSTAL END-HEADING
DO Write_Letter
BEGIN-HEADING 20 FOR-REPORTS = (REPORT2)
From PS_PERSONAL_DATA WHERE EMPLID IN (SELECT TOP 5 B.EMPLID FROM
PS_PERSONAL_DATA B WHERE B.STATE <> '' AND B.POSTAL <> '') ...
End-Select END-HEADING
End-Procedure
 New-Report command used to create
Begin-Procedure Write_Letter new reports and we have to give the report path.
Begin-Document (1, 1)
USE-REPORT REPORT1
&EMPLID
LET $REPORT1 = 'C: \TEMP\REPORT1.PDF
&NAME
NEW-REPORT REPORT1
@STATE_COUNTRY_POSTAL
.b USE-REPORT REPORT2
.b LET $REPORT2 = 'C: \TEMP\REPORT2.PDF
$current-date NEW-REPORT REPORT2
Dear Sir or Madam:
.b  Before writing any data, mention the
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX report name with Use-Report command.
XXXXXXXXXXXXXXX
USE-REPORT REPORT1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
PRINT 'FULL TIME EMPLOYEES DETAILS' (1, 1)
XXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX USE-REPORT REPORT2
.b PRINT 'PART TIME EMPLOYEES DETAILS' (1, 1)
.b
Sincerely, Mailing Labels
XXXXXXXXXXXXXXX
XXXXXXXXXXXX 252. What is the use of Mailing Labels?
XXXXXXXX Useful to print the data across the page.
End-Document In normal reports lot of space in a page will be wasted.
Position () @STATE_COUNTRY_POSTAL 253. What are the Commands mainly used with
Print &STATE () mailing labels?
Print ', ' ()
 COLUMNS – Useful to enable the Column.
Print &COUNTRY ()
Print ' ' ()  NEXT-COLUMN – Moves the cursor to the
Print &POSTAL () edit xxxxx-xxxx next column.
 USE-COLUMN 0 – Reinitialize the cursor with #end-file command identifies end of file. At end of file it
what ever the value specified in the use-column. In this returns 1.
situation it reinitialized with Zero position. 262. What is the use of WRITE Command?
 ALTER-PRINTER – Alter the printer Writes the data into a file.
environment at run time such as fonts, font size. WRITE 1 FROM 'SRINIVAS' '|' '111' '|' '999'
Ex: WRITE 1 FROM 'SRINIVAS' ',' '111' ',' '999'
ALTER-PRINTER WRITE 1 FROM 'SRINIVAS':5 ',' '111':5 ',' '999':5
FONT=4 ! HELVETICA WRITE 1 FROM $NAME $EMPLID $SALARY
POINT-SIZE = 4 WRITE 1 FROM $NAME:10 $EMPLID:10 $SALARY:10
FONT-TYPE = FIXED WRITE 1 FROM $NAME $COMMA $EMPLID $COMMA $SALARY
PITCH = 4 263. How to WRITE the data into file?
 DECLARE-LAYOUT – Change the paper  Specify the File Path and File name.
environment.  Specify the file number.
 Next-Listing –  Open the file for writing purpose.
254. Sample Program about Mailing Labels?  Write the data using Write Command.
BEGIN-PROGRAM
OPEN 'C:\CNU\OUTPUT.TXT' AS 1 FOR-WRITING RECORD=50
STATUS=#OPENSTAT
IF #OPENSTAT != 0
Flat Files SHOW 'ERROR WHILE OPENING FILE!!'
STOP QUIET
255. What is the use of flat files? END-IF

Flat files/Sequential files are used to Import/Export the BEGIN-SELECT


EMPLID
data from/Into database.
NAME
256. What are the main commands useful to work WRITE 1 FROM $NAME $EMPLID $SALARY
with Flat Files? FROM PS_PERSONAL_DATA
257. What are the file manipulation commands? END-SELECT
OPEN, READ, WRITE, CLOSE, FOR-READING, FOR- END-PROGRAM
WRITING, FOR-APPEND, #END-FILE, STATUS, STOP 264. Sample program which reads the data from a file
QUIET. and writes into another file.
258. About OPEN Command? BEGIN-PROGRAM
OPEN 'C:\CNU\INPUT.TXT' AS 1 FOR-READING RECORD=30
Useful to open a file for Reading / Writing / Append. STATUS=#OPENREADSTAT
FOR-READING IF #OPENREADSTAT != 0
FOR-WRITING SHOW 'ERROR WHILE OPENING FILE FOR READING!!'
STOP QUIET
FOR-APPEND
ELSE
259. What is the use of READ Command? OPEN 'C:\CNU\OUTPUT.TXT' AS 2 FOR-WRITING RECORD=30
To read Text and Binary Data from a file. STATUS=#OPENWRITESTAT
IF #OPENWRITESTAT != 0
EX:
SHOW 'ERROR WHILE OPENING FILE FOR WRITING!!'
READ 1 INTO $NAME:30 $EMPLID:11 $SALARY:10
STOP QUIET
READ #I INTO $NAME:30 $EMPLID:11 $SALARY:10 ELSE
READ 1 INTO $FILE_DATA:30 STATUS=#READSTAT WHILE 1
UNSTRING $FILE_DATA BY ',' INTO $NAME $EMPLID $SALARY READ 1 INTO $FILE_DATA:30 STATUS=#READSTAT
260. Code to READ data from a file? IF #READSTAT != 0
SHOW 'ERROR WHILE READING FILE!!'
 Specify the File Path and File name.
STOP QUIET
 Specify the File Number which identifies the file in ELSE
the application while reading or writing. It can be a IF #END-FILE = 1
Literals or a numeric variable (should be +ve and less BREAK
than 64000). END-IF
 Open the file for reading purpose. WRITE 2 FROM $FILE_DATA
END-IF
 Specify the length and file
END-WHILE
type(FIXED/FIXED_NOLF/VARY)
END-IF
 Read the data till end of the file. END-IF
BEGIN-PROGRAM END-PROGRAM
OPEN 'C:\CNU\INPUT.TXT' AS 1 FOR-READING RECORD=30
STATUS=#OPENSTAT 265. When you open a file with OPEN Command, and
IF #OPENSTAT != 0 then not writing any data. Will SQR generates a file?
SHOW 'ERROR WHILE OPENING FILE!!' Yes, SQR will create an empty file.
STOP QUIET 266. Can we write floating point values into a file?
ELSE
No, we can’t directly write floating point values into file.
WHILE 1
However we can first convert to string and then write the
READ 1 INTO $FILE_DATA:30 STATUS=#READSTAT
IF #READSTAT != 0
string.
SHOW 'ERROR WHILE READING FILE!!' 267. Can we write numeric variables?
STOP QUIET Yes, but when writing numeric variables, the length
ELSE argument is required. Only 1, 2, or 4 byte binary integers
IF #END-FILE = 1 are written.
BREAK
268. What is the command to close a file?
END-IF
UNSTRING $FILE_DATA BY ',' INTO $NAME $EMPLID $SALARY Using Close Command.
SHOW $NAME Ex: Close 5, Close #I
SHOW $EMPLID 269. Is it necessary to Close the file at the end of the
SHOW $SALARY
program?
END-IF
END-WHILE
Yes it’s required to Close the file once we done with
END-IF
reading or writing. Otherwise when we run the program
END-PROGRAM next time, SQR throws an error message stating that
‘Specified file number not opened for writing/reading.
261. How to identify the end of file?
After a file is opened, it remains open until explicitly
closed by the CLOSE command. OPEN 'C:\CNU\OUTPUT.CSV' AS 2 FOR-WRITING RECORD=50
STATUS=#OPENWRITESTAT
270. Open a file for Writing with the length of 80, WRITE 2 FROM $NAME1 ',' $NAME2
what happens when you try to write 100 END-PROGRAM
characters?
SQR will throw an error stating that ‘Length of Variables
exceeds record length’.
271. How many Maximum numbers of files we can SQCs
open at a time?
278. About SQCs?
256
 SQC is a Function Library file.
272. What is the maximum record length for the OPEN
 It can be called from SQR.
command?
 When there is a common code used in
The maximum is 32K bytes (32767).
multiple places, put that code in one place and name it as
273. Assume a program is having open statement like SQC. Include the SQC wherever we require instead writing
open 'D:\Temp\1.txt' as 1 for-writing record = 10. the entire code again.
But Temp directory is not available in D. So will the
279. What are the mandatory SQCs?
SQR creates a folder and opens the file in it or what
it will do? SETENV.SQC – Set Environment
Throws an error stating that ‘No Such File or Directory’ STDAPI.SQC – Routines to update run status
274. About FIXED/VARY and FIXED_NOLF file types? DATETIME.SQC – Routines for date and time formatting
FIXED: This file type assumes that all records contained 280. How to run SQCs?
within the file are the same length. Each record is We can’t run the SQCs directly. We have to include in any
terminated by a line terminator (system dependent). This of the SQR thru #include and call the Procedures of SQCs.
file type can be used when writing or reading binary data. 281. How to insert a SQC into SQR Program?
FIXED_NOLF: This file type assumes that all records #include ‘SQC name’ Ex: #include ‘setenv.sqc’
contained within the file are the same length with no line 282. How to update the Process Scheduler status in
terminator. This file type can be used when writing or SQR?
reading binary data.
 We have to make the SQR Program API
VARY: This is the default file type. This file type specifies Aware by including mandatory SQCs.
that the records can be of varying length. When reading
 And include STDAPI-INIT procedure at the
records, any data beyond the maximum length specified
beginning and STDAPI-TERM at the end of the SQR.
will be ignored.
 And Call Update-Prcs-Run-Status
275. Can we create Word Documents thru SQR?
procedure which will update PSPRCSRQST Table with
Yes. RUNSTATUS.
OPEN 'C:\OUTPUT.DOC AS 2 FOR-WRITING RECORD=50
283. What happens if STDAPI-INIT and STDAPI-TERM
276. What would be the output to the below are not included in the SQR?
statements?
SQR will run to success but Status in Process Monitor will
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10 not be get updated, it shows ERROR only.
write 1 from '123456789012345' 284. Where we have to place the SQC in the program
Output: Length of variables exceeds record length. if the SQC represents the Setup Section?
At the top of the program.
open 'C:\temp\Ouput.txt' as 1 for-writing record=10
285. Where we have to place the SQC in the program
write 1 from '1234567890' if the SQC represents the Procedure Section?
Output: 1234567890 At the bottom of the program.
286. Where we have to place the SQC in the program
open 'C:\temp\Ouput.txt' as 1 for-writing record=10
if the SQC represents the Heading Section?
write 1 from '1234567890':5
Output: 12345 287. Where we have to place the SQC in the program
if the SQC represents the Footing Section?
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10
write 1 from '12345'
288. What is the procedure needs to be called to get
Output: 12345 the OperatorID and Process Instance?
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10:vary Get-Prcs_run_Cntl.
write 1 from '12345' 289. What are the commonly used SQCs?

Output: 12345 SETENV ASKEFFDT


STDAPI EOJ
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10:fixed
write 1 from '12345' DATETIME SETUP01
CURDTTIM SETUP02
Output: 12345
DATEMATH SETUP31
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10:vary
TIMEMATH SETUP32
write 1 from '12345':10
PRCSAPI RDBMS
Output: 12345_____
PRCSDEF READXLAT
open 'C:\cnu\Ouput.txt' as 1 for-writing record=10:fixed RESET SQLERR
write 1 from '12345':10
NUMBER STDHDG01
Output: 12345_____ TRANCTRL
277. XL Formatting Commands. 1. SETENV.SQC: Useful to Setup the environment like
BEGIN-PROGRAM
Printer indicator, Page size indicator, Country indicator,
LET $NAME1 = 'SRINIVAS,S'
Language indicator. It should be placed at the top of the
LET $NAME2 = '000123'
program.
LET $NAME1 = '"'||$NAME1||'"'
LET $NAME2 = '="'||$NAME2||'"' 2. STDAPI.SQC:
 It includes two procedures. to update the Process Scheduler request records.
 STDAPI-INIT: Which Defines Process  Get-Run-Control-Parms(): it gets the
Scheduler Variables and get the Run Control values. #prcs_process_instance, $prcs_oprid, $prcs_run_cntl_id
 STDAPI-TERM: It updates the Process  Get_Process_Language (): Sets the
Scheduler Variables(Success or Failure). $prcs_language_cd value from the process scheduler run
control table.
3. DATETIME.SQC Includes set of procedures useful to
 Update-Prcs-Run-Status (): updates the
format Dates and Time.
process run status.
 Init-Datetime: Which must be called before  Update-Process-Status (): updates the
the other procedures timings.
 Format-DateTime ($in, :$out, $date, $time,
8. PRCSDEF.SQC Defines and initializes the process
$native)
scheduler variables.
 Diff-Date ($indate1, $indate2, :#dY,
:#dM, :#dD): This procedure will calculate the difference 9. RESET.SQC:
between two dates, returning the result in three different
units.  Useful to reset the printer and to indicate the
end of a report.
 Get-DateComponents ($indate, :#outyr,
:#outmo, :#outday) 10. NUMBER.SQC:
 Convert-To-MM (:$mm)
 Useful to format numeric numbers.
 Convert-To-MMM (:$mm)
 Init-Number() must be called before the other
4. CURDTTIM.SQC procedures.
 Format-Number (#in, :$out, $mask)
 Retrieves the Current System Date and Time.
 Format-Amt (#in, :$out, $mask, $curin, :
 Get-Current-DateTime() is the procedure to $curout)
retrieve the date and time related variables like
&SysDateTime, $SysDateTime, $AsOfToday, $AsOfNow,  Format_Currency_Amt (#in_amt, $currency,
$ReportDate, $ReportTimea, $CurrentCentury. $in_Effdt, $in_mask, :$out_amt, $MsgType)

5. DATEMATH.SQC: Includes set of date arithmetic 11. ASKEFFDT.SQC:


procedures related to Date.  It will ask the user for an Effective Date.
 Convert-To-DTU-Date ($date_in, :$dtu_date)  Two Procedures are there in ASKEFFDT.SQC
 dtu-parse-date ($dtu_date, :#dtu_yr,  Ask-Eff-Date (): Loops until user enters a
:#dtu_mo, :#dtu_da) valid Effective Date.
 dtu-add-days ($dtu_date, #dtu_days, :  Get-Date(): Prompts the user for an
$dtu_date_out) Effective Date. If no value is provided, the current date is
 dtu-subtract-days ($dtu_date, #dtu_days, : used ($AsOfToday from Get-Current-DateTime). If the
$dtu_date_out) user gives a value, then it validates.
 dtu-add-weeks ($dtu_date, #dtu_weeks, : 12. EOJ.SQC: (Updates process scheduler status)
$dtu_date_out)
 Performs end of job processing if the program
 dtu-add-months ($dtu_date, #dtu_months, :
ran to success.
$dtu_date_out)
 It calls the Update-Prcs-Run-Status and then
 dtu-add-years ($dtu_date, #dtu_years, :
Commit-Transaction.
$dtu_date_out)
 dtu-month-begin ($dtu_date, : 13. SETUP01.SQC: To setup portrait orientation report.
$dtu_date_out)
14. SETUP02.SQC: To setup landscape orientation report.
 dtu-month-end ($dtu_date, :$dtu_date_out)
 dtu-diff-days ($dtu_date1, $dtu_date2, 15. SETUP31.SQC: Useful to initialize commands for
#dtu_days) portrait orientation.
 dtu-diff-months ($dtu_date1, $dtu_date2, 16. SETUP32.SQC: Useful to initialize commands for
#dtu_months) landscape orientation.
 dtu-diff-years ($dtu_date1, $dtu_date2,
17. RDBMS.SQC: Gives the currently working database
:#dtu_years)
system.
 dtu-dayofweek# ($dtu_date,
:#dtu_dayofweek) 18. READXLAT.SQC: Read-Translate-Table () is the main
 dtu-dayofweek$ ($dtu_date, : procedure to get the long and short names for a given
$dtu_dayofweek) field/value from the XLATTABLE.

6. TIMEMATH.SQC: Includes set of date arithmetic 19. SQLERR.SQC: For SQR Error handling purpose.
procedures related to Time. #sql-status and $sql-error will be populated.

 Parse_Duration($in_duration, 20. STDHDG01.SQC:


:#out_hours, :#out_minutes, :#out_seconds)  Prints the standard heading for printed
 Add_Time_Duration ($in_time, reports.
$in_duration, :$out_time, :#carry_days)  It will not contain begin-heading or end-
 Subtract_Time_Duration ($in_time, heading statements, however, It prints PeopleSoft
$in_duration, :$out_time, #borrow_days) (centred), then the report ID (left side), report title
 Subtract_Time_Time ($in_time1, $in_time2, : (centred), and page number (right side) on the next line,
$out_duration) and the report date and time on the following two lines
 Add_Duration_Duration ($in_duration1, (right side).
$in_duration2, :$out_duration) 21. TRANCTRL.SQC: Performs Commit and Rollback.
 Subtract_Duration_Duration ($in_duration1, Available procedure: Begin-Transaction (), Commit-
$in_duration2, :$out_duration) Transaction (), Rollback-Transaction ()
7. PRCSAPI.SQC: (Update Process API) 290. What is the difference between SQR and SQT?
 Useful to get the run control parameters and SQT SQR
.SQR files will be complied running SQR program directory.
and executed when there is  Example if we enter –FSRI. Then it creates the
.SQT files are pre-complied
no –RS Command line output file with the name “SRI” in the same directory
files.
argument passed in where the source program is there.
SQRW.exe.
 If we enter –FC:\TEMP\. Then it creates the output
.SQT files will be created
file with the same program in the temp directory.
Using -RS command line Not required
argument with SQRW.exe.  If we enter –FC:\TEMP\SRI. Then it creates the
.SQT files will be executed output file with the name “SRI” in the temp directory.
with -RT Command line Not required 8. -I:
argument with SQRW.exe.  We can specify the File Path, so that SQR search for
.SQT files will be executed the files included in the program with #Include Command.
.SQR files will be executed
with SQRWT.exe  Ex: #Include ‘Setenv.sqc’ is the statement included
with SQRW.exe executable
executable file. No need to in SQR. And Command Line Argument –I C:\PT8.45\sqr is
file.
pass –RT. specified while running the SQR. So SQR will search for
.SQT files can’t be converted setenv.sqc in C:\PT8.45\sqr directory.
SQR files can be converted
back (De-Compile) to
to SQT by using –RS.  If no file path is mentioned then SQR will search in
original SQR file.
the same SQR directory.
291. What is the difference between SQR and SQC?  We can also give more than one directory but must
SQR SQC be separated by commas (,) or semicolons (;).
SQR is nothing but an Actual SQCs are like Functions in 9. –KEEP: It creates the .SPF file output in addition to
Source Program. Program. the .LIS files. But the .SPF files not be invoked automatically
Can be run as a standalone We can’t. Should be included to the user.
program. in any of the SQR. 10. –NOLIS: It prevents the creation of .LIS file and it
Use Call System Command Include the SQC name in the simply creates the .SPF file.
to call SQR from another SQR then call the 11. -O[file]:
SQR. procedures of SQC.
 By Default log file name is SQR.LOG.
Program Section is not
Program Section is required.  If we enter –O then it creates the log file with same
required.
name of the program in the same directory.
 If we enter –Osri then it creates the log file with
name “SRI” in the same directory.
12. –P: Suppresses printer control characters from column
Command-Line Flags 1.
13. -PRINTER:xx: It overrides the printer type for all the
292. How to Pass Command Line Flag while running report.
thru Process Scheduler?
EH - Enhanced HTML
Override Options tab, Parameter List, Append.
EP - Enhanced HTML
293. How to pass negative numbers as command line
HP - HP LaserJet
parameters?
HT – HTML
Use double – sign.
LP - Line Printer
EX: if you wanted to pass -123 as command line
PD – PDF
argument then pass --123.
PS – PostScript
294. What are the Command Line Arguments available
with SQR? WP – Windows
1. –A: 14. –RS: It creates compiled version of SQR that is .SQT
file. The default name of the runtime file is the name of
 It works with only .LIS files. It doesn’t work with
the program with the extension .SQT.
.SPF files.
15. –RT: It executes the pre-compiled .SQT files. It skips
 Useful to append the output to already existing
the syntax and error checking and starts the processing.
output file.
16. -SORTnn: Specifies the size of the sort buffer in
 Generally we use –A when we want to run a single
characters.
program more than once but want only single output file.
17. -Tnn: We can test our reports for NN pages. If we
2. -Bnn:
enter –T10 it displays only 10 pages of output. It saves
 It retrieves specified no of rows of data from the the time during testing.
database to buffer.
18. –XB: Suppresses the SQR banner and the "SQR... End
 By default it retrieves 10 rows when we specify –B. of Run" message.
 We can override the default value by specifying 19. –XMB: Disables error display box and error file will be
number. Ex: –B100. Will fetch 100 rows from database created in the mentioned path with –E.
into buffer at a time. –XMB –EC:\ABC this combination will disables error
3. -C: It displays the CANCEL Dialog box while running display box and error file will be created in C directory
the program, So we can cancel the program execution when with ABC.err
required. 20. –ZIV: It invokes the SQR portable file. It implicitly
4. –CB: It forces the communication box to be used. invokes the -KEEP command line flag, so that we can get
5. –DEBUG[xxx]: the .LIS file also.
6. -E[File Path and File Name]: 21. –ZMF: Specifies the full path and name of the SQR
 It creates an error file with same name of the error message file, sqrerr.dat.
program with .ERR as the extension.
 If no errors occur, no error file will be created.
 We can also override the error file name. Example if
we enter the command line flag as –Ec:\SRI. Then the
HTML Procedures
error file will be created in C Drive with the name SRI.err.  By using the SQR programs we can
7. -F[file | directory]: generate the reports in an HTML compatible format.
 Overrides the default output file directory and file  These reports can publish only on
name. the internet or an intranet. We can place the hypertext links
 Default output directory of a program is currently in reports which are used to jump to another report or any
another website. Before inserting we can check
 –PRINTER: HT or –PRINTER: EH SQR Whether the given value is number or not.
command line flags are useful to create HTML Output which Whether the date is valid or not.
automatically converts the program output into the HTML SSN is valid or not.
format and will take care of positioning, HTML tags, font
and letter size mapping and so on. Any special characters are there or not.
 Graphical Features - Font selection, 309. What is the basic Difference between Function
Bar codes, Lines and boxes, Charts, and graphs can’t be and Procedure?
converted to HTML. A FUNCTION is always returns a value using the return
 Graphical Features - Images, Font statement.
sizing, Font style, and Centring can be converted to HTML. A PROCEDURE may return one or more values through
 #include html.inc is the mandatory parameters or may not return at all.
file. And html_on is the mandatory procedure which needs 310. How to call External Functions from SQR?
to be included at the top of the program. Call System.
295. Commonly used commands with HTML? 311. About Call System Function?
 Calls the other language commands.
 2 options are available WAIT and NOWAIT
 Default is NOWAIT.
SQR Errors  WAIT: SQR will suspend until the CALL SYSTEM
has finished processing.
296. Invalid Object name <Wrong Object Name>  NOWAIT: Calls the CALL SYSTEM commands and
When the table name is incorrect. SQR will continue with the processing.
297. Can’t find required numeric parameter 312. Sample Program which runs external Functions?
When there is no parameter mentioned after Begin- Below SQR copies TEST.TXT file from C Drive to D Drive.
Heading or Begin-Footing. BEGIN-PROGRAM
LET $CMD = 'C:\WINDOWS\SYSTEM32\CMD.EXE /C COPY C:\TEST.TXT D:\'
298. Command Not allowed in this Section: SHOW
CALL SYSTEM USING $CMD #STATUS
When there is a Show statement in Setup Section. SHOW #STATUS
299. Command Not allowed in this Section: PRINT END-PROGRAM
When there is a PRINT statement in Setup Section. 313. How to get the run control values thru SQR?
300. Did not find end of paragraph: begin-select Using $PRCS_OPRID and $PRCS_RUN_CNTL_ID variables.
When there is no End-Select These variables are available in Get-Run-Control-Prams()
301. Assume there is a statement in the SQR. Procedure which is available in PRCSAPI.SQC.
Let &Name = ‘Srinivas’ 314. About GOTO Statement?
Print &Nam (1,1)
Then what would happen?
SQR will not print the name and it will not give any error.
302. Program line too long; maximum is 511. Sample Code
SQR will throw this error when there is a code of more
than 511 columns in a single line. 315. Code to print Exclamatory (!)?
Using two Exclamatory marks.
Using CHR(33).

General – SQR Using Encode <33>


BEGIN-PROGRAM
SHOW '!!'
303. How will you perform ERROR Handling in SQR?
LET $EXCLAMATION1 = CHR(33)
Thru ON-ERROR = STOP/WARN/SKIP (Compile Time) SHOW $EXCLAMATION1
Thru ON-ERROR = PROCEDURE NAME (Run Time) ENCODE <33> INTO $EXCLAMATION2
Thru $SQL-Error, #SQL-Status Variables. SHOW $EXCLAMATION2
BEGIN-PROCEDURE SQL-ERROR-HANDLING END-PROGRAM
#DEBUGP SHOW 'STARTING PROCEDURE' 316. Code to Print ‘SRINIVAS’
SHOW $ERROR_MESG BEGIN-PROGRAM
SHOW 'SQL STATUS = ' $SQL-STATUS SHOW '''SRINIVAS'''
SHOW 'SQL ERROR = ' $SQL-ERROR LET $NAME = 'SRINIVAS'
#DEBUGP SHOW 'FINISHING PROCEDURE' LET $NAME = '''' || $NAME || ''''
END-PROCEDURE SQL-ERROR-HANDLING SHOW $NAME
304. How will you perform Exceptional Handling in END-PROGRAM
SQR? 317. How to Print Graphic Box?
How to Print Graphic Horizontal Line?
305. If already existing SQR taking much time to How to Print Graphic Vertical Line?
execute, what exactly you would do to optimize as a How to Increase font Size while printing Graphics?
developer? How to Print Bar Codes
Ask DBA to run statistics for the tables which are being Using Graphic Command.
referred by the SQR and check the indexes.
BEGIN-PROGRAM
306. When you are converting data from legacy to
GRAPHIC (1,1,19) BOX 4 20
PeopleSoft, due to large number of data, if SQR fails,
GRAPHIC () FONT 23 28.5
how can you handle?
PRINT 'SRINIVAS' (3,1)
Ask DBA to increase the table space.
GRAPHIC (7,1,19) BOX 3 0 4
307. Can we have multiple database connections in PRINT-BAR-CODE (8,1)
SQR? TYPE=8
Yes, we have to create the DB Link and mention the HEIGHT=0.2
<Table Name> @ <Database Name> TEXT='SRINIVAS'
308. How can you validate the data in SQR? GRAPHIC () FONT 4 8.5
We can validate the data thru various ways. One scenario GRAPHIC (1,30,11) HORZ-LINE 8
like we are reading data from file and inserting into table.
PRINT 'HORIZONTAL LINE' (1,30) SET-COLOR PRINT-TEXT-BACKGROUND = (0,0,0)
PRINT 'BLACK ' (1,1)
GRAPHIC (1,30,13) VERT-LINE 8
SET-COLOR PRINT-TEXT-BACKGROUND = (255,255,255)
!Code to print text vertically PRINT 'WHITE ' (,+1)
LET $STRING = 'VERTICAL LINE' SET-COLOR PRINT-TEXT-BACKGROUND = (128,128,128)
LET #LENGTH = LENGTH($STRING) PRINT 'GRAY ' (,+1)
LET #LINE_NUM = 2 SET-COLOR PRINT-TEXT-BACKGROUND = (192,192,192)
LET #I = 1 PRINT 'SILVER ' (,+1)
WHILE #I <= #LENGTH + 1 SET-COLOR PRINT-TEXT-BACKGROUND = (255,0,0)
LET $SUBSTR = SUBSTR($STRING, #I, 1) PRINT 'RED ' (2,1)
PRINT $SUBSTR (#LINE_NUM, 29) SET-COLOR PRINT-TEXT-BACKGROUND = (0,255,0)
LET #I = #I + 1 PRINT 'GREEN ' (,+1)
LET #LINE_NUM = #LINE_NUM + 1 SET-COLOR PRINT-TEXT-BACKGROUND = (0,0,255)
END-WHILE PRINT 'BLUE ' (,+1)
END-PROGRAM SET-COLOR PRINT-TEXT-BACKGROUND = (255,255,0)
Output Would be: PRINT 'YELLOW ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (128,0,128)
PRINT 'PURPLE ' (3,1)
SET-COLOR PRINT-TEXT-BACKGROUND = (128,128,0)
PRINT 'OLIVE ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (0,0,128)
PRINT 'NAVY ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (0,255,255)
PRINT 'AQUA ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (0,128,0)
PRINT 'LIME ' (4,1)
SET-COLOR PRINT-TEXT-BACKGROUND = (128,0,0)
PRINT 'MAROON ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (0,128,128)
PRINT 'TEAL ' (,+1)
SET-COLOR PRINT-TEXT-BACKGROUND = (255,0,255)
PRINT 'FUCHSIA' (,+1)
END-PROGRAM

318. Code to print text vertically? Output Would be:


BEGIN-PROGRAM
LET $NAME = 'SRINIVAS'
LET #LEN = LENGTH($NAME)
PRINT $NAME (1,1) WRAP 1 #LEN
END-PROGRAM
319. How to print text in different colour?
BEGIN-PROGRAM 321. How to Create Hyperlinks?
SET-COLOR PRINT-TEXT-FOREGROUND = (0,0,0)
PRINT 'BLACK ' (1,1) BOLD
SET-COLOR PRINT-TEXT-FOREGROUND = (255,255,255) 322. Query to get preferred name?
PRINT 'WHITE ' (,+1) BOLD BEGIN-PROCEDURE GET-PREFERRED-NAME
SET-COLOR PRINT-TEXT-FOREGROUND = (128,128,128) #DEBUGP SHOW 'ENTERING PROCEDURE ---> GET-PREFERRED-NAME'
PRINT 'GRAY ' (,+1) BOLD BEGIN-SELECT
SET-COLOR PRINT-TEXT-FOREGROUND = (192,192,192) NAMES.LAST_NAME
PRINT 'SILVER ' (,+1) BOLD NAMES.FIRST_NAME
SET-COLOR PRINT-TEXT-FOREGROUND = (255,0,0) NAMES.MIDDLE_NAME
PRINT 'RED ' (,+1) BOLD NAMES.NAME_PREFIX
SET-COLOR PRINT-TEXT-FOREGROUND = (0,255,0) NAMES.NAME_SUFFIX
PRINT 'GREEN ' (,+1) BOLD FROM PS_NAMES NAMES
SET-COLOR PRINT-TEXT-FOREGROUND = (0,0,255) WHERE NAMES.EMPLID = 'AAAA'
PRINT 'BLUE ' (,+1) BOLD AND NAMES.NAME_TYPE = 'PRF'
SET-COLOR PRINT-TEXT-FOREGROUND = (255,255,0) AND NAMES.EFFDT = (SELECT MAX (EFFDT) FROM PS_NAMES
PRINT 'YELLOW ' (,+1) BOLD WHERE EMPLID = NAMES.EMPLID
SET-COLOR PRINT-TEXT-FOREGROUND = (128,0,128) AND NAME_TYPE = NAMES.NAME_TYPE
PRINT 'PURPLE ' (2,1) BOLD AND EFFDT <= CURRENT DATE)
SET-COLOR PRINT-TEXT-FOREGROUND = (128,128,0) END-SELECT
PRINT 'OLIVE ' (,+1) BOLD
SET-COLOR PRINT-TEXT-FOREGROUND = (0,0,128) #DEBUGP SHOW 'FINISHING PROCEDURE ---> GET-PREFERRED-NAME'
PRINT 'NAVY ' (,+1) BOLD END-PROCEDURE GET-PREFERRED-NAME
SET-COLOR PRINT-TEXT-FOREGROUND = (0,255,255) 323. Query to get the Termination date?
PRINT 'AQUA ' (,+1) BOLD BEGIN-PROCEDURE GET-TERMINATION-DATE
SET-COLOR PRINT-TEXT-FOREGROUND = (0,128,0) #DEBUGP SHOW ' ENTERING PROCEDURE --> GET-TERMINATION-DATE '
PRINT 'LIME ' (,+1) BOLD MOVE {BLANK} TO $TERMINATION_DATE
SET-COLOR PRINT-TEXT-FOREGROUND = (128,0,0)
BEGIN-SELECT
PRINT 'MAROON ' (,+1) BOLD
EMP.TERMINATION_DT
SET-COLOR PRINT-TEXT-FOREGROUND = (0,128,128)
MOVE &EMP.TERMINATION_DT TO $TERMINATION_DATE
PRINT 'TEAL ' (,+1) BOLD
FROM PS_EMPLOYMENT EMP
SET-COLOR PRINT-TEXT-FOREGROUND = (255,0,255)
WHERE EMP.EMPLID = 'AAA'
PRINT 'FUCHSIA' (,+1) BOLD
AND EMP.EMPL_RCD = 0
END-PROGRAM
END-SELECT
Output Would be: #DEBUGP SHOW ' FINISHING PROCEDURE --> GET-TERMINATION-DATE '
END-PROCEDURE GET-TERMINATION-DATE
324. Query to get the Parent Department.
SELECT PARENT_NODE_NAME
FROM PSTREENODE A
WHERE A.SETID = <SETID>
AND A.TREE_NAME = <TREE NAME>
320. Code to change the Background Colour? AND A.TREE_NODE = <DEPARTMENT NAME>
BEGIN-PROGRAM AND A.EFFDT = (SELECT MAX(B.EFFDT)
FROM PSTREENODE B  MV <FILE NAME> <DIRECTORY NAME>/ -MOVING A FILE/CHANING FILE
WHERE A.SETID = B.SETID LOCATION
AND A.TREE_NAME = B.TREE_NAME  LS -L | MORE ONE DIRECTION
AND A.TREE_NODE = B.TREE_NODE  LS -L | LESS BOTH THE DIRECTIONS - USE ARROW KEYS
AND B.EFFDT <= GETDATE())  LS -L | PAGE - ONE PAGE AT A TIME
 LS H* - DISPLYS ALL FILES STARTING WITH 'H'
325. Query to get all the Child DEPTIDs for a given
 LS -L ??? ALL THE FILES WHICH HAVE GOT 3 CHARECTERS
DEPTID
 LS -L *[1-4] -SPECIFIES A RANGE.
SELECT A.TREENODE
 MAN
FROM PSTREENODE A, PSTREENODE B
 WHATIS
WHERE A.TREE_NAME = <TREE_NAME>
 HELP
AND A.SETID = <SETID>
 CUT -C3 <FILE NAME>
AND A.EFFDT = <EFFDT>
 CUT -C1-3 <FILE NAME>
AND B.TREE_NAME = A.TREE_NAME
 CUT -D" " -F1 <FILE NAME>
AND B.SETID = A.SETID
 CUT -D" " -F2 <FILE NAME>
AND B.EFFDT = A.EFFDT
 CUT -D" " -F1,3 <FILE NAME>
AND B.TREENODE = <DEPTID>
 CAT <FILE NAME> | TR "[A-Z]" "[A-Z]"
AND A.TREE_NODE_NUM BETWEEN B.TREE_NODE_NUM AND
B.NODE_NUM_END  CAT <FILE NAME> | TR "[A,E,I,O,U]" "[1,2,3,4,5]"
 CAT <FILE NAME> | TR " " ","
326. Code to Find out Report Elapsed Time?
 CAT <FILE NAME> | TR " " "," > <FILE NAME>
BEGIN-PROGRAM
 WHO
DO GET-CURRENT-DATETIME
 WHO AM I
LET $BEGIN_TIME = 'PROGRAM BEGIN: '||$ASOFTODAY||' AT ' ||$ASOFNOW
 WHO | CUT -F1 -D" "
MOVE $ASOFNOW TO $BEGIN_PROG_TIME
 LS -L | TR -S " "
SHOW $BEGIN_TIME
 LS -L | TR -S " " | CUT -F9 -D" "
DO GET-CURRENT-DATETIME  LS -L | TR -S " " | CUT -F5,9 -D" "
LET $END_TIME = 'PROGRAM BEGIN: '||$ASOFTODAY||' AT ' ||$ASOFNOW  SORT <FILE NAME>
MOVE $ASOFNOW TO $END_PROG_TIME  SORT -R <FILE NAME>
SHOW $END_TIME  SORT -F <FILE NAME>

DO SUBTRACT_TIME_TIME ($END_PROG_TIME, $BEGIN_PROG_TIME,  SORT -N <FILE NAME>


$RUN_TIME)  HISTORY
SHOW 'PROGRAM ELAPSED TIME -->' $RUN_TIME  LS -L | TR " " ","
END-PROGRAM  LS -L | TR -S " " ","
327. Lock Table in exclusive Mode?  LS -L | TEE TR -S " " ","
 CAT <FILE NAME> | TEE <NEW TEXT> - ITS LIKE A | SYMBOL AND
DISPLAYS THE OUTPUT.
328. Code to Send Mail thru SQR?  FIND . -NAME "<FILE NAME> - CURRENT DIRECTORY
Using MAILX command.  FIND .. -NAME "<FILE NAME> -
 FIND ~ -NAME "<FILE NAME> -
Let $Shell = 'Mailx -r ' || $Mail_From ||' -s' || $Subject || '
 FIND /~ -NAME "<FILE NAME> - ROOT DIRECTORY
' || $Mail_To || ' < ' || $File
 FIND / -NAME "<NAME> 2>ERROR
Call System using $Shell #Unix_Status  FIND . -NAME "*[1-3]" - STARTS WITH ANY CHAR BUT ENDS WITH ANY 1 -
if #Unix_Status <> 0 3
 FIND . -NAME "*" -SIZE 1
show 'ERROR ON : ' $Shell
 CAL 8 2006
show 'UNIX STATUS : ' #Unix_Status  BANNER <NAME>
end-if  ECHO "HELLO"

329. Can we trim date variable?  PS - WILL GIVE THE LIST OF ALL BACK GROUND PROCESS RUNNING
 MESG
Yes, we can perform ltrim and rtrim on date variables.
 TALK
LET $DATE = LTRIM(RTRIM($CURRENT-DATE,' '),' ')
 WRITE
SHOW $DATE
 /*
330. How to Convert -Ve Number To +Ve Number?  VAR="HEWITT"
LET #X = -5  ECHO $VAR
SHOW #X  */
LET #X = #X - (2*#X)
334. Code find some text in a folder and create a file with
SHOW #X
search found values.
UPDATE PS_JOB SET COMPRATE = COMPRATE -(2*COMPRATE) WHERE
COMPRATE < 0  $ CD /EXPORT/HOME/A55849
 $ MKDIR DATA
331. Code to find out Week Number.
 $ CD /APPS/PSOFT/HRCURRENT/SQR
LET #WEEK =
 $ GREP -I "LOCATION"
CEIL((DATEDIFF(&CHECK_DT,STRTODATE(EDIT(&CHECK_DT,'YYYY') || '-01-
*.*>>/EXPORT/HOME/A55849/DATA/OUTPUT_GREP.TXT
01' ,'YYYY-MM-DD'),'DAY')/7))
 $ CD /EXPORT/HOME/A55849
332. Code to check whether the given value is Integer
 $ CD DATA
or not?
If (#Number - Floor(#Number) = 0)  $ LS -LRT
Display 'The Number Is An Integer'
Else
Display 'The Number Is Not An Integer'
End-If
333. Shall Script Commands?
 CD / - MOVE TO PRVIOUS PATH
 CD ~/<FOLDER NAME> -PARENT DIRECTORY THEN FOLDER
 LS -LR - REVERS ORDER
 LS -F - WILL PUT * IN FRONT OF EXECUTABLE FILE
 CAT > <FILE NAME>
 CNTL Z
 CP <SOURCE NAME> <DESTINATION NAME>
 CP <FILENAME PATH>/
 RM <FILE NAME>
 RM -I <FILE NAME>
 RM -R <DIRECTORY NAME>
 RM -IR <DIRECTORY NAME>
 MV <FILE NAME> <NEW FILE NAME> - RENAMING FILE NAME

Das könnte Ihnen auch gefallen