| This's the code. You can find the SQL_REPORT.SCO file in the RDM$DEMO
directory.
The same command on my VAX machine has not problem.
Thanks,
Massimo
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
identification division.
program-id. sql-report.
*
* This program uses DEC COBOL and DEC Rdb SQL statements to create a
* report based on the PERSONNEL database. The report provides salary
* details and totals for each department. The report file, SQLSAMP.RPT,
* is created in the RDM$DEMO directory.
*
environment division.
input-output section.
file-control.
select report_file assign to "sqlsamp.rpt".
data division.
file section.
fd report_file report is sample_report.
working-storage section.
*
* Copy the SQL Communication Area into the program to define
* fields that the program will use when checking exception
* conditions.
*
exec sql include sqlca end-exec.
*
* Declare the database which the program accesses with
* the first executable SQL statement.
*
exec sql declare alias filename 'personnel' end-exec.
*
* Declare the type of transaction that the first executable
* SQL statement in the program will start.
*
exec sql declare transaction read only end-exec.
*
* Declare the cursor from whose result table the program
* fetches data to be used in the report. Rows are ordered
* first by DEPARTMENT_CODE and then by JOB_CODE so that
* row order in the result table is correct given the control
* breaks defined later in the program for the report.
* This cursor provides data needed for the detail lines of
* the report. Salary amount totals at the control breaks are
* done by host language statements, not by SQL.
*
* The DECLARE CURSOR statement is not executable; thus, you do
* not monitor its execution with an error handler. You can
* include the statement anywhere above its reference in source
* code. You can include it in an SQL context file instead of
* writing it in source code.
*
exec sql declare report_cursor cursor for
select j.employee_id, j.last_name, j.first_name,
j.job_code, j.department_code, s.salary_amount
from current_job j, current_salary s
where j.employee_id = s.employee_id
order by j.department_code, j.job_code
end-exec.
*
* Specify the subroutine to which the program will pass control
* when an SQL exception condition occurs.
*
exec sql whenever sqlerror goto error_handler end-exec.
*
* INPUT_REC is a variable into which the program places
* a result table row. (The program moves INPUT_REC contents
* into report variables both to output a detail line for the
* report and to augment values being totaled by the program.)
*
*
* NOTE: This example assumes that each row returned to the
* program contains a value in each column. To handle null values
* in columns used by your program, you need program declarations
* for indicator variables as well as main variables.
*
01 input_rec.
02 employee_id pic x(5).
02 last_name pic x(14).
02 first_name pic x(10).
02 job_code pic x(4).
02 department_code pic x(4).
02 salary_amount pic s9(7)v99 comp.
01 todays-date.
02 mm pic xx.
02 pic x value '/'.
02 dd pic xx.
02 pic x value '/'.
02 yy pic xx.
01 accept-date.
02 yy pic xx.
02 mm pic xx.
02 dd pic xx.
01 employee-name pic x(24).
report section.
rd sample_report
controls are final, department_code, job_code
page limit is 66 heading 1 first detail 4 last detail 58.
01 page-header type is page heading.
02 line is 1.
04 column 26 pic x(11) value "SALARY DATA".
04 column 64 PIC X(11) source todays-date.
02 line is 2.
04 column 24 pic x(14) value "BY DEPARTMENTS".
04 column 64 pic x(6) value "Page ".
04 column 70 pic 99 source page-counter.
01 job-code-head type is control heading job-code.
02 line is plus 2.
04 column 10 pic x(3) value 'Job'.
04 column 62 pic x(6) value 'Salary'.
02 line is plus 1.
04 column 1 pic x(4) value 'Dept'.
04 column 10 pic x(4) value 'Code'.
04 column 18 pic x(2) value 'Id'.
04 column 24 pic x(14) value 'Last Name'.
04 column 40 pic x(10) value 'First Name'.
04 column 62 pic x(6) value 'Amount'.
02 line is plus 1.
04 column 1 pic x(4) value all '-'.
04 column 10 pic x(4) value all '-'.
04 column 18 pic x(5) value all '-'.
04 column 24 pic x(14) value all '-'.
04 column 40 pic x(10) value all '-'.
04 column 59 pic x(14) value all '-'.
01 detail-line type is detail line is plus 1.
02 column 1 pic x(4) source department_code.
02 column 10 pic x(4) source job_code.
02 column 18 pic x(5) source employee_id.
02 column 24 pic x(14) source last_name.
02 column 40 pic x(10) source first_name.
02 column 59 pic $$,$$$,$$9.99 source salary_amount.
01 job-code-foot type is control footing job-code.
02 line is plus 2.
03 column 59 pic x(14) value is all "-".
02 line is plus 1.
03 column 30 pic x(4) source job_code.
03 column 35 pic x(16) value is 'Salary Total in'.
03 column 51 pic x(4) source department_code.
03 column 55 pic x value is ':'.
03 column 59 pic $$,$$$,$$9.99 sum salary_amount.
01 dept-code-foot type is control footing department-code.
02 line is plus 2.
03 column 54 pic x(19) value is all "-".
02 line is plus 1.
03 column 25 pic x(16) value is 'Total Salary For'.
03 column 42 pic x(4) source department_code.
03 column 46 pic x value is ':'.
03 column 55 pic $$,$$$,$$$,$$9.99 sum salary_amount.
01 final-foot type is control footing final.
02 line is plus 2.
03 column 54 pic x(19) value is all "-".
02 line is plus 1.
03 column 25 pic x(22) value is 'Grand Total Salaries:'.
03 column 55 pic $$,$$$,$$$,$$9.99 sum salary_amount.
procedure division.
driver.
*
* Do setup tasks:
*
* o Open the report file
*
* o Open the cursor to create the result table containing data
* for the report
*
* The OPEN statement is the first executable SQL statement in
* the program and so causes the program to connect with the
* database and start the transaction declared earlier.
*
* o Initiate the report.
*
open output report_file.
exec sql open report_cursor end-exec.
initiate sample-report.
*
* Initialize some variables needed for the report header.
*
accept accept-date from date.
move corr accept-date to todays-date.
*
* Loop through all of the records in the cursor and generate a detail
* line for each. (The condition SQLCODE = 0 is true unless
* an error condition occurs or the "no next record" condition is
* encountered.) The control specifications in the preceding
* COBOL report description cause the program to calculate and output
* the appropriate salary total whenever a value change occurs for
* JOB_CODE or DEPARTMENT_CODE and also at the end of the report.
*
perform until sqlcode not = 0
exec sql fetch report_cursor into input_rec end-exec
if sqlcode = 0 then generate detail-line end-if
end-perform.
*
* Do cleanup tasks:
*
* o End the report
*
* o Close the file and delete the result table
* associated with the cursor declaration
*
* o End the transaction
*
* o Stop the program
*
terminate sample-report.
close report_file.
exec sql close report_cursor end-exec.
exec sql rollback end-exec.
stop run.
error_handler.
display "an unexpected error was encountered ", sqlcode with conversion.
call "sql_signal".
stop run.
|