printing on power systems program/ command data report layout (printer file) job output queue *file...

48
Printing on power systems

Upload: stephany-simmons

Post on 02-Jan-2016

215 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Printing on power systems

Page 2: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Printing on power systems

Program/Command

Data ReportLayout(Printer File)

Job Output Queue

*FILE*FILE

Spooled File

Page 3: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Printing Reports with COBOL

Page 4: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 5: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 6: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 7: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Picture Clause Review

• Define Variables

• Define how Variables are displayed

Page 8: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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 *

Page 9: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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+

Page 10: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 11: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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+

Page 12: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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).

Page 13: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 14: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 15: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 16: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 17: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 18: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Control Breaks

A.K.A Level Breaks

Page 19: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Report Types

• Transaction Reports

• Summary or Group Reports

• Exception Reports

Page 20: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 21: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

Control Break

• Occurs when there is a change in key fields when reading sequentially through a file

Page 22: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled 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?

Page 23: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 24: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 25: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 26: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 27: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 28: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

28

Sequential Access

• Reads one record at a time

• Reads records in arrival / sorted sequence.

Page 29: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 30: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

30

Sequential Read.

READ file-name

AT END

Perform end-of-file-logic

NOT AT END

Perform detail-processing

END-READ

Page 31: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

31

Random Access Techniques

Page 32: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 33: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

33

Dynamic Access

• Defined when a file will be used both randomly and sequentially

Page 34: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 35: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 36: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 37: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 38: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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

Page 39: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 40: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

40

Beware of File Status Code 95!

Need to add ‘WITH DUPLICATES’ to your select statement or your need

to take it out!

Page 41: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 42: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 43: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 44: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

44

Other Random Access Verbs

Page 45: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 46: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 47: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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.

Page 48: Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File

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