Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE...
-
Upload
stephany-simmons -
Category
Documents
-
view
215 -
download
1
Transcript of Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE...
Printing on power systems
Printing on power systems
Program/Command
Data ReportLayout(Printer File)
Job Output Queue
*FILE*FILE
Spooled File
Printing Reports with COBOL
A Good Report…
• Heading (a meaningful report name)– Date and Page Number
• Column Headings (to identify data)• Order column from left to right to highlight
significant data• Edit numbers for readability• Include Totals at end of report and groups of items• ** To identify the ‘level’ of a total• Clearly indicate the end of the report.
Record Formats
• Each Record format is defined using it’s own Group-Item in the Working Storage Section.
• Record format name is defined using the 01 level
• Fields and literals are defined using subsequent levels with Picture & Values Clauses
How Many Record Formats?
Heading Customer Accounts Date: 2004-12-31 Page: 999
Column Heading Date Amount
Customer Heading Customer: 1015 Cindy LaurinDetail Line 2004-05-12 $100.00Detail Line 2004-06-09 $200.00Detail Line 2004-09-28 $300.00
Customer Total * Totals: 1015 Cindy Laurin $600.00
Customer Heading Customer: 1016 Bruce NugentDetail Line 2004-01-31 $100.00
Customer Total * Totals: 1016 Bruce Nugent $100.00
Report Total ** Totals: All Customers $700.00End of Report *** End of Report
Picture Clause Review
• Define Variables
• Define how Variables are displayed
Editing FunctionsFunction CharacterPrinting of a / as a separator /
Printing of Decimal Point in an integer .
Suppress Leading Zeros in an integer Z
Print a Dollar Sign in front of an integer $
Print a Comma in an integer ,
Printing of + or – signs + or -
Printing of ‘Debit’ or ‘Credit’ symbols DB or CR
Printing of Spaces as separators B
Printing of Zeros as separators 0
Print Leading asterix *
Examples
Trans-Amount PIC S9(6)V999 Value 4565.78.
Report-Item Edited Results
PIC $ZZZ,ZZZ.99-
PIC $ZZZ,ZZZ.99CR
PIC $ZZZZZZB99
PIC $ZZZZZZ.99+
Examples
Trans-Amount PIC S9(6)V999 Value 4565.78-.
Report-Item Edited Results
PIC 9(6)V999
PIC $999999V999
PIC $ZZZ,ZZZ.99
PIC $ZZZ,ZZZ.9
Examples
Trans-Amount PIC S9(6)V999 Value 4565.78-.
Report-Item Edited Results
PIC $ZZZ,ZZZ.99-
PIC $ZZZ,ZZZ.99CR
PIC $ZZZZZZB99
PIC $ZZZZZZ.99+
Printing in COBOL
FILE SECTION
FD Customer-Report.
01 Print-Record-Out.
WORKING STORAGE.01 Heading-1 05 PIC X(8) Value Spaces. 05 PIC X(17) Value ‘Customer
Accounts’ 05 PIC X(5) Value Spaces. 05 PIC X(6) Value ‘Date: ‘ 05 WS-Date-Out format of date. 05 PIC X(1) Value Spaces. 05 PIC X(6) Value ‘Page: ‘. 05 WS-Page PIC 9(3).
Printing or Writing to a Spooled File
And using an IMPLIED MOVE
WORKING-STORAGE.
01 Detail-Line-1 PIC X(80)
VALUE ‘Cindy’s Test’
01 Detail-Line-2 PIC X(80)VALUE ‘COBOL Line of Code’
WRITE Print-Record-Out FROM Detail-Line-1
WRITE Print-Record-Out FROM Detail-Line-2
Printing or Writing to a Spooled File (using AFTER ADVANCING)
Detail-Line-1 PIC X(80)
VALUE ‘Cindy’s Test’.
Detail-Line-2 PIC X(80)VALUE ‘COBOL Line of Code’.
WRITE Print-Record-Out FROM Detail-Line-1 AFTER ADVANCING 1 LINE.
WRITE Print-Record-Out FROM Detail-Line-2
AFTER ADVANCING 1 LINE.
Printing or Writing to a Spooled File (using BEFORE ADVANCING)
Detail-Line-1 PIC X(80)
VALUE ‘Cindy’s Test’.
Detail-Line-2 PIC X(80)VALUE ‘COBOL Line of Code’.
WRITE Print-Record-Out FROM Detail-Line-1
BEFORE ADVANCING 1 LINE.
WRITE Print-Record-Out FROM Detail-Line-2 BEFORE ADVANCING 1 LINE.
Printing or Writing to a Spooled File (using AFTER ADVANCING)
Detail-Line-1 PIC X(80)
VALUE ‘Cindy’s Test’.
Detail-Line-2 PIC X(80)VALUE ‘COBOL Line of Code’.
WRITE Print-Record-Out FROM Detail-Line-1.
WRITE Print-Record-Out FROM Detail-Line-2
AFTER ADVANCING PAGE.
Printing or Writing to a Spooled FileWith MIXED advancing!
Detail-Line-1 PIC X(80)
VALUE ‘Cindy’s Test’.
Detail-Line-2 PIC X(80)VALUE ‘COBOL Line of Code’.
WRITE Print-Record-Out FROM Detail-Line-1
AFTER ADVANCING 1 LINE.
WRITE Print-Record-Out FROM Detail-Line-2
BEFORE ADVANCING 1 LINE.
Control Breaks
A.K.A Level Breaks
Report Types
• Transaction Reports
• Summary or Group Reports
• Exception Reports
Summary or Group Reports
• Most efficiently handled using:– Logical Files to sort the data in Summary or
Group order– Control Breaks methodology to process the
data.
Control Break
• Occurs when there is a change in key fields when reading sequentially through a file
Customer Accounts Date: 05/04/00 Page: 999
Date AmountCustomer: 1015 Cindy Laurin-Moogk
05/01/00 $100.0005/02/00 $200.0005/03/00 $300.00
* Totals: 1015 Cindy Laurin-Moogk $600.00
Customer: 1016 Bruce Nugent05/01/00 $100.00
* Totals: 1016 Bruce Nugent $100.00
** Totals: All Customers $700.00*** End of Report
Where’s the Control Break?
What do you do at a Control Break?
• Print the totals for the save or previous key
• Initialize the accumulators used for the group or level
• Print headings for the new or file key
Single Control Break(using ifs)
Read the First Record (check for EOF)If not EOF
Write the heading for file-keyMove file-key to save-key
Do While not End of FileIf save-key file-key
Calculate & Write totals for save-keyInitialize AccumulatorsMove file-key to save-keyWrite headings for file-key
Process RecordRead the next Record (check for EOF)
ENDDOCalculate & Write totals for save-key
Single Control Break(Using Nested Loops)
Read the First Record (check for EOF)Do While not End of File
Write the heading for file-keyMove file-key to save-keyDo While file-key = save-key and not EOF
Process RecordRead the next record (check for EOF)
ENDDOCalculate & Write totals for save-keyInitialize Accumulators
ENDDO
Multiple Control Breaks (Using Ifs)Read the First Record (check for EOF)If not EOF
Write the headings for file-keyMove file-key to save-key
Do While not End of FileIf save-Primary-key file-Primary-key
Calculate & Write totals for save-Secondary-keyCalculate & Write totals for save-Primary-keyInitialize Primary & Secondary AccumulatorsMove file-key to save-keyWrite headings for Primary & Secondary file-keys
If save-Secondary-key file-Secondary-keyCalculate & Write totals for save-Secondary-keyInitialize Secondary AccumulatorsMove file-Secondary-key to save-Secondary-keyWrite headings for file-Secondary-key
Process RecordRead the next Record (check for EOF)
ENDDOCalculate & Write totals for save-Secondary-keyCalculate & Write totals for save-Primary-key
Multiple Control Breaks (Using Nested Loops)
Read the First Record (check for EOF)Do While not End of File
Write the headings for file-Primary-keyMove file-Primary-key to save-Primary-keyDo While not EOF and file-Primary-key = save-Primary-key
Write headings for file-Secondary-keyMove file-Secondary-key to save-Secondary-keyDo While not EOF and file-Secondary-key = save-Secondary- key
and file-Primary-key = save-Primary-keyProcess RecordRead the next record (check for EOF)
ENDDOCalculate & Write totals for save-Secondary-keyInitialize Secondary Accumulators
ENDDOCalculate & Write totals for save-Primary-keyInitialize Primary Accumulators
ENDDO
28
Sequential Access
• Reads one record at a time
• Reads records in arrival / sorted sequence.
29
Defining Sequential organization with sequential Access
SELECT Employee-File
ASSIGN to DATABASE-EMPPF
ORGANIZATION is SEQUENTIAL
ACCESS MODE is SEQUENTIAL.
If the ORGANIZATION clause is omitted then it is assumed sequential.
30
Sequential Read.
READ file-name
AT END
Perform end-of-file-logic
NOT AT END
Perform detail-processing
END-READ
31
Random Access Techniques
32
Random Access
• Records are processed in some other order than the one in which they were physically written to the disk or indexed.
• A key field is looked up in an index, the address is retrieved and the record is accessed from the physical file using the address.
33
Dynamic Access
• Defined when a file will be used both randomly and sequentially
34
Normalization Theory(Relational Database Design)
• First Normal Form:– Information entities are divided into Files or Tables on
the basis of their Relationships.
• Second Normal Form:– All Entities must have a logical dependency on the
Primary Key (or part of).
• Third Normal Form:– All Entities must have a functional dependency on the
Primary Key in it’s entirety.
35
Due to Normalization Practices, we usually have more than one file in our
databases.
Typically reports usually consists of one or more Sequential files and one
or more Random Access files.
36
Defining INDEXED organization with Sequential Access
SELECT Employee-File
ASSIGN to DATABASE-EMPPF
ORGANIZATION is INDEXED
ACCESS MODE is SEQUENTIAL
RECORD KEY is
EXTERNALLY-DESCRIBED-KEY
File status is WS-STATUS.
03 WS-STATUS PIC XX.
37
FILE STATUS CLAUSEWhen this clause is used the system will provide feed back to a program
in a on any I/O activity to a file.
The STATUS variable can be tested for specific errors encountered.
i.e. WRITE DATA-FILE
INVALID KEY
PERFORM CHECK-STATUS
END-WRITE
IF STATUS-FIELD = ‘00’ PERFORM ALL-IS-NORMAL
END-IF.
38
Defining a Random Access FileSELECT Employee-File
ASSIGN to DATABASE-EMPPF
ORGANIZATION is INDEXED
ACCESS MODE is RANDOM
RECORD KEY is
EXTERNALLY-DESCRIBED-KEY
(with duplicates)
File status is variable-name.
STRICTLY RANDOM
39
Defining a Dynamic Access File
SELECT Employee-File
ASSIGN to DATABASE-EMPPF
ORGANIZATION is INDEXED
ACCESS MODE is DYNAMIC
RECORD KEY is
EXTERNALLY-DESCRIBED-KEY
(with duplicates)
file status is variable-name.
40
Beware of File Status Code 95!
Need to add ‘WITH DUPLICATES’ to your select statement or your need
to take it out!
41
Randomly Retrieve a Record using a Random Defined File
Update/Populate the Key Fields in the File.
READ file-name
INVALID KEY
Perform invalid-logic
NOT INVALID KEY
Perform valid-logic
END-READ.
42
Sequentially Read using a Random Defined Record
Make sure that ACCESS is DYNAMIC!!
READ file-name NEXT RECORD
AT END
Perform perform end-of-file-logic
END-READ.
43
Positioning the File Pointer in an INDEXED organized file
Used with ACCESS Sequential or dynamic access defined files.
Initialize the record key
START file-nameINVALID KEY
Perform Invalid-LogicNOT INVALID KEY
Perform valid-logicEND-START.
A “start” MUST be followed by a valid read to retrieve the file data into the specific file’s area.
44
Other Random Access Verbs
45
REWRITE
• Updates a record in a file• File must be opened as I-O instead of input• Record must be read first before rewrite
REWRITE record-name (FROM variable-name)
INVALID KEY perform error-rtn
NOT INVALID KEY perform continue-rtn
END-REWRITE.
46
DELETE
• Deletes a record from a file• File must be opened as I-O• The record must be read first
DELETE file-name RECORD
INVALID KEY perform error-rtn
NOT INVALID KEY perform continue-rtn
END-DELETE.
47
WRITE
• Writes records to a file
• File must be opened as I-O or OUTPUT
WRITE record-name (FROM variable)
INVALID KEY perform error-rtn
NOT INVALID KEY perform continue-rtn
END-WRITE.
48
Check the source for CPCH13B to familiarize and see an example.
Source to be found in BAC344LIB CPCH13C
for use of
DECLARATIVES
DECLARATIVES
Used to declare / define / catch execution time situations / conditions “GLOBAL” to a
program