Sunteți pe pagina 1din 28

SQR.

Conceptos
Herramienta de reportes y procesos
Se programa en archivos de texto con nombre de 8 caracteres mximo y
extensin SQR
Mdulos a incluir con extensin SQC

Los programas son procesados por un interprete escrito en C++


Ejemplo: sqrw.exe
El intrprete depende de la plataforma
El intrprete realiza 2 pasadas

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Estructura del programa

Heading

Body

Footing

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Primera pasada
Se procesan los #INCLUDE SQCs y se insertan en el cdigo principal
Se evalan todos los dems comandos #. En particular se sustituyen los
#DEFINE por su valor
Se procesa la seccin SETUP y se reserva memoria para arrays
Se verifica la sintxis

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Segunda pasada
La ejecucin comienza desde el Begin-Report y termina en End-Report
El cuerpo del reporte es calculado restando el Page-Size definido en la seccin
Setup menos el Cabezal y el Pie de pgina.
1. Processes data for the Body section
If page overflow occurs or a NEW-PAGE command is encountered in the code:
a. Processes HEADING section
b. Processes FOOTING section
c. Writes page buffer to the output buffer
d. Returns back to 1., above
2. Processes HEADING section
3. Processes FOOTING section
4. Writes entire page buffer to file

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Secciones
Report or Program (principal)
nica seccin obligatoria
Generalmente se compone de comandos do
begin-program
do MyProcedure
end-program

Setup (Declaraciones)
begin-setup
! Declare the default layout for this report
declare-layout default
paper-size=(8.5,11)
left-margin=1 right-margin=1
top-margin=1 bottom-margin=1
end-declare
end-setup

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Secciones (2)
Heading/Footing
begin-heading 1
print 'Tutorial Report' (1) center
end-heading
begin-footing 1
! print "Page n of m" in the footing
page-number (1,1) 'Page '
last-page () ' of '
end-footing

Procedures
begin-procedure myprocedure
[paragraphs and commands]
end-procedure
Se llaman con el comando do

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Paragraphs
Select
Sentencia SELECT al estilo SQR!!
SQL
Permite ejecutar sentencias SQL Update,Delete,etc.

Document
Permite mezclar texto y datos recuperados de la DB

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Paragraph select

