How to delete the last 3 entries in a sequential file

I have n entries in my serial file and I have to delete the last 3 entries in the serial file using the COBOL program. How can i do this?

+3
source share
3 answers

Yes, there are tricks, but none of them carry different Cobol compilers and different OS versions.

If you want to do this in a clean, fully portable Cobol style, read the entire file, buffering three records at a time, and write each record when it falls from the buffer. When you hit the end of the file, just stop writing buffered entries and you will omit the last three.

Some pseudo-cobbles may look like this:

   Perform Fill-Buffer
   Perform until End-Of-File
      Perform Write-Buffer
      Perform Fill-Buffer
   End-Perform
   .

Write-Buffer.
   Write OUTPUT-FILE 
    from The-Buffer (TOP-OF-BUFFER)
   End-Write
   .

Fill-Buffer.
* Do reads to fill a 3 position ring buffer
* and adjust TOP-OF-BUFFER to the current record...   
   .

, , SORT. Cobol.

+1

, , , ?

, . , , .

, , , 3 . 1 .

0

, dfssort, . . , . , .

//SORTT001 EXEC PGM=SORT                                                00100003
//SYSOUT   DD  SYSOUT=*                                                 00110003
//SORTIN   DD  DSN=INPUT.FILE,DISP=SHR                                  00160003
//SORTOUT  DD  DSN=OUTPUT.FILE,                                         00170003
//             SPACE=(2790,(5376,1075),RLSE),                           00180003
//             UNIT=SYSSF,                                              00190003
//             DCB=(RECFM=FB,LRECL=0080,BLKSIZE=0),                     00200003
//             DISP=(NEW,CATLG,DELETE)                                  00210003
//SYSIN    DD  *                                                        00220003
 SORT FIELDS=COPY,STOPAFT=100                                           00230003
/*       

"STOPAFT = 100" . , , .

0
source

Source: https://habr.com/ru/post/1790515/


All Articles