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


Rewrite, Delete, and Extend


Previoushome Next






REWRITE, DELETE, and EXTEND

In order to ammend a record in a file, such as to update data (see League Table Program in sample programs section), to delete a record altogther, or to add a record to the end of a file, you can use REWRITE, DELETE or EXTEND, respectively.

A D V E R T I S E M E N T
However, to use REWRITE or DELETE you must open the file using I-O mode. Also, DELETE can only be used on files with RELATIVE or INDEXED organization (see example below).

RELATIVE and INDEXED files are discussed in the following section

The format of the DELETE statement is:

DELETE filename
ON INVALID KEY
{statements}
NOT ON INVALID KEY
{statements}
END-DELETE

ON INVALID KEY means the record was not found, so you might want to display an error message
e.g. DISPLAY 'RECORD NOT FOUND'

To REWRITE you can refer to the level 01 name to change the record with the ammended field:

FD IN-FILE
01 RECORD-IN.
 03 IN-NAME PIC X(20).
 03 IN-ADDRESS PIC X(60).

PROCEDURE DIVISION.
MAIN-PARAGRAPH.
 :

 OPEN I-O IN-FILE
 :

 READ IN-FILE

 IF IN-NAME = 'BILLY NOMATES' THEN
 MOVE 'JIMMY MOREPALS' TO IN-NAME
 REWRITE RECORD-IN
 ELSE
 DISPLAY IN-NAME
 END-IF
 :

To EXTEND you must open the file in EXTEND mode:

 OPEN EXTEND IN-FILE
 :

 DISPLAY 'Type in new name'
 ACCEPT NEW-NAME
MOVE NEW-NAME TO IN-NAME
 EXTEND IN-FILE

 DISPLAY 'Type in new address'
 ACCEPT NEW-ADDRESS
 MOVE NEW-ADDRESS TO IN-ADDRESS
 EXTEND IN-FILE
 :
Here is a sample program that deletes a record from an INDEXED file using the DELETE statement, followed by deletion of a record that does not use the DELETE statement but writes the whole file (less the record to be deleted) to a temporary file. The program asks for a six digit code that identifies the record to be removed from the file. If you want to try this program then you'll need to create a couple of test files: TESTDATA1.DAT and TESTDATA2.TXT.

TESTDATA1.DAT needs to be an indexed file. To create this you'll need to compile and run the Create INDEXED file program and Read INDEXED file program (both in the Sample Code section).

TESTDATA2.TXT should be LINE SEQUENTIAL and of the form:

CODE--SOME ENTRY OF 43 CHARACTERS
123456abc----------**********----------**********
:
:

000010 IDENTIFICATION DIVISION.
000020 PROGRAM-ID. DELETION-EXAMPLE.
000030 AUTHOR. TIM-R-P-BROWN.
000040* Program that deletes a record from a
000050* file where the specified record ID code is entered
000060* by the user. 2 differing methods are used.
000070
000080 ENVIRONMENT DIVISION.
000090
000100 INPUT-OUTPUT SECTION.
000110 FILE-CONTROL.
000120 000130 SELECT IN-FILE-1 ASSIGN TO 'TESTDATA1.DAT'
000140 ORGANIZATION IS INDEXED
000150 ACCESS MODE IS DYNAMIC
000160 RECORD KEY IS RECORD-CODE-1.
000170 SELECT IN-FILE-2 ASSIGN TO 'TESTDATA2.TXT'
000180 ORGANIZATION IS LINE SEQUENTIAL.
000190 SELECT TEMP-FILE ASSIGN TO 'TEMP.TXT'
000200 ORGANIZATION IS LINE SEQUENTIAL.
000210 000220 DATA DIVISION.
000230 FILE SECTION.
000240 000250 FD IN-FILE-1.
000260 01 RECORD-1.
000270 03 RECORD-CODE-1 PIC X(6).
000280 03 RECORD-DETAILS-1 PIC X(43).
000290 000300 FD IN-FILE-2.
000310 01 RECORD-2.
000320 03 RECORD-CODE-2 PIC X(6).
000330 03 RECORD-DETAILS-2 PIC X(43).
000340 000350 FD TEMP-FILE.
000360 01 TEMP-RECORD.
000370 03 TEMP-CODE PIC X(6).
000380 03 TEMP-DETAILS PIC X(43).
000390 000400
000410 000420 WORKING-STORAGE SECTION.
000430 000440 01 END-OF-FILE-FLAG PIC X VALUE 'N'.
000450 88 EOF VALUE 'Y'.
000460 000470 01 REC-DELETE-FLAG PIC X VALUE 'N'.
000480 88 RECORD-DELETED VALUE 'Y'.
000490
000500 01 DEL-CODE PIC X(6) VALUE SPACES.
000510 000520
000530
000540 PROCEDURE DIVISION.
000550 000560 MAIN-PARAGRAPH.
000570 000580 PERFORM FIRST-METHOD
000590 MOVE 'Y' TO END-OF-FILE-FLAG
000600 PERFORM SECOND-METHOD
000610 STOP RUN.
000620 000630***********************************************************
000640 000650 FIRST-METHOD.
000660* Paragraph that uses the DELETE to remove a record
000670 000680 DISPLAY 'Enter 6 digit code of record to be deleted'
000690 ACCEPT RECORD-CODE-1
000700 OPEN I-O IN-FILE-1
000710 000720 000730 DELETE IN-FILE-1
000740 INVALID KEY DISPLAY 'RECORD NOT FOUND'
000750
000760 END-DELETE
000770
000780
000790 CLOSE IN-FILE-1.
000800 000810***********************************************************
000820 000830 SECOND-METHOD.
000840* Paragraph that writes to a temporary file without
000850* including the record to be deleted
000860 000870 DISPLAY 'Enter 6 digit code of record to be deleted'
000880 ACCEPT DEL-CODE
000890 OPEN INPUT IN-FILE-2
000900 OUTPUT TEMP-FILE
000910 000920 MOVE 'N' TO REC-DELETE-FLAG
000930 MOVE 'N' TO END-OF-FILE-FLAG
000940 000950*----first write all records (except the selected one) to
000960*----the temporary file
000970 PERFORM UNTIL EOF
000980 READ IN-FILE-2
000990 AT END SET EOF TO TRUE
001000 NOT AT END
001010 IF RECORD-CODE-2 = DEL-CODE THEN
001020 SET RECORD-DELETED TO TRUE
001030 ELSE
001040 WRITE TEMP-RECORD FROM RECORD-2
001050 END-IF
001060 END-READ
001070 END-PERFORM
001080 001090 001100 001110 IF NOT RECORD-DELETED THEN
001120 DISPLAY 'Record not found'
001130 END-IF
001140 001150 CLOSE IN-FILE-2 TEMP-FILE
001160 001170 MOVE 'N' TO END-OF-FILE-FLAG
001180 001190*----now read all records from temp-file to a new 'TESTDATA-2.TXT'
001200*----This is virtually the same as just renaming the temporary file
001210*----when you think about it, just done the COBOL way!
001220 OPEN INPUT TEMP-FILE
001230 OUTPUT IN-FILE-2
001240*---------the original 'TESTDATA-2.TXT' will be overwritten-----*
001250 001260 PERFORM UNTIL EOF
001270 READ TEMP-FILE
001280 AT END SET EOF TO TRUE
001290 NOT AT END
001300 WRITE RECORD-2 FROM TEMP-RECORD
001310 END-READ
001320 END-PERFORM
001330 001340 CLOSE TEMP-FILE IN-FILE-2.
001350 001360***********************************************************
001370***********************************************************


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-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.