Presentation is loading. Please wait.

Presentation is loading. Please wait.

DT266/2 COBOL Basics – Declaring Data Basic Operations.

Similar presentations


Presentation on theme: "DT266/2 COBOL Basics – Declaring Data Basic Operations."— Presentation transcript:

1 DT266/2 COBOL Basics – Declaring Data Basic Operations

2 Program Development Design Program Write Code Compile Test Release Maintain

3 COBOL Program Structure Program = sequence of statements COBOL program consists of 4 divisions IDENTIFICATION DIVISION ENVIRONMENT DIVISION DATA DIVISION PROCEDURE DIVISION Identification is mandatory Others optional but must appear in order given above if they do appear

4 Divisions Identification Division Used to identify the program Only required entry is PROGRAM-ID Can include authors name, date, comments on function as comments Environment Division Used to associate program with the computer system on which it will run Leave blank for now – will deal with in file handling

5 Divisions Data Division Used to specify the type of data used I.e. files, records, other items Two Sections FILE SECTION WORKING-STORAGE SECTION Procedure Division Contains instructions to achieve program function

6 COBOL Structure DIVISIONS SECTIONS PARAGRAPHS SENTENCES STATEMENTS CLAUSES

7 COBOL Line of Code 80 character line – position is important Column 1-6 = sequence number Column 7 = indicator * means comment - word continued from previous line Area A = Columns 8 – 12 Division headers, section headers, paragraph names, some data description Area B = Columns 12 – 72 Code statements

8 COBOL Restrictions Beware of case Use full stop Terminate division, section, paragraph headers Data item definitions Most code statements Exceptions statements within IF or PERFORM

9 Program Development Design Sequence Selection Iteration Writing code in COBOL Data Division & Procedure Division Compiling Converts COBOL code to machine code Machine code = object program Executing Code from procedure division is run

10 Data Division All data used in code statements must be defined in data division Data items (variables) Arrays Records Files Two sections FILE SECTION (will deal with later) WORKING-STORAGE SECTION

11 Data items – Level Number Permissible numbers 01-49, 77 01 levels must be in Area A column 8-11 Allow data items to be sub-divided into different levels 01 Customer-name. 03 Customer-TitlePic x(3). 03 Customer-Firstname. 05 Customer-InitialPic x.P 05 Customer-AllPic x(20). 03 Customer-SurnamePic x(20). Levels above 01 must be subordinate to a data item of level 01 Sub levels must be indented one tab from their parent

12 Data Item – Level Numbers Can be used to group items for clarity e.g 01WS-COUNTERS. 03 COUNT-EGGSPIC 9. 03 COUNT-BACON PIC 9.

13 Data Item - Names Can consist of characters a-z, A-Z, 9 and – May be up to 30 characters long - cannot be the first or last letter All names must include one alphabetic character Cannot be a RESERVED word (see handout)

14 Data Items - Picture Describes the length and type of data that can be contained in the item TypeDescriptionDefinition AlphabeticAlphabetic characters A Numeric0-99 CharacterAny characterX

15 Data Item - Picture E.g 01MY-NAMEPIC A(10). 01 MY-AGEPIC 9(3). LAWLESA 002

16 Data Item – Value Clause You can set the initial value of a data item at definition time using the Value clause E.g 01 MY-AGEPIC 9(3)VALUE 2. 01 MY-NAMEPIC A(10) VALUE LAWLESS. Always provide an initial value for data items used to control program execution

17 Basic Instructions Procedure division is sequence of English like statements Getting Data In from keyboard ACCEPT For Fujitsu many have to include from console at end of this statement Sending Data To Screen DISPLAY with no advancing Move data from one item to another Move to Terminate Program STOP RUN.

18 Basic Maths MOVE A TO B ADD A TO B ADD A TO B GIVING C BEFORE AB 1020 AFTER AB 10 BEFORE AB 1020 AFTER AB 1030 BEFORE ABC 10205 AFTER ABC 102030

19 Basic Maths SUBTRACT A FROM B SUBTRACT A FROM B GIVING C What will be in C after? MULTIPLY A BY B MULTIPLY A BY B GIVING C BEFORE AB 1020 AFTER AB 10 BEFORE AB 1020 AFTER AB 20010 BEFORE ABC 10205 AFTER ABC 1020200

20 Basic Maths DIVIDE A BY B DIVIDE A BY B GIVING C BEFORE AB 2010 AFTER AB 210 BEFORE ABC 20105 AFTER ABC 20102


Download ppt "DT266/2 COBOL Basics – Declaring Data Basic Operations."

Similar presentations


Ads by Google