begin-SELECT [DISTINCT][Loops=#][ON-ERROR=procedure]
COLUMN_NAME
! normally 1 per line
[SQR commands]
! must be indented
FROM TABLE/VIEW
[WHERE]
[Order by ]
end-SELECT
begin-select
name (,1)
city (,32)
state (,49)
phone (,55)
position (+1) ! Advance to the next line
from customers
end-select
9

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Paragraph SQL

begin-SQL ON-ERROR= {procedure_name or STOP|WARN|SKIP}


{SQL statements}
end-SQL
ON-ERROR =STOP - Halts SQR if error occurs, remainder is scanned but
not processed.
WARN - Causes warning message, but continues processing
normally.
SKIP - Ignores all errors and report continues with no message.

El commit se hace al final del programa por default.


begin-sql on-error skip
delete from PS_MyTable
End-sql

10

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Command Print Explcito


PRINT {literal, SQR variable} (fila, col, largo) [format]
La fila/col puede ser absoluta o relativa (+/-)
begin-procedure explicit-print
begin-SELECT
NAME &student_name
print &student_name
PHONE &student_phone
print &student_phone
FROM PS_STUDENT_DATA
end-SELECT
end-procedure explicit-print

11

SQR

(+1,1,30)
(,+5,15)

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Print Implcito/Sustitucin {}

begin-procedure implicit-print
begin-SELECT
NAME
(+1,1,30)
PHONE
(,+5,15)
FROM PS_STUDENT_DATA
end-SELECT
end-procedure implicit-print
#define c1 1
#define c2 35
begin-procedure implicit-print
begin-SELECT
NAME
(+1,{c1})
PHONE
(,{c2})
FROM PS_STUDENT_DATA
end-SELECT
end-procedure implicit-print
12

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Print Formatos

Center
Edit
Fill
Wrap
On-Break
PRINT '=+= (+1,5,9) FILL

!Results: =+==+==+=

PRINT &descrlong (+1,25) WRAP 30 8


PRINT &units (0,10) edit b999

13

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Print Cortes de Control


PRINT {field} (a,b,c) ON-BREAK PRINT=change
change/top-page
always
never
PROCEDURE=procedure_name
AFTER=procedure_name
SAVE=$text_var
BEFORE=procedure_name
SKIPLINES=nn
LEVEL=nn
CHANGE: Prints only when a change occurs and is the default.
CHANGE/TOP-PAGE: Prints when change occurs and at top of page.
ALWAYS: Duplicates the break field for every detail group.
NEVER: Suppresses printing.
PROCEDURE= To be invoked when the value changes.
BEFORE= Procedure to invoke before the value changes.
AFTER= Procedure to invoke after the value changes.
SAVE= A string variable where the previous value of a break field will be stored.
SKIPLINES= Specifies how many lines to skip when the value changes.
LEVEL= Level of break for report with multiple ON-BREAK options.

14

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Variables/command Let
Pueden tener cualquier largo
No son case-sensitive
Son globales (salvo parmetros de procedures)
Data Type

Variable Name

Maximum Size

Initialized
to

Character, string,
text, date

$Text

RDBMS longvar

null

Numeric (float,
decimal, integer)

#Num

RDBMS double
floating point

LET $address3 = &city||', '||&state||' '||&zip


Begin-SELECT
CITY||', '||STATE||' '||ZIP &address3
FROM PS_STUDENT_DATA
End-SELECT
LET $phone = EDIT(&phone, '(xxx) xxx-xxxx')
15

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Variables reservadas
#CURRENT-LINE Current physical line on a page.
#CURRENT-COLUMN Current column on a page.
#PAGE-COUNT
Current page number (can be reset).
#END-FILE
Set to 1 if end of file occurs.
#RETURN-STATUS Value returned to operating system when SQR exits.
#SQL-COUNT
The # of rows affected by an SQL DML statement.
#SQL-STATUS
Status value from database after each query is compiled/executed.
$SQR-DATABASE The database type for which SQR was compiled.
$SQL-ERROR
Text message of error returned from DBS.
$SQR-LOCALE
The name of the current locale being used.
#SQR-PID
The process ID of the current SQR process.
$SQR-PLATFORM The hardware/operating system type for which SQR was compiled.
Valid values are: WINDOWS, VM, MVS, VMS, and UNIX.
$SQR-PROGRAM The name of the SQR program file.
$SQR-VER
The text string shown with -ID flag.

16

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Arrays
Array
CREATE-ARRAY
NAME= of array
SIZE= number of rows, starting at zero (0)
FIELD= fieldname : type : occurs
begin-procedure array_students
CREATE-ARRAY NAME=students SIZE=25
FIELD=
student_id:char
FIELD=
name:char
FIELD=
course:char:3
end-procedure array_students

Put
PUT '2001'
INTO students(0)
student_id

Get

'Larsen,Mark''1001' '1001' '1014'


name

course(0) course(1) course(2)

GET {any SQR variable} FROM array_name(row) field(occurs)

GET $name FROM students(0) name

17

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Sentencias de control
DO

Perform a procedure

BREAK

Causes an exit from within an Evaluate or a While

IF

Conditional execution

EVALUATE

18

SQR

Multi-way branching (case)

WHILE

Loop structure

GO TO

Jump to a label

STOP QUIET

Aborts SQR with Press Enter to Close

STOP

Aborts SQR with Program stopped at User Request

EXIT-SELECT

Exit query loop prematurely

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Sentencias de control (2)


IF

IF {field} = {value}
{execute SQR command(s)}
ELSE
{execute SQR command(s)}
END-IF
If &Course_Type = 'T'
and $Project_Role = 'DBA'
Do Process-DBA
Else
Do Process-Functional
End-if

EVALUATE
EVALUATE variable
WHEN = {value or variable}
{execute SQR command(s)}
BREAK
WHEN = {value or variable}
{execute SQR command(s)}
BREAK
WHEN-OTHER
{default SQR command(s)}
END-EVALUATE
19

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Sentencias de control (3)

WHILE
WHILE #num < {#num_var or literal}
{execute SQR command(s)}
add 1 to #num
END-WHILE

WHILE #count < #total-count


do more-work
if #curr-count = 199
break ! Exit loop
end-if
add 1 to #count
end-while

20

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Manejo de archivos
OPEN

Open a file for reading or writing

READ

Read data from a file

WRITE

Write data to a file

CLOSE

Close a file

OPEN {filename} AS {filenum}


FOR-READING | FOR-WRITING | FOR-APPEND
RECORD = {length} : FIXED | VARY
STATUS = #number_variable
OPEN 'C:\input.dat' AS 1
FOR-READING
RECORD=132:FIXED
STATUS= #Open1
If #Open1 = -1
! Error
STOP QUIET
End-If
21

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Manejo de archivos (2)

READ {filenum} INTO {SQR_variables}:{length}


While 1 = 1
Read 1 into $COURSE:6
$Dummy:14
$DESCR:30
If #end-file = 1
Break
End-if
End-while

WRITE {filenum} FROM {SQR_variable}:{length}


WRITE 10 FROM $NAME:30 - $ADDRESS:70 - $SUBJECT:30

22

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

SQR Runner
Editor y ejecutor de SQR integrado
No es distribuido por PeopleSoft
Cuenta con templates para SQR nuevos

23

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

SQR Runner
Opciones
En registry o al momento de ejecutar

Ruta donde est


el interprete

Principales Flags de SQR


-zif Indica la ruta al archivo pssqr.ini
-i Indica la ruta donde se hallan los SQCs
24

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

SQR Runner (2)


Ejecucin

Usuario de DB, no PS
25

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Debug
No tiene debugger integrado, es mediante comandos show
Se utiliza la directiva #debug para indicar que ejecute el comando
Se ejecuta con el parmetro DEBUG para indicar que ejecute las directivas
En ambientes de produccin no se usa

#debug show 'Finished query.'

26

SQR

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

Tarea V

Copyright 2007 Galaz, Yamazaki, Ruiz Urquiza, S.C.


Todos los derechos reservados

S-ar putea să vă placă și