Structured Query Reporting
Structured Query Reporting
ADVANTAGES Used for Reporting. Used for background Sql processing Used to migrate/ move data from legacy system to PeopleSoft system. Used to perform file integration. Used where programming logic is more. This can be used as both GUI and CUI(character use interface)( GUI is supported only till 7.5 version, it is also called work bench).
DATA/BODY FOOTING
SQR page
a.
BEGIN-SETUP:
This is used to perform output page setup like page size, margins, font size etc. We can have only 1 setup section in SQR program The page setup done will be applied to all output pages.
Syntax: // THESE ARE SPACE SENSITIVE.THE CODE WILL BE TYPED IN NOTEPAD // THESE ARE SPACE OR WORDPAD AND SAVED AS .SQR BEGIN-SETUP OTHER COMMANDS END-SETUP
SENSITIVE.THE CODE WILL BE TYPED IN NOTEPAD OR WORDPAD AND SAVED AS .SQR
b. BEGIN-HEADING
This is not a mandatory section. This is used to design heading region of O/p page. We can have only one heading region. The heading design will be applied to all the O/P pages.
Syntax:
BEGIN-HEADING
c. BEGIN-FOOTING
This is not a mandatory section. This is used to design footing region. We can have only 1 footing section. The footing design will be applied to all the O/P pages.
Syntax:
BEGIN-FOOTING
d. BEGIN-PROGRAMM
This is a mandatory section in SQL program. This is used to design data region of O/p page. We can have only program section in SQR program The SQR program execution starts from program section.
Syntax:
e. BEGIN-PROCEDURE
This is not a mandatory section. This is used to design data or body region on O/p page. We can have any number of procedures Every procedure has unique procedure name. Procedures are functions in SQR which can be re-used. We do not write actual coding in program section, instead we write it in procedure section & call them in program section.
Syntax:
2. PARAGRAPHS a. BEGIN-SELECT
This is used to retrieve data from database which is required to generate output. This is used to implement for looping in SQR programs.
Syntax BEGIN-SELECT Field1 . From<table-list> [where<condition>] [group by[<having>]] [order by] END-SELECT B. BEGIN-SQL This is used to execute all SQL statements like DML,DDL,DCL statements except select. Syntax BEGIN-SQL SQL-STATEMENT END-SQL
IF THERE MULTIPLE SQLSTATEMENTS, USING ; AT END OF EVERY STATEMENT.
c. BEGIN-DOCUMENT
This is used to combine static text with data from database.(EG:- while giving offer letter or any greetings, the text is same , only the name changes.) Syntax BEGIN-DOCUMENT (1,1) OTHER COMMANDS END-COMMANDS
OTHER COMMANDS.
i) PRINT-COMMAND
This is mandatory for any SQR report. They are of two types Implicit: no commands required, used for printing static text. Bold - Center - Underline Explicit: print command is required. - Wrap
ON-BREAK Used for redundancy of printing Group headings Group footings Options: change,top-page,never,always,before,after,save ON-BREAK = NEVER ( NEVER CHANGE THE VALUE) = ALWAYS(PRINT VALUE ALWAYS) = AFTER (USED FOR GROUP FOOTING)
EXPLICIT PRINT PRINT <STATIC TEXT> (<ROWNO><COL NO>[<LEN>]) (<OPTIONS>) EG: PRINT DETAIL (1,20)
ON-BREAK: REDUNDANCY OF PRINITNG & COUNTRY(1,1) ON-BREAK &CITY (1,5) ON-BREAK & EMPID(1,7)
DIFFERENT FILE TYPES .SQR -> SOURCE CODE FILE (EXECUTABLE FILE) .SQT-> INTERMEDIATE FILE .LIS-> LIST FILE o/p FILE .SQC-> FUNCTION LIBRARY FILE .SPF-> PORTABLE FILE FORMAT .INI-> INITIALIZATION/CONFIGURATION .MAX-> MAXIMAZATION FILE( INCREASE BUFFER FILE) .HTML .PDF .CSV .ERR -> ERROR FILE .LOG-> LOG FILE O/P FILE FORMATS
DATA TYPES
-
VARIABLES COLUMN VARIABLES : These are columns in database ie, fields from database tables. These variable names will be staring with & SQR VARIABLES :
Variable name consists of hyphen - Developer cannot use these names for user defined variables.
Document markers o
o
These are used only in BEGIN-DOCUMENT paragraph. These variable names start with @.
Substitution variables oIn these variables, values are stored at start of program and remain till end of program.
o The variables are enclosed in { }
Scope of variable
Local
TYPES OF RECORDS
TABULAR REPORTS: This is used to generate report from a single table. MASTER DETAIL REPORT: This is to generate reports from more than one table. FORM REPORTS: In this report, for each and every row we will have a separate output page. EG: PAY SLIPS MAILING LABELS: In this we partition the output page vertically and generate an output . EG: ADRESS PRINITNG LETTERS AND DOCUMENTS: In this report we combine static text. With the column variables. EG: OFFER LETTERS AND RELIEVING LETTERS CROSS TABULAR REPORTS: In this report we perform both row wise as well as column wise calculations. EG: FINDING ALL THE TOTALS IN BELOW TABLE TOTAL TA TOTAL DA TOTAL SALARY TOTAL TOTAL
THE EXECUTABLE FILE TO RUN AN sqr PROGRAM IS sqrw.EXE. THIS IS LOCATED AT <DRIVE>:\ PEOPLETOOLS 8.X\bin\sqr\<DATABASE>\BINW\sqrw.exe
! Tabular report
! This report gets the data from employee table and generates output for all employees. BEGIN - HEADING 2 PRINT Employee detail report (1, 20) BOLD BOX PRINT Employee id (2, 1) BOLD UNDERLINE PRINT EmpName (2, 15) BOLD UNDERLINE PRINT Country (2, 60) BOLD UNDERLINE PRINT Salary (2, 70) BOLD UNDERLINE
END-HEADING BEGIN - FOOTING 2 PRINT ** Confidential information** (2, 10) BOLD END - FOOTING ! This is main section which calls tabular procedures. BEGIN - PROGRAM DO TABULAR END - PROGRAM
! This is a procedure to get the data and print BEGIN - PROCEDURE BEGIN -SELECT EMPLID (+1,1) ! +1: AUTO INCREMENTS ROWS NAME ( ,15) COUNTRY ( ,60) COMPRATE ( ,70) FROM PS_EMPLOYEES END - SELECT END PROCEDURE
MASTER DETAILS REPORT 1. USING JOINS 2. USING PROCEDURES 3. USING LOAD LOOKUP USED TO GENERATE REPORTS FROM MULTIPLE TABLES.
!** master detail report using joins BEGIN-PROGRAM DO MAIN ! CALLING PROCEDURE END-PROGRAM BEGIN - PROCEDURE MAIN BEGIN - SELECT A. EMPLID (+1, 1) A. BIRTHDATE ( ,10) B. EMPLID ! IT WILL BE STORED IN BUFFER BUT WILL NOT BE PRINTED B. COUNTRY ( ,55) FROM PS_PERSON A, PS_ADDRESS B WHERE A.EMPLID= B.EMPLID AND B.ADDRESS-TYPE=HOME END - SELECT END - PROCEDURE MAIN NEW Commands used in the above two programs: ! MAIN IS PROCEDURES NAME
DO COMMAND- This is used to call a program. Syntax: DO <procedure name> COMMENTING: using ! we can write single line comments. Syntax:! <comment> MOVE- This is used to move the data from one variable to the other. This is also used for typecasting # DEFINE- used to define the substitute variables. Syntax: # DEFINE <sub var name> <value> LET- this is used to assign values to variables. This is used to perform arithmetic or string operations.
!** Master detail report using global variables BEGIN - PROGRAM DO GBL_VAR END - PROGRAM BEGIN - PROCEDURE GBL_VAR BEGIN - SELECT A. EMPLID(+1,1) B. BIRTHDATE ( ,10) MOVE &A.EMPLID TO $EMPLID VARIABLE NAME DO ADDR_DET FROM PS_PERSON A END - SELECT END - PROCEDURE BEGIN - PROCEDURE ADDR_DET BEGIN - SELECT B.EMPLID B.CITY (+1, 25) B.COUNTRY ( , 60) FROM PS-ADDRESS B WHERE B.EMPLID=$EMPLID AND B.ADDRESS-TYPE=HOME !$EMPLID IS USER DEFINED
BEGIN-PROGRAM DO MAIN END-PROGRAM BEGIN - PROCEDURE MAIN BEGIN - SELECT A. EMPLID (+1,1) A. BIRTHDATE ( ,15) DO EMPL_DET (&A. EMPLID) EMP_DET PROCEDURE FROM PS_PERSON A END - SELECT END - PROCEDURE BEGIN - PROCEDURE EMPL_DET ($ EID) BEGIN - SELECT B.EMPLID B.CITY (+1, 40) ! PASSING ARGUMENT TO $ EID IN
B.COUNTRY ( , 60) FROM PS_ADDRESS B WHERE B.EMPLID=$EID AND B.ADDRESS-TYPE=HOME END - SELECT END PROCEDURE
FORM REPORTS
! ** This is a form report** BEGIN - HEADING 1 PRINT FORM REPORT (1, 20) BOLD BOX END- HEADING BEGIN-PROGRAM DO FORM_REPORT END-PROGRAM BEGIN - PROCEDURE FORM_REPORT BEGIN - SELECT EMPLID NAME MONTHLY_RT MOVE &EMPLID T0 $SETID MOVE &NAME TO $ENAME MOVE &MONTHLY_RT TO $ SALARY DO PRINTING FROM PS_EMPLOYEES END - SELECT END - PROCEDURE BEGIN - PROCEDURE PRINTING PRINT EMPLID : (1 ,1)
: (3, 1) : (5, 1)
MAILING LABELS
#DEFINE MAX_LABEL_LINES 10 #DEFINE LINES_BETWEEN_LABELS 3 BEGIN-PROGRAM DO LABELS END-PROGRAM BEGIN - PROCEDURE LABELS
LET #LABEL-COUNT=0 LET #LABEL-LINES=0 COLUMNS 1 30 60 BEGIN - SELECT EMPLID (1, 1, 29) ADDRESS1 (2, 1, 29) ADDRESS2 (3, 1, 29) ADDRESS3 ADDRESS4 CITY STATE COUNTRY LET $ADDR-LINE=&ADDRESS3 ll , ll &ADDRESS4 LET $LASTLINE= &CITY ll , ll&STATE ll , ll &COUNTRY
PRINT $ADDR-LINE (4, 1, 29) PRINT $LASTLINE (5, 1, 29) NEXT-COLUMN AT-END=NEWLINE ADD 1 TO #LABEL-COUNT IF #CURRENT-COLUMN=1 ADD 1 TO LABEL-LINES IF #LABEL-LINES ={MAX-LABEL-LINES} NEW-PAGE LET #LABEL-LINES=0 ELSE NEXT-LISTING NO-ADVANCE SKIPLINES={LINES-BETWEEN-LABELS} END-IF FROM PS-ADDRESSES WHERE ADDRESS-TYPE= HOME END - SELECT
USE COLUMN=0 NEW-PAGE PRINT TOTAL LABELS PRINTED : (+1, 1) PRINT #LABEL-COUNT ( ,30)
END - PROCEDURE