CPSC1111 Cobol - Columbus State Universitycsc.columbusstate.edu/rogers/COBOL-I.ppt · PPT file ·...

Click here to load reader

  • date post

    30-Mar-2018
  • Category

    Documents

  • view

    216
  • download

    3

Embed Size (px)

Transcript of CPSC1111 Cobol - Columbus State Universitycsc.columbusstate.edu/rogers/COBOL-I.ppt · PPT file ·...

  • CPSC3111/CISM3111 COBOL

    Structured COBOL Programming

    Text: murachs structured COBOL

    Authors: Murach, Prince, Menendez

  • What is a Computer?

    Components of a ComputerInput Unit(s); Keyboard, tape, disksOutput Unit(s); CRT, tape, disksMemory (Storage) units [Addresses]Control Unit (Executes Instructions)Arithmetic/Logic Unit (Math and Logic)Only understands machine language

  • Hardware / Software

    Hardware: Physical equipmentSoftware: Programs, commands, etc.System: O/S, compilers, utilities, etc.Application: User or third party supplied.Languages: Assembler, Basic(VB), Fortran, RPG, Easytrieve, C, C++, C#, Ada, Java, Compilers job - translate source language to machine language (or byte code)

  • Online vs Interactive

    Off-line = batchLocal BatchRemote BatchOnline = InteractiveMany users with terminals (PCs)Can be either local or remote Single/Multiple User - Timesharing

  • Data Organization

    Bit - Binary digIT - [on/off] or [1/0]Character - byte (8 Bits)Field - One or more Bytes (Characters)Record - One or more FieldsFile - One or more RecordsDatabase - One or more FilesUsually contains metadata

  • Report Components

    Page HeadingColumn HeadingsReport BodyPossibly with subtotals, etc.SummaryFinal totals, summary totals, etc.

  • Program Design

    ProgramSequence of instructions describing actions to be taken by the computerFlowchartGraphical description of program logicUses rectangles, diamonds, ovals, etcPseudocodeSymbolic representation of program logicMore ENGLISH-like

  • Data Information Needed

    Type and SizeTypesAlphabetic (Seldom used = A)Alphanumeric (X)Numeric (Sign and Decimal)BinaryNumericPacked NumericFloating Point, etc. (Compatibility)

  • Program Development

    Define problemDesign test dataDesign programCode programCompile programTest programDocument Program

    End of Chapter 1.

  • Identifier Rules

    30 Character MaximumA-Z, a-z, 0-9, - Characters- not first or last characterUsually at least 1 alphabetic

    Begin Chapter 2.

  • CARD FORMAT

    01 - 06 Line Numbers (XNU)07Comment / Debug08 - 11Margin A12 - 72Margin B73 - 80Identification (XNU)

  • COBOL Divisions

    IDENTIFICATION DIVISION.ENVIRONMENT DIVISION.DATA DIVISION.PROCEDURE DIVISION.

    Divisions can be divided into SECTIONSSections can be divided into PARAGRAPHSParagraphs are composed of SENTENCES

  • IDENTIFICATION

    IDENTIFICATION DIVISION.PROGRAM-ID. PROG1.

    All other entries are obsoleteAn * in cc07 can be used (Comment)

  • ENVIRONMENT

    ENVIRONMENT DIVISION.INPUT-OUTPUT SECTION.FILE-CONTROL.SELECT INPUT-FILE

    ASSIGN TO MYINFILE.

    SELECT PRINT-FILE

    ASSIGN TO MYREPORT.

  • ENVIRONMENT (SELECTS)

    SELECT PRINT-FILE ASSIGN TO \RMC\DATA\INPUT.DAT.(For PC Files)

    SELECT PRINT-FILE ASSIGN TO PRINTER-QPRINT.(For AS400 Files)

  • DATA

    DATA DIVISION.FILE SECTION.FD INPUT-FILE.01 INPUT-REC. 10 FILLER PIC X(80).FD PRINT-FILE.01 PRINT-REC. 10 FILLER PIC X(132).

  • WORKING-STORAGE

    WORKING-STORAGE SECTION.Programs scratchpadLEVEL NUMBERS 01-4901 STARTS IN COLUMN 802-49 COLUMN 12 AND UPUsually use 05, 10, 15, 20,EACH 01 IS A NEW RECORDAll fields must be specified

  • PROCEDURE

    PROCEDURE DIVISION.010-START-HERE.(INITIALIZATION)

    (PROCESS CONTROL LOOP)

    (TERMINATION)

  • OPEN

    OPEN INPUT file-nameOPEN OUTPUT file-name(Gets files ready for processing)

  • ACCEPT

    ACCEPT identifier FROM DATE identifier will contain YYMMDDACCEPT identifier FROM TIME identifier will contain HHMMSSMS (Used to get date and time)ACCEPT identifier [options]Gets data from keyboard

  • MOVE

    MOVE identifier-1 TO identifier-2 (Alpha - Left Just. - Space Filled) (Numeric - decimal aligned) (Edited - follows edit characters)

  • READ

    READ file-name [into WS-name] AT END ANY IMPERATIVE STATEMENT(S)END-READREAD INPUT-FILE INTO WS-IN-REC AT END MOVE YES TO EOF-FLAGEND-READ

  • WRITE (Generic)

    WRITE record-name [FROM ws-name] AFTER ADVANCING identifier LINESEND-WRITE

    WRITE PRINT-REC FROM WS-PRINT-REC AFTER ADVANCING WS-SPACINGEND-WRITE

  • WRITE (New-Page)

    MOVE SPACES TO PRINT-RECWRITE PRINT-REC AFTER ADVANCING PAGEEND-WRITE (Used to start new page for heading.)

  • PERFORM

    PERFORM Paragraph-namePERFORM Paragraph-name UNTIL Condition

    PERFORM 100-READ-INPUTPERFORM 300-PROCESS-DATA UNTIL EOF-FLAG = YES

  • ADD

    ADD literal TO identifier-1ADD 1 TO REC-COUNT

    ADD identifier-1 TO identifier-2ADD WS-SPACING TO WS-LINES

  • Decisions - Simple

    IF Condition-1 True StatementsEND-IF

  • Relational Conditions

    > GREATER THAN< LESS THAN= EQUAL TO>= GREATER OR EQUAL
  • Decisions - ELSE

    IF condition-1 True StatementsELSE False StatementsEND-IF

  • Decisions - Examples

    IF HOURS-WORKED > 40 PERFORM 350-CALC-OVERTIMEELSE PERFORM 360-CALC-REGTIMEEND-IF

  • Decisions - complex

    IF complex-condition True statementsELSE False statementsEND-IF

  • Complex - conditions

    Two or more simple conditions connected with AND or OR.IF (DEPARTMENT = 234 AND HIRE-DATE < 96-06-01) ADD 1 TO OVER-5-YEARSEND-IF

  • CLOSE

    CLOSE file-nameCLOSE INPUT-FILE (Terminate file processing.)

  • GOBACK / STOP RUN

    GOBACK. (Returns to calling entity.)

    STOP RUN. (Returns to Operating System)

    End of Chapter 1.

    Begin Chapter 2.