Presentation is loading. Please wait.

Presentation is loading. Please wait.

Any Questions?.

Similar presentations


Presentation on theme: "Any Questions?."— Presentation transcript:

1 Any Questions?

2 Agenda Please review your marks Procedure Division.
Chapter 3 – Working with Files Chapter 4 – Printing!

3 Picture Clause Review Define Variables
Define how Variables are displayed

4 Editing Functions Function Character Printing 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 Print Leading asterix *

5 Examples Trans-Amount PIC 9(6)V999 Value 4565.78.
Report-Item Edited Results PIC 9(6)V999 PIC $999999V999 PIC $ZZZ,ZZZ.99 PIC $ZZZ,ZZZ.9

6 Examples Trans-Amount PIC 9(6)V999 Value 4565.78.
Report-Item Edited Results PIC $ZZZ,ZZZ.99- PIC $ZZZ,ZZZ.99CR PIC $ZZZZZZB99 PIC $ZZZZZZ.99+

7 Procedure Division Program Logic
Statements are executed in the order that they appear. Logic can be divided into paragraphs (sub-routines) Some advice: Make sure a logical paragraph is terminated with a period at the end of the last statement line in the paragraph.

8 The Procedure Division
It contains all the instructions the program will execute Any variable or data field referred by any instruction must have been defined in the DATA DIVISION The instructions are known as ‘statements’

9 Procedure Division (Syntax)
paragraph-name. statements.

10 Procedure Division Structure
00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. PERFORM HEADER-LINE PERFORM PROCESS-RECORDS UNTIL EOF-FLAG = 'N'. CLOSE PAYROLL-FILE PRINT-FILE. STOP RUN. EJECT HEADER-LINE. MOVE HEADING-LINE TO PRINT-LINE. WRITE PRINT-LINE. PROCESS-RECORDS. MOVE EMP-NAME TO DET-NAME MOVE EMP-HOURS TO DET-HOURS MOVE DETAIL-LINE TO PRINT-LINE COMPUTE DET-PAY = EMP-HOURS * EMP-RATE WRITE PRINT-LINE Paragraph.( Pos 8-….) A sentence/statement starts at pos 12 till …. Statement or Instruction Sentence or group of Statement

11 Coding a COBOL Program Column based 3 parts to a COBOL source line
Continuation (-) (in col 7) Area A (col. 8) Area B (col 12)

12 Program Comments (*) * to start a comment line
Generally placed in column 7 but could be used anywhere at the end of a statement preceded by a space. i.e. …–name. *

13 Area A (col 8) Division Names Section Names Paragraph Names

14 Area B Everything else (anywhere from col 12 to 72)

15 Frequently Used COBOL Verbs

16 Types of Statements Arithmetic: Add, Subtract, Compute
Input/Output: Read file records Data Manipulation: Move Selection: If..Then..Else Iteration: Perform…Until Case Structure: Evaluate..When Selection, Iteration, Case: Structured Programming Constructs

17 Working With Files (Procedure Division)
(rest of Chapter 3)

18 Opening A File OPEN STATEMENT
A File must be open before its records are processed The OPEN process makes the record buffer available to the program The buffer is named in the File Section as the DATA RECORD An OPEN will determine how to read or write in the file

19 Opening A File OPEN STATEMENT
A Sequential File can be opened in different modes: Input: Records are only read - not modified Output: Records are new or written over. I-O read and or update existing records. Extend - New records to be appended after the last record When open as output new blank record space is assigned and all fields should be populated!

20 OPEN Statement Usually the first statement in a program
Open files for processing Terminator is a period

21 OPEN STATEMENT OPEN mode file-name OPEN INPUT MASTER-FILE
OPEN OUTPUT NEW-PAYROLL OPEN EXTEND NEW-PAYROLL

22 OPEN, CLOSE, and STOP RUN STATEMENTS
PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE OUTPUT PRINT-FILE. ========= CLOSE PAYROLL-FILE PRINT-FILE. STOP RUN. Each file gets an OPEN. Each OPEN has a CLOSE: File has to be closed before to end the program

23 CLOSE Statement Closes the files used in the program
Usually the second to last set of statements executed in the program Terminator is .

24 STOP RUN Statement Terminates the program
The last statement executed in the program. Terminator is .

25 OPEN Statement Usually the first statement in a program
Open files for processing Terminator is a period

26 READ Statement Used to Read a Record from a File End of File Logic
Not End of File Logic Terminator - END-READ.

