Presentation is loading. Please wait.

Presentation is loading. Please wait.

DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment.

Similar presentations


Presentation on theme: "DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment."— Presentation transcript:

1 DT266/2 Information Systems COBOL Revision

2 Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment Division Configuration Section  Special-Names Input-Output Section  File-Control Data Division File Section Working-Storage Section Screen Section Report Section Linkage Section Procedure Division

3 Basic Statements Move Add Subtract Multiply Giving Divide Perform

4 Paragraphs Paragraph Grouping of statements that can be placed anywhere within a program Execute using PERFORM statement  PERFORM para-name. Use for maintainability and readability When a paragraph is executed, control returns to the statement after the perform Displaced paragraph Occurs after the stop run and performed from elsewhere in the program

5 Chapter 2 Hutty & Spence Data & Conditions Conditions, and, or, not, less than, ….. Data Pictures Computational and display data types PIC Types 9, A, X, Z, $, etc Decimals V,. Signs +. -, CR, DB Commas, currency MOVE Rules for different data types

6 Chapter 2 Hutty & Spence LEVELS Group Item 01 can contain subordinate items which must have higher number Level 88 Condition Name Specifies that a condition is true when value of data item changes to that defined in the associated picture clause 01 WS-MONTH. 88 VALID-MONTH VALUE 1 THROUGH 12. 88 FEBVALUE 2. 88 30-DAYVALUE 4,6,9,11. EVALUATE TRUE WHEN 30-DAY WHEN FEB WHEN OTHER END-EVALUATE

7 Validation Range Checks Level 88s Selection checks If Alphabetic checks Special names Complex checks Combine checks and, or, not Especially important when working with files No record should be written to a file unless the data is valid Reason for accepting into working-storage not directly into a file

