Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 370
  • Last Modified:

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

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
chenwei
Asked:
chenwei
  • 3
  • 2
1 Solution
 
LordWabbitCommented:
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
 
chenweiAuthor Commented:
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
 
chenweiAuthor Commented:
Besides, I am working on TANDEM computer.
0
 
LordWabbitCommented:
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
 
chenweiAuthor Commented:
Really a good help. Thanks!
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now