Unformatted text preview:

Interactive vs Batch ProgramsSlide 2Files, Records, FieldsOverview of the Four DivisionsSlide 5Slide 6Sample Interactive ProgramSlide 8Slide 9Data Defined in Sample ProgramPICTURE ClausePICTURE ClausesGiving Field Initial ValuePROCEDURE DIVISIONSlide 15PERFORM … END-PERFORMSlide 17Slide 18Sample Batch ProgramSlide 20COBOL DivisionsDATA DIVISION (will be repeating this many times)Slide 23Slide 24Slide 25100-MAIN-MODULEREAD StatementREAD Statement - 1READ Statement - 2200-WAGE-ROUTINE Entering & Running a ProgramCOMMENTS 1COMMENTS 2COMMENTS 31Interactive vs Batch ProgramsCobol suited for developing both types of programsInteractive programsAccept input data from keyboardInput data processed immediatelyOutput (results) displayed on screen immediately2Interactive vs Batch ProgramsBatch programsProcess large volumes of input at periodic intervalsInput data read in from filesOutput written to filesCan be files on disk, print files, files to be transmitted to a remote location: but files.3Files, Records, FieldsField – a single data item: your name; salary;Record – everything to do with a specific topic, such as all the information about YOU to generate your pay check:Your name, ssan, deductions, address, bank account number, hours worked, overtime hours….File – The grouping of individual records of all employees working in a corporation for whom you want to generate a pay check.Typically read a single record, prepare the output, read next record, and continue until EOF.Book definitions: p. 214Overview of the Four DivisionsEvery COBOL program contains up to four separate divisions in the following order:IDENTIFICATION DIVISIONENVIRONMENT DIVISION DATA DIVISIONPROCEDURE DIVISION5Overview of the Four DivisionsIDENTIFICATION DIVISIONIdentifies program to operating systemProvides documentation about program ENVIRONMENT DIVISIONDefines file-namesDescribes devices used to store themNot included in fully interactive programs6Overview of the Four DivisionsDATA DIVISIONDescribes input and output format of data in filesDefines any constants and work areasPROCEDURE DIVISIONContains instructions to read input, process it and create output7Sample Interactive ProgramPurposeto compute employee WAGESInput from keyboardHOURS and RATEProcessingcompute WAGES as HOURS x RATEOutput displayed on screenWAGES8Sample Interactive ProgramIDENTIFICATION DIVISIONOne required entry, PROGRAM-IDNames the programDATA DIVISIONDescribes and defines storage for all data Data defined in WORKING-STORAGE SECTION for interactive program9IDENTIFICATION DIVISION. PROGRAM-ID. CH0102. DATA DIVISION. WORKING-STORAGE SECTION. 01 SALES-AMOUNT PIC 999V99. 01 SALES-TAX PIC 99.99. Fields; sizes; numeric 01 MORE-DATA PIC XXX VALUE 'YES'. Field; alphanumeric PROCEDURE DIVISION. instructions: operate on data 100-MAIN. PERFORM UNTIL MORE-DATA = 'NO' DISPLAY 'ENTER SALES AMOUNT AS DOLLARS AND CENTS' ACCEPT SALES-AMOUNT reads / accepts from keyboard COMPUTE SALES-TAX = SALES-AMOUNT * .08 DISPLAY SALES-TAX writes to keyboard DISPLAY 'IS THER MORE INPUT (YES OR NO)?‘ prompts user ACCEPT MORE-DATA accepts keyboard input END-PERFORM STOP RUN.Sample COBOL Program – Interactive (no Environment Division)10Data Defined in Sample ProgramKeyed input fields (HOURS, RATE)Output fields (WAGES)Other fields used for processing (MORE-DATA) Wages (not shown)01 WAGES PIC 999.99.11PICTURE Clause01 level begins definition of each fieldmuch more later on this…01 has special significance.PICTURE or PIC clause describesType of dataNumeric (PIC 9)Nonnumeric (PIC X) (alphanumeric)Size of field - determined by number of 9’s or X’s12PICTURE ClausesRATE with PIC 99V99 includes V to show assumed decimal point positionUser enters data with decimal pointProgram uses V to align dataWAGES includes actual decimal point Shown when value displayed on screenWages (not shown)01 WAGES PIC 999.99.13Giving Field Initial ValueMORE-DATA with PIC XXX is nonnumeric fieldAssigned initial contents of YES by use of VALUE clauseValue must be in quotation marks since MORE-DATA is nonnumeric field14PROCEDURE DIVISIONSet of instructions to be executed by programOrganization of instructions planned before coding beginsPseudo-code, an English-like description of program instructions, used for planningDescribes program logic and order in which instructions will be executed15PROCEDURE DIVISIONPROCEDURE DIVISION includes one paragraph 100-MAINNote: program here is horribly simple, as we would expect at this time.There is only one paragraph (module) and a structure chart (architectural design) is almost meaningless – would contain a single box…List of instructions that follow make up paragraphPeriod follows last statement in paragraph (STOP RUN.)Main processing controlled by PERFORM … END-PERFORM loopEND-PERFORM is called a ‘scope terminator.’VERY important!16PERFORM … END-PERFORMRepeats set of instructions as long as user enters YES in response to prompt"IS THERE MORE DATA (YES/NO)?"MORE-DATA initially contains YES so instructions in loop executed first time17PERFORM … END-PERFORMWhen user enters NO as responseMORE-DATA set to "NO" and loop ends After loop, STOP RUN is executed, ending program(Note the indentation of code within the loop. This is essential to good programming style!)18PERFORM … END-PERFORMStatements in loop executed in order they are listedDISPLAY displays value in quotes or value of field on screenACCEPT stores value user enters from keyboard in fieldMULTIPLY performs calculation to find WAGES19Sample Batch ProgramIn batch mode, data comes from input file instead of keyboard Data for each employee stored in a record in file on disk (see page 21)Employee name, hours and rate data called fields20Sample Batch ProgramCalculated results (Wages) stored in file instead of displayed on screen (but can be both displayed as well as stored in a For each input recordRecord created and stored in output fileIncludes employee name, hours, rate and computed wages File intended for printing so spacing added between fields for readabilityI disagree. Most input data is NOT spaced for printing!!!Fields are all contiguous


View Full Document

UNF COP 2120 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?