?
Solved

COBOL question: How to delete a record from a file?

Posted on 2003-03-12
5
Medium Priority
?
329 Views
Last Modified: 2013-11-25
Here is the program. I want to delete the record if the first CHAR = "D". How can I write the code?

************************************************

IDENTIFICATION DIVISION.
 PROGRAM-ID.      EXAMPLE.
 AUTHOR           My Name.

 ENVIRONMENT DIVISION.
 INPUT-OUTPUT SECTION.
 FILE-CONTROL.
     SELECT FD-INPUT
              ASSIGN TO "test.txt"
              ACCESS SEQUENTIAL
              ORGANIZATION LINE SEQUENTIAL.

 DATA DIVISION.
 FILE SECTION.
 FD FD-INPUT.
 01 PRINT-REC         PIC X(60).

 WORKING-STORAGE SECTION.
 01 EOF-FLAG          PIC 9(1).
    88 END-OF-IN-FILE VALUE 1.

 PROCEDURE DIVISION.
 MAIN-PARAGRAPH.
    OPEN INPUT FD-INPUT

    PERFORM WITH TEST AFTER UNTIL END-OF-IN-FILE
       READ FD-INPUT
          AT END SET END-OF-IN-FILE TO TRUE
          NOT AT END
              IF PRINT-REC (1:1) = "D"
                 PERFORM PRINT-DETAILS
              END-IF
       END-READ
    END-PERFORM

    CLOSE FD-INPUT

    STOP RUN.

 PRINT-DETAILS SECTION.
* print out the record first
    DISPLAY PRINT-REC
* Then delete this record
    DELETE ??????????(what should I write here?)
    CONTINUE.
 
0
Comment
Question by:chenwei
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:LordWabbit
ID: 8125901
The file is sequential so you cant simply delete a record out of it.  if you had create a vsam file it would be another matter.  obviously you are running this code on a pc so we won't go into jcl and all the other lovely ways of working around the limitations of sequential files on a mainframe.  what you can do is create another file (output) and then read the input and for each record write out to the output file.  if the record is to be deleted do not write it and move on to the next record.  
0
 

Author Comment

by:chenwei
ID: 8129277
Thanks.

If I define the input file as a relartive file, etc. a strcutured file. Is it possible to delete a record?

***********************************************
 FILE-CONTROL.
*-------------*
      SELECT FD-EINGABE
             ASSIGN           TO "#DYNAMIC"
             ORGANIZATION     RELATIVE
             ACCESS           SEQUENTIAL
             FILE STATUS      IS WS-INPUT-FILE-STAT.
0
 

Author Comment

by:chenwei
ID: 8129432
Besides, I am working on TANDEM computer.
0
 
LVL 11

Accepted Solution

by:
LordWabbit earned 200 total points
ID: 8134125
You cant 'delete' a record in a relative file structure otherwise it looses it's count, all you can do is blank it out.  To turn the file into a vsam file you will have to write a program to read the sequential file and then output it to a vsam file so that it can build the index.  

Reading vsam files sequentially is slower then reading a sequential file sequentially.  also whatever created the sequential file would have to be changed to now use the vsam file.

To be honest I think your best bet would be to simply create a second output file and write all the records that don't begin with a D to that file, thereby 'deleting' it by omission.
0
 

Author Comment

by:chenwei
ID: 8134406
Really a good help. Thanks!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is about my first experience with programming Arduino.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
Introduction to Processes
Suggested Courses

800 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question