27 READ Statement READ Employee-File AT END
PERFORM 500-End-Of-File-Routine NOT AT END PERFORM 300-Process-Employee END-READ.

28 WRITE Statement Writes/Updates records in a file Terminator is .

29 CLOSE Statement Closes the files used in the program
Usually the second to last set of statements executed in the program Terminator is .

30 STOP RUN Statement Terminates the program
The last statement executed in the program. Terminator is .

31 Printing on the AS/400 Job Output Queue Program/ Command Spooled File
Data Report Layout (Printer File) *FILE *FILE

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

33 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

34 Customer Accounts Customer Accounts Date: 05/04/00 Page: 999
Date Amount Customer: 1015 Cindy Laurin-Moogk 05/01/00 $100.00 05/02/00 $200.00 05/03/00 $300.00 * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer: 1016 Bruce Nugent * Totals: 1016 Bruce Nugent $100.00 ** Totals: All Customers $700.00 *** End of Report

35 How Many Record Formats?
Heading Customer Accounts Date: 05/04/00 Page: 999 Column Heading Date Amount Customer Heading Customer: 1015 Cindy Laurin-Moogk Detail Line 05/01/00 $100.00 Detail Line 05/02/00 $200.00 Detail Line 05/03/00 $300.00 Customer Total * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer Heading Customer: 1016 Bruce Nugent Customer Total * Totals: 1016 Bruce Nugent $100.00 Report Total ** Totals: All Customers $700.00 End of Report *** End of Report

36 Page Number Manually Calculated
Need to know how many lines print on a page Printer File Your programs must have: Line-Counter Variable Page-Counter Variable

37 Printer Spacing Charts
Report Format Line Number 1 2 3 4 5 6 7 8 9

38 REMEMBER to READ a file But WRITE a RECORD

39 Sequential READ Statement
Used to Read the next Record from a File End of File Logic Not End of File Logic Terminator - END-READ.

40 Sequential READ Statement
READ Employee-File AT END PERFORM 500-End-Of-File-Routine NOT AT END PERFORM 300-Process-Employee END-READ.

41 READ STATEMENT PROCEDURE DIVISION. 00-MAIN. OPEN INPUT PAYROLL-FILE
OUTPUT PRINT-FILE. READ PAYROLL-FILE AT END MOVE 'N' TO EOF-FLAG END-READ. 01 EMPLOYEE-IN. 05 EMP-NAME PIC X(25). 05 EMP-HOURS PIC 9(03). 05 EMP-RATE PIC 99V9 USAGE COMP-3. 05 EMP-DEP PIC X(15).

42 READing A FILE The READ statement ‘gets’ the next record in the file
Format: READ file-name AT END statement. After execution the record is moved to the buffer declared in the file section as ‘record-name’

43 Display File Read Used to read information from a screen
RECORD keyword is needed because display files usually have more than one record format. Read Display-file RECORD.

44 WRITE Statement Writes/Outputs records to a file
Terminator is . Or END-WRITE. ‘Format is’ clause needed for display files Format is record format Needed because display files usually have more than one record format (screen)

45 The WRITE Statement It writes a record to a file
An OPEN OUTPUT or OPEN EXTEND has been issued prior to the WRITE WRITE adds a record to a data file WRITE prints a record to a printer file Sequential Write: WRITE file-record-name

46 Writing to a Physical File
Write Product-record invalid key display ‘write failed’ not invalid key display ‘write ok’ End-write.

47 Writing to a Report Write print-record-out.

48 Writing to a Display File
Write display-record Format is ‘RECORD1’ end-write.

49 Changing Data - 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.

50 Examples Customer Name PIC X(20) Value ‘Cindy Laurin-Moogk’
Report Item PIC X(20) PIX XXXXXXXXXXBXX

51 Customer Accounts Customer Accounts Date: 05/04/00 Page: 999 Date Amount Customer: 1015 Cindy Laurin-Moogk 05/01/00 $100.00 05/02/00 $200.00 05/03/00 $300.00 * Totals: 1015 Cindy Laurin-Moogk $600.00 Customer: 1016 Bruce Nugent * Totals: 1016 Bruce Nugent $100.00 ** Totals: All Customers $700.00 *** End of Report

