Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO.

Slides:



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

2-1 Chapter 2.  Coding Requirements of IDENTIFICATION DIVISION  Sections of ENVIRONMENT DIVISION  Assigning Files to Devices in ENVIRONMENT DIVISION.
The IDENTIFICATION and ENVIRONMENT DIVISIONS Chapter 2.
5-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
Programming Logic and Design Fourth Edition, Introductory
© 2004 Pearson Addison-Wesley. All rights reserved5-1 Iterations/ Loops The while Statement Other Repetition Statements.
Understanding the Mainline Logical Flow Through a Program (continued)
COBOL for the 21 st Century Stern, Stern, Ley Chapter 1 INTRODUCTION TO STRUCTURED PROGRAM DESIGN IN COBOL.
- Meeting 4 – Writing a Complete Program
Welcome to SAS…Session..!. What is SAS..! A Complete programming language with report formatting with statistical and mathematical capabilities.
Chapter 8 Printing 1. In COBOL you send data to the printer by writing data to a file. In COBOL, the printer is defined as a file, and it is opened, closed,
Any Questions!. Agenda Fun with Functions –how to get the system date Condition Names INDARA and SI Iteration Logical Files Positioning the file pointer.
Structured COBOL Programming, Stern & Stern, 9th edition
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
COBOL Programming DAY 2. Copyright © 2005, Infosys Technologies Ltd 2 ER/CORP/CRS/LA01/003 Version 1.0  Data Movement verbs.  Sequence Control verbs.
4-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
2-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
History COBOL (Common Business Oriented Language) was one of the earliest high-level programming languages. COBOL was first proposed in 1959 by the Conference.
Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!
Programming in COBOL-85 For IBM Mainframe System 390 Jyothi Sridhar Kini E&R, Infosys Mail-id: Phone:
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
The DATA DIVISION Chapter 3. COBOL Data Organization Field - group of characters forming a meaningful unit or basic fact –Characters in a name or digits.
3-1 Chapter 3. To familiarize you with  Ways in which data is organized in COBOL  Rules for forming data-names  Defining input and output files in.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
CS CS Computing for Business Instructor:David Tucker GTA:Batul Mirza.
Printing on power systems Program/ Command Data Report Layout (Printer File) Job Output Queue *FILE Spooled File.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
Indexed and Relative File Processing
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
1 The Procedure Division Chapter 4. 2 Main Two Sections File Section –Used to define files and record formats –Field names within records Working Storage.
CPSC3111/CISM3111 COBOL Structured COBOL Programming Text: murach’s structured COBOL Authors: Murach, Prince, Menendez.
9-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
9-1 Iteration: Beyond the Basic PERFORM Chapter 9.
Visual Basic Programming
Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout.
Any Questions!. Test Coming Up! Agenda Printing with Externally Described Printer Files Arrays.
COBOL Screens Please use speaker notes for additional information!
Structured COBOL Programming, Stern & Stern, 9th Edition CHAPTER 2 Cobol Language Fundamentals.
1 Chapter 5 – The Procedure Division File handling statements –OPEN statement Initiates processing for a file Input Output Each file opened must have been.
1 Chapter 9. To familiarize you with  Simple PERFORM  How PERFORM statements are used for iteration  Options available with PERFORM 2.
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
2-1 COBOL for the 21 st Century Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout (Emeritus)
PowerPoint Presentation: Richard H. Baum, Ph.D. DeVry Institute of Technology 9th Edition Structured COBOL Programming Nancy Stern Hofstra University Robert.
1.  Introduction  The Benefits of the Report Writer Module ◦ For Detail and Summary Printing ◦ For Control Break Processing ◦ For Printing Headings.
Any Questions? Week 1 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
The PERFORM. The PERFORM Verb  Iteration is an important programming construct. We use iteration when we need to repeat the same instructions over and.
 2007 Pearson Education, Inc. All rights reserved. A Simple C Program 1 /* ************************************************* *** Program: hello_world.
Week 2/3 - 2nd Lecture Intro to COBOL Programming Defining Files and Processing Data.
371 Structured COBOL Programming Nancy Stern Hofstra University Robert A. Stern Nassau Community College James P. Ley University of Wisconsin-Stout John.
Random update Please use speaker notes for additional information!
Introduction to Sequential Files. COBOL's forte  COBOL is generally used in situations where the volume of data to be processed is large.  These systems.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Silberschatz and Galvin  C Programming Language Kingdom of Saudi Arabia Ministry of Higher Education Al-Majma’ah University College of Education.
Loop Structures.
Designing and Debugging Batch and Interactive COBOL Programs
Any Questions?.
Chapter 3 The DATA DIVISION.
Scope and System Time/Date
File I/O in C Lecture 7 Narrator: Lecture 7: File I/O in C.
SCOPE TERMINATORS Definition:
3.5- The while Statement The while statement has the following syntax:
Chapter 6: Repetition Statements
Agenda Collating sequence / Sorting data
Using screens and adding two numbers - addda.cbl
Presentation transcript:

Statement Syntax1 THE SELECT STATEMENT Purpose: designates a file and points to its physical location Syntax Definition : SELECT file-name-1 ASSIGN TO implementor-name-1 [ORGANIZATION IS LINE SEQUENTIAL] Examples: SELECT INPUT-FILE ASSIGN TO “lab1.dat”. select input-file assign “lab1.dat”. SELECT input-file ASSIGN “lab1.dat” organization is line sequential. select INPUT-FILE assign to “lab1.dat” organization line sequential. Select abcdefg ASSIGN ‘lab1.dat’. For Your Information The ASSIGN clause information is machine dependent c:\cobol\prelabin.dat /usr/class/cis314/prelab/lab1.dat lab1.dat No period on Syntax Defn - Why?! Remember, the file-name-1 is the user-defined data name used on the FD associated with the physical file implementor-name-1 Starts in Area B 1 SELECT for every file your program accesses

Statement Syntax2 THE OPEN/CLOSE STATEMENT Syntax Definition : OPEN {INPUT file-name-1… OUTPUT file-name-2…} CLOSE file-name-3… Reminder: { } means one are required … means one or more can be listed Examples: open input in-file1 in-file2 open output out-one out-two open input input1 output output1 open input infile1 infile2 output outfile1 outfile2 outfile3 close in-one in-two close in-two in-one For Your Information The order of INPUT and OUTPUT does not matter (open) The OPEN statement always starts access to the file from the top Do not put the OPEN or CLOSE statements in a loop! Open Purpose: accesses the files and indicates which are input and which are output Close Purpose : releases the files and deactivates the devices

Statement Syntax3 THE MOVE STATEMENT Purpose: copies a piece of data/information into a memory location Syntax Definition : MOVE identifier-1|literal-1 TO identifier-2… Examples: MOVE 1 to A. move a to b. move b to c d. Move user-name-in to user-name-out. For Your Information For now, using the move statement is going to be simple. Be sure to move data from one similar picture clause to another. There are numerous rules about moving different types and lengths which we will get to later :o) Identifier-2 MUST be a memory location.

Statement Syntax4 THE WRITE STATEMENT Purpose: writes the information in the output buffer area (i.e. FD/01) to a file Syntax Definition : WRITE record-name-1 [FROM identifier-1] [ {AFTER|BEFORE} ADVANCING { PAGE | {integer-1|identifier-2} [LINE|LINES] ] } Reminder: { } means one are required [ ] means optional Examples: WRITE OUTPUT-REC. WRITE print-rec FROM COL-HEAD. WRITE rec-out AFTER 2. write outrec from page-head before num-blank-lines. For Your Information Notice that you WRITE from the output record “buffer” i.e. the 01 identifier name on the output FD. This is different from the READ (next slide) which uses the FD identifier name. The FROM identifier should be declared in the working-storage section. The equivalent to the WRITE/FROM is a MOVE then WRITE. For example, MOVE COL-HEAD TO PRINT-REC. WRITE PRINT-REC. WRITE only = auto advance 1 line then write (i.e. equiv to “after advancing 1 line”) You can ADVANCE page or # lines. BEFORE = write then advance AFTER = advance then write Before and after tells the printer when to advance the print head to the next line (will notice these control characters in your output file  ^M, etc)

Statement Syntax5 THE READ STATEMENT Purpose: fills the input record buffer area with one record of information from the input file Syntax Definition : READ file-name-1 [ INTO identifier-1 ] AT END statement-1… [ NOT AT END statement-2… ] [END-READ] Examples: READ input-file at end move “Y” to eof. Read input-file into ws-work-area at end perform 999-total-data. Read file-in-1 at end move “yes” to end-of file move “the end” to last-output close file-in END-READ For Your Information Notice that after the READ reserve word is the name of the FD, unlike the WRITE which uses the record-name (i.e. 01). The first period encountered will end the READ statement. The END-READ is called a scope terminator. Statement-1… will execute when the end of the file is reached Statement-2… will execute when you READ and the end of the file marker is not reached The INTO identifier should be declared in the working-storage section. The equivalent to the READ/INTO is a READ then MOVE. For example, READ input-file AT END… MOVE input-rec to ws-work-area.

Statement Syntax6 THE PERFORM STATEMENT Purpose: a sometimes loop, other times modular programming statement, that executes statement(s) sometimes based on a condition Syntax Definition : PERFORM [paragraph-name-1] [ { THROUGH|THRU} paragraph-name-2 ] UNTIL condition-1 [END-PERFORM] Examples: PERFORM 500-output-data. PERFORM 100-read-data until eof = “Y”. perform until no-more-recs = “yes” read… move… write… end-perform For Your Information TYPES: Single perform paragraph, Perform until, In-line perform (for both) Perform and perform until jump to the paragraph, execute the statements and come back to the perform statement before dropping to the next statement after the perform. If the UNTIL clause exists, the associated paragraph will execute if condition-1 is FALSE. If condition-1 is TRUE, the statements in the paragraph (or in line) will not be performed. *** This means that the condition will be checked first, then the paragraph executed If using the THRU option, the first paragraph must occur sequentially/physically prior to the second. All paragraphs in between are also executed Be careful of recursive-type (explain) and infinite loops  be sure the condition eventually goes TRUE!

Statement Syntax7 THE READ STATEMENT cont PRIMING READ OPEN WRITE page and column headers READ first record at end statement(s) PERFORM until end of file move… calculate… write… READ next record at end statement(s) End-Perform Close files Stop ??? Looks like in-line perform…??? READ AT END NOT AT END OPEN WRITE page and column headers PERFORM until end of file READ one record at end statement(s) not at end move… calculate… write… END-READ End-Perform ??? What happens if delete “not at end”???

Statement Syntax8 THE DISPLAY and ACCEPT OMITTED Purpose:  displays non-numeric literals and the values of memory locations to the terminal screen  pauses the execution of the program. Syntax Definition : DISPLAY non-numeric-literal-1|identifier-1… ACCEPT OMITTED Examples: display “input rec is “ input-rec. display a b c. display “a = “ a “b = “ b “c = “ c. display “in perform”. For Your Information These two statements can be added to a program at any point. The ACCEPT OMITTED statement pauses the execution of the program, allowing the programmer to check the screen for terminal screen output information (from the display statements). Pressing the space bar will continue the execution of the program…

Statement Syntax9 THE STOP RUN STATEMENT Purpose: terminates the execution of the program Syntax Definition : STOP RUN. Examples: Not applicable :o) For Your Information This statement should be the last logical statement that your program executes. Not to be confused with the last physical statement of your program.

Statement Syntax10 PUTTING IT ALL TOGETHER OPEN files WRITE page and column headers READ first record AT END… PERFORM loop until end of file detected MOVE input info to output buffer WRITE output buffer READ next record AT END… END-PERFORM CLOSE files STOP RUN GROUP problem solving PROBLEM: Choose a simple problem to solve. Fill in record layout forms, coding form, and printout form

Statement Syntax11 SCOPE TERMINATORS Definition : Delimits the end of a logical control construct or the end of a statement with clauses. DELIMITER = a character that begins or ends a unit of data DELIMIT = to fix or define the limits of Examples : END-READ END-PERFORM END-COMPUTE (etc…) period For Your Information FOR THE PROCEDURE DIVISION: A period will end every “open” logical control structure currently begun. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ READ INPUT-FD AT END MOVE “yes” TO EOF PERFORM 200-CALC UNTIL EOF = “yes” MOVE INPUT-REC TO OUTPUT-REC WRITE OUTPUT-REC READ INPUT-FD AT END MOVE “yes” TO EOF ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RULE OF THUMB: Always use END-STRUCTURE delimiters and you will only need a period at the end of every paragraph. Indentation has NOTHING to do with the logic of the program!!!

Statement Syntax12 ACCEPT DATE For Your Information The default format for the date is YYMMDD. If using the YYYYMMDD format option, the pic clause for todays- date is 9(8) and todays-yr is 9(4). Purpose:  accepts current date from the computer system Syntax Definition : ACCEPT identifier FROM DATE [YYYYMMDD]. Examples: 01 TODAYS-DATE PIC 9(6). or… 01 TODAYS-DATE. 05 TODAYS-YR PIC TODAYS-MM PIC TODAYS-DD PIC 99. ACCEPT TODAYS-DATE FROM DATE.

Statement Syntax13 ACCEPT TIME For Your Information The default format for the date is HHMMSSss. Notice that I ignored (i.e. truncated) the ss portion! The HH is MILITARY TIME! A picture clause of 9(8) could also have been used if you wanted to additional hundredths of seconds. There is a difference between moving a 9(8) to a 9(6) – decimal justifies and truncates to left- and a 9(8) to an alphanumeric group item i.e. x(6) – left justifies and truncates to right. Purpose:  accepts current time from the computer system Syntax Definition : ACCEPT identifier FROM TIME. Examples: 01 TODAYS-TIME PIC 9(6). or… 01 TODAYS-TIME. 05 TODAYS-HR PIC TODAYS-MIN PIC TODAYS-SEC PIC 99. ACCEPT TODAYS-TIME FROM TIME.