Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

Cobol
Introduction to Cobol Programming
Cobol Basics
Cobol Divisions
The Identification Division
The Environment Division
Data Division
Procedure Division
Defining Data Part 1
Number Formats
Moving and Editing Data
Initializing Data
Defining Data Part 2
Printing and Writing Data
Tables
Boolean Data
HIGH-VALUES and LOW-VALUES
Commands and Logics
Accept and Display
Move
Perform
Cobol IF... THEN...ELSE...
Conditions
Cobol Evaluate
Cobol Strings
Cobol Write
Scope Terminators
File Handling
Reading and Writing
REWRITE, DELETE, and EXTEND
SORT and MERGE
Input and Output Procedure
FILE STATUS (error handling)
Debugging COBOL Code

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
CSS 1.0
CSS 2.0
HLML
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Reading and Writing


Previoushome Next






Reading and Writing

In order to either read, alter or create a new file, we must first open it (even if it doesn't even exist yet). In doing so, a open mode must be defined.

A D V E R T I S E M E N T
To simply read data from an existing file it would be opened in INPUT mode. In this mode, the file is read-only and cannot be altered in any way.
If writing to new file, i.e. creating one (or overwriting an existing file so be careful) the new file would be opened in OUTPUT mode. You cannot read data from a file opened in OUTPUT mode.
EXTEND mode allows for records to be added to the end of an existing file.
I-O mode is for input and output access to the file, such as when you wish to update a record, or delete a record.

When a file is no longer required, the file needs to be closed again (using CLOSE). You can open and close a file as often as you like during a program run, although bear in mind that each time you open a file the computer will read from the first record onwards (in INPUT and I-O mode) or will overwrite in OUTPUT mode.

 

OPEN {INPUT or OUTPUT or I-O or EXTEND} {filename-1}...
           {INPUT or OUTPUT or I-O or EXTEND} {filename-2}...


e.g.
 
     OPEN INPUT DATA-1-FILE DATA-2-FILE
          OUTPUT NEW-DATA-FILE
		
     CLOSE DATA-1-FILE DATA-2-FILE NEW-DATA-FILE

  READ

The READ statement will read the data from a file, taking precisely the data that is defined in the file descriptor (FD) in the data division (file section) (see The Four Divisions section).
The format is:
 

READ {FD filename}
      AT END {statements}
      NOT AT END {statements}
END-READ


Since a file would likely contain more than one record, the READ statement is often contained within a PERFORM loop:
 

 

IDENTIFICATION DIVISION.
PROGRAM-ID. READ-EXAMPLE.
AUTHOR ZINGMATTER.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
ASSIGN IN-FILE TO 'A:CUSTOMER.DAT'
ORGANIZATION IS LINE SEQUENTIAL.
ASSIGN PRINT-FILE TO PRINTER.
: DATA DIVISION.
FILE SECTION.
FD IN-FILE.
01 CUSTOMER-DETAILS.
03 CUS-NAME PIC X(20).
03 CUS-NUM PIC 9(6).
FD PRINT-FILE.
01 PRINT-REC PIC X(60).
WORKING-STORAGE SECTION.
01 EOF-FLAG PIC X.
88 END-OF-IN-FILE VALUE 'Y'.
01 P-CUS-DETAILS
03 PIC X(5) VALUE SPACES.
03 P-NAME PIC X(25).
03 P-NUM PIC Z(5)9.
: PROCEDURE DIVISION.
MAIN-PARAGRAPH.
OPEN INPUT IN-FILE
*"Prime" read
READ IN-FILE
AT END MOVE 'Y' TO EOF-FLAG
NOT AT END PERFORM PRINT-DETAILS
END-READ
*Main reading loop
PERFORM UNTIL END-OF-IN-FILE
READ IN-FILE
AT END MOVE 'Y' TO EOF-FLAG
NOT AT END PERFORM PRINT-DETAILS
END-READ
END-PERFORM
STOP RUN.
PRINT-DETAILS.
MOVE CUS-NAME TO P-NAME
MOVE CUS-NUM TO P-NUM
WRITE PRINT-REC FROM P-CUS-DETAILS AFTER 1 LINE.
 
  • A record containing a customer name (CUS-NAME) and the customer number (CUS-NUM) are read from a file customer.dat assign to IN-FILE.
  • The file is opened for INPUT (i.e. read-only).
  • The "prime read" refered to in the comment is the initial read of IN-FILE that allows for the possibility that the file contains no records.
  • The AT END clause tests for the end of file condition. When true, a series of statements can then be executed. Likewise, the NOT AT END clause allows for a series of statements to be executed when this condition is true. In the above example, when the file contains no more records (i.e. is at the end of the file) 'Y' is moved to EOF-FLAG, thereby making the condition name condition (END-OF-IN-FILE) true. When not at the end of the file, a record is read into memory and the paragraph PRINT-DETAILS is executed.
  • The statements between PERFORM UNTIL... and END-PERFORM are executed until the END-OF-IN-FILE condition is true (when the AT END of the read statement is true).

If you want to place data from a record into an item in WORKING-STORAGE (in addition to the memory space already allocated to the same data defined in the data division - so not much call for it), then use READ ... INTO. i.e:
 

    READ IN-FILE INTO W-RECORD-IN



Be the first one to comment on this page.




  Cobol eBooks
More Links » »
 
 Cobol FAQs
More Links » »
 
 Cobol Interview Questions
More Links » »
 
 Cobol Articles
More Links » »
 
 Cobol News
More Links » »
 
 Cobol Jobs
More Links » »

Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Previoushome Next

Keywords: Cobol Basics, cobol programming language, cobol language programming tutorial pdf, history of cobol programming, basic cobol programming, syntax use in cobol programming, cobol programming software download, cobol programming code, learn cobol programming, cobol performs syntax, cobol 2008

HTML Quizzes
HTML Quiz
XHTML Quiz
CSS Quiz
TCP/IP Quiz
CSS 1.0 Quiz
CSS 2.0 Quiz
HLML Quiz
XML Quizzes
XML Quiz
XSL Quiz
XSLT Quiz
DTD Quiz
Schema Quiz
XForms Quiz
XSL-FO Quiz
XML DOM Quiz
XLink Quiz
XQuery Quiz
XPath Quiz
XPointer Quiz
RDF Quiz
SOAP Quiz
WSDL Quiz
RSS Quiz
WAP Quiz
Web Services Quiz
Browser Scripting Quizzes
JavaScript Quiz
VBScript Quiz
DHTML Quiz
HTML DOM Quiz
WMLScript Quiz
E4X Quiz
Server Scripting Quizzes
ASP Quiz
PERL Quiz
SQL Quiz
ADO Quiz
CVS Quiz
Python Quiz
Apple Script Quiz
PL/SQL Quiz
SQL Server Quiz
PHP Quiz
.NET (dotnet) Quizzes
Microsoft.Net Quiz
ASP.Net Quiz
.Net Mobile Quiz
C# : C Sharp Quiz
ADO.NET Quiz
VB.NET Quiz
VC++ Quiz
Multimedia Quizzes
SVG Quiz
Flash Quiz
Media Quiz
SMIL Quiz
Photoshop Quiz
Gimp Quiz
Matlab Quiz
Gnuplot Programming Quiz
GIF Animation Quiz
Scientific Visualization Quiz
Graphics Quiz
Web Building Quizzes
Web Browsers Quiz
Web Hosting Quiz
W3C Quiz
Web Building Quiz
Web Quality Quiz
Web Semantic Quiz
Web Careers Quiz
Weblogic Quiz
SEO Quiz
Web Site Hosting Quiz
Domain Name Quiz
Java Quizzes
Java Quiz
JSP Quiz
Servlets Quiz
Struts Quiz
EJB Quiz
JMS Quiz
JMX Quiz
Eclipse Quiz
J2ME Quiz
JBOSS Quiz
Programming Langauges Quizzes
C Quiz
C++ Quiz
Visual Basic Quiz
Data Structures Using C Quiz
Cobol Quiz
Assembly Language Quiz
Mainframe Quiz
Forth Programming Quiz
Lisp Programming Quiz
Pascal Quiz
Delphi Quiz
Fortran Quiz
OOPs Quiz
Data Warehousing Quiz
CGI Programming Quiz
Emacs Quiz
Gnome Quiz
ILU Quiz
Soft Skills Quizzes
Communication Skills Quiz
Time Management Quiz
Project Management Quiz
Team Work Quiz
Leadership Skills Quiz
Corporate Communication Quiz
Negotiation Skills Quiz
Database Quizzes
Oracle Quiz
MySQL Quiz
Operating System Quizzes
BSD Quiz
Symbian Quiz
Unix Quiz
Internet Quiz
IP-Masquerading Quiz
IPC Quiz
MIDI Quiz
Software Testing Quizzes
Testing Quiz
Firewalls Quiz
SAP Module Quizzes
ERP Quiz
ABAP Quiz
Business Warehousing Quiz
SAP Basis Quiz
Material Management Quiz
Sales & Distribution Quiz
Human Resource Quiz
Netweaver Quiz
Customer Relationship Management Quiz
Production and Planning Quiz
Networking Programming Quizzes
Corba Quiz
Networking Quiz
Microsoft Office Quizzes
Microsoft Word Quiz
Microsoft Outlook Quiz
Microsoft PowerPoint Quiz
Microsoft Publisher Quiz
Microsoft Excel Quiz
Microsoft Front Page Quiz
Microsoft InfoPath Quiz
Microsoft Access Quiz
Accounting Quizzes
Financial Accounting Quiz
Managerial Accounting Quiz
Testimonials | Contact Us | Link to Us | Site Map
Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
Copyright ? 2003-2021 Vyom Technosoft Pvt. Ltd., All Rights Reserved.