52 Printing in COBOL FILE SECTION FD Customer-Report.
WORKING STORAGE. 01 Heading-1 PIC X(8) Value Spaces. PIC X(17) Value ‘Customer Accounts’ PIC X(5) Value Spaces. PIC X(6) Value ‘Date: ‘ 05 WS-Date-Out PIC 99/99/99. PIC X(1) Value Spaces. PIC X(6) Value ‘Page: ‘. 05 WS-Page PIC 9(3). FILE SECTION FD Customer-Report. 01 Print-Record-Out.

53 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 1 LINE.

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

55 Printing or Writing to a Spooled File
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.

56 Sorting Data Using Access Paths

57 Physical Files vs Logical Files
EMPLOYEEPF *FILE EMPLOYEE *FILE Physical Files or Logical Files?

58 Externally Described Files
Select Statement when physical/logical file has a key. SELECT Cobol-file-name ASSIGN TO database-actual-file-name [ORGANIZATION IS INDEXED] [ACCESS MODE IS SEQUENTIAL] RECORD KEY is data-element. (data-element could be EXTERNaLLY-DESCRIBED-KEY)

59 Externally Described Files
Copying the record layout. FD Cobol-file-name. 01 Cobol-Record-Name. COPY DD-actualrecordname OF actualfilename. (DD can be replaced by DDS if you require the 10 char field names instead of the aliases)

60 Handy Physical File Commands
DSPPFM – Display Physical File Member Displays the contents of a Physical File in arrival sequence. DSPFD – Display File Description Information about the file – eg access path. DSPFFD – Display File Field Description Displays the fields in the file.

61 Random Reads Used to retrieve a record based on the value of a key field Need an access path sorted by the key field needed Select statement changes

62 Defining a Random Access File
SELECT Employee-File ASSIGN to DATABASE-EMPPF ORGANIZATION is INDEXED ACCESS MODE is RANDOM RECORD KEY is EXTERNALLY-DESCRIBED-KEY (with duplicates).

63 Random Reads If the key field to EMPPF is the Employee-Number then:
Move 1 to Employee-Number. Read Employee-File Invalid Key Move ‘Error’ to Employee-Name-Out Not invalid key Move Employee-Name to Employee-Name- out End-Read.

64 Validating the Province Code
Database object: PROVINCES

65 Problem FILENAME is a 10 character field in the file, FILELIST.
FILELIST is a Physical file that contains a record for each of the physical files in QGPL. You are required to write a COBOL program that prints all of the files listed in FILELIST. What COBOL statement would list all of the Files in QGPL that start with ‘CHAP’?

66 ACCEPT Statement ACCEPT variable FROM DAY-OF-WEEK DATE DAY TIME
DAY-OF-WEEK = 1-7 (Mon-Sun) DATE = YYMMDD DAY = Julian Date TIME = hhmmsshh

67 Convert YYMMDD to MMDDYY?
01 Heading WS-RUN-DATE 05 HL-RUN-MNTH WS-RUN-YEAR 05 HL-RUN-DAY WS-RUN-MONTH 05 HL-RUN-YEAR WS-RUN-DAY ACCEPT WS-RUN-DATE FROM DATE. MOVE WS-RUN-MONTH TO HL-RUN-MONTH. MOVE WS-RUN-DAY TO HL-RUN-DAY. MOVE WS-RUN-YEAR TO HL-RUN-YEAR.

68 Indicators in Display Files

69 Option Indicators in COBOL
Binary Values Working Storage Definition example 01 ws-indicator-list. 05 IN88 INDICATOR 88 PIC 1 value B’0’. Passed to display files in the write statement Write Display-record format is ‘RECORD1’ indicators are ws-indicator-list.

70 Example – Indicator 90 displays the message, Employee Name is invalid
Working Storage. 01 ws-indicators. 05 IN90 INDICATOR 90 pic 1. Procedure Division. If scr-employee-name is equal to spaces move b’1’ to IN90 else move b’0’ to IN90 end-if.

71 Response Indicators in COBOL
Stored as binary values in the display file and passed as PIC X(2) via the control Area. Select Display-file assign to workstation-dspfile-si organization is transaction control area is ws-control. Working Storage Section. 01 ws-control. 05 ws-function-key pic x(2).

72 Example – check to see if function key 3 was pressed.
Select Display-file assign to workstation-dspfile-si organization is transaction control area is ws-control. Working Storage Section. 01 ws-control. 05 ws-function-key pic x(2). Procedure Division. if ws-function-key = ’03’ ….. end-if.


Download ppt "Any Questions?."

Similar presentations


Ads by Google