8 Chapter 3, 4, 5, 6 Hutty & Spence Control Constructs - Selection IF statement IF …. THEN ELSE ENDIF EVALUATE statement EVALUATE WHEN A> B PERFORM A WHEN A { "@context": "http://schema.org", "@type": "ImageObject", "contentUrl": "http://images.slideplayer.com/8/1386892/slides/slide_8.jpg", "name": "Chapter 3, 4, 5, 6 Hutty & Spence Control Constructs - Selection IF statement IF ….", "description": "THEN ELSE ENDIF EVALUATE statement EVALUATE WHEN A> B PERFORM A WHEN A

9 Chapter 3, 4, 5, 6 Hutty & Spence Control Constructs - Iteration PERFORM statement LEADING EDGE While Loop Test Before TRAILING EDGE Repeat Loop Test After VARYING For Loop

10 Chapter 3, 4, 5, 6 Hutty & Spence Control Constructs – Iteration LEADING EDGE Display “Enter Age : “. Perform Enter-Age until AGE-IN > 3 and AGE-IN < 19. Condition is evaluated at the start of each loop Execute 0 or more times TRAILING EDGE Perform Accept-Option WITH TEST AFTER UNTIL WS-OPTION >0 AND WS-OPTION < 6. Forces code to be executed at least once and then condition is tested

11 Chapter 3, 4, 5, 6 Hutty & Spence Control Constructs - Iteration FOR LOOP Perform Display-Array- Value varying WS- ARRAY-INDEX from 1 by 1 Execute statements a set number of times. FOR LOOP Perform Display-Array- Value varying WS- ARRAY-INDEX from 1 by 1 until ARRAY- INDEX > 10 Execute statements a set number of times.

12 Chapter 7 & 8 Hutty & Spence Arrays An array is a group item each of its elements belongs to it Each element has the same picture and the element ‘occurs’ a number of times Subscripting always starts at 1. Arrays are fixed length Indexing Can be part of the definition Can be controlled by another working storage variable

13 Chapter 7 & 8 Hutty & Spence 1- D Arrays Definition 01 months-of-the-year. 03 month-name pic AAA occurs 12 times indexed by month-no. Indexing Set month-no to 1. Set month-no up by 1. Referencing Display Month-Name (Month #)

14 Chapter 7 & 8 Hutty & Spence 2-D Arrays Definition 01 box-of-chocolates. 02 layer-of-chocolates occurs 4 times indexed by layer-no. 03 chocolate occurs 20 times pic 99 indexed by choc-no. Indexing as before Referencing Access lowest level Chocolate (layer #, chocolate #)

15 Chapter 7 & 8 Hutty & Spence Arrays - Initialising Within the procedure division Move Accept Use perform statement to control Within working storage section Redefines clause 01 Month-Days. 02 Jan-Dayspic 99value 31. 02 Feb-Dayspic 99value 28. 02 Mar-dayspic 99value 31. 02 Dec-dayspic 99value 31. 01 Days-arrayredefines Month-Days pic 99 occurs 12 times. OR 01 Days-of-yearpic 9(36) value 312831303130313130313031. 02 Month-Daysredefines Days-of-year pic 99 occurs 12 times.

16 Chapter 11, 12, 13, 14 Hutty & Spence File Handling File Introduced in Environment Division Input-Output Section File-Control What happens ? Give logical name by which file will be referred to in program Give physical name and location of file Describe file organisation and method used to access it

17 Chapter 11, 12, 13, 14 Hutty & Spence File Handling Describe the structure of the records in the file Data Division File Section. FD 01 Each file must have a File Descriptor entry in the File Section Record must be level 01 Do not embed validation in file descriptors

18 Chapter 11, 12, 13, 14 Hutty & Spence File Organisation 3 Types Sequential  Records stored one after another in order in which they are written Indexed Sequential  Each record is given a key that determines its position Relative

19 Chapter 11, 12, 13, 14 Hutty & Spence File Access Sequential Access Next record in sequence is read/written A file whose organisation is sequential can only have sequential access Random Access Record is read/written by specifying its KEY Relative or Indexed Sequential Files Dynamic Access Combination of the above Relative or Indexed Sequential files

20 Chapter 11, 12, 13, 14 Hutty & Spence Sequential Files Writing Open output OR Open extend Write Close Reading Open Input Read Close Checking for End of File Read  AT END  NOT AR END End-Read Use a Level 88 Cannot Rewrite Can Delete

21 Chapter 11, 12, 13, 14 Hutty & Spence Indexed Sequential Files Declaring Organisation Keys (primary & alternate) Access method Reading Open Input OR Open I-O Read  Invalid Key  Not Invalid Key End-Read Close Positioning using a key START FILE-NAME KEY NOT < KEY-NAME INVALID KEY INVALID KEY CLAUSE {NOT INVALID KEY NOT INVALID KEY CLAUSE} END-START

22 Chapter 11, 12, 13, 14 Hutty & Spence Indexed Sequential Files Writing Open Output OR Open extend OR Open I-O Write  Invalid Key  Not Invalid Key End-write Close ReWriting Open I-O Rewrite  Invalid Key  Not Invalid Key End-Rewrite Close Must have positioned at record first Deleting Always ask DELETE record

23 Chapter 11, 12, 13, 14 Hutty & Spence Relative Files Records can be accessed directly, according to the number of the record within the file Each record has a key, which is it’s relative address from the start of the file This is suitable for only a small number of records

24 Chapter 17 Hutty & Spense Report Writer Report Section Reports written to external file Declare file to program File Definition FD Report is RD Report Definition  Must Define PAGE LIMIT No. of lines to print on each page HEADING Line at which heading will appear FIRST DETAIL Line at which first detail will appear LAST DETAIL Line at which last detail will appear FOOTING Line at which footing will appear

25 Chapter 17 Hutty & Spense Report Writer Each RD entry consists of one or more 01 level-number entries. Each 01 level-number entry identifies a report group A unit consisting of one or more print lines and is of a particular type. Report Heading - Printed once at start of the report Report Footing - Printed once at the end of the report Page Heading - Printed at the start of every page Page Footing - Printed at the end of every page Detail - Basic report detail, the body of the report Control Heading - Printed each time some particular value changes Control Footing - Printed each time some particular value changes

26 Chapter 17 Hutty & Spense Report Writer Defining Report Lines Must identify the type of line Have sub-ordinate items Must identify the line on which it is to be printed in the report For each section of the line must identify where the data to be included is positioned I.e. column Must identify the source of the data to be included on that line

27 Chapter 17 Hutty & Spense Report Writer Controlling Reports Define control in the report definition RD STOCK-REPORT CONTROLS ARE FINAL, DEPARTMENT Data to control report must appear in a detail or control line FINAL is a report writer specific word Ensures last control footing of the report will be output When detail line first generated report writer saves values of control data items Each time a detail line is generated report item checks to see if values have changed beginning with the first listed in the RD If a control data item changes it also cause all other control breaks that are sub-ordinate to it

28 Chapter 17 Hutty & Spense Report Writer Creating the report in Procedure Division OPEN File INITIATE the report GENERATE the lines of the report TERMINATE the report CLOSE File

29 Chapter 15 Hutty & Spence Sorting Simple Sorting File to be sorted is copied to special work file Records in this work file are sorted into the requested order Sorted work file is copied to an output file Declare Work-file in Environment Division Select SortFile assign to dummy. Define structure of workfile in File Section SD SORT-FILE. 01 S-CAR-RECORD. Sort file in Procedure Division SORT ON {ASCENDING/DESCENDING } KEY {IDENTIFIER} USING GIVING

30 Chapter 15 Hutty & Spence Sorting Selective Sorting Sort as before, but Cut down on the fields in the output file Or include other fields in the output file Change the procedure division to sort using an input procedure and output procedure instead of input and output files Define 2 more sections, one for the input procedure and one for the output procedure Release records into the sort and Return them from the sort Keywords USING and GIVING not required instead have INPUT PROCEDURE IS OUTPUT PROCEDURE IS

31 Chapter 15 Hutty & Spence Sorting Write record to sort file Read record from sort file


Download ppt "DT266/2 Information Systems COBOL Revision. Chapters 1 & 2 Hutty & Spence Divisions of a Cobol Program Identification Division Program-ID. Environment."

Similar presentations


Ads by Google