I have PS flat file with 14 records. I want to read from
4th to 9th record and want to write those 6 records (4th
record to 9th record) to another PS file (output file).
there is no key defined in the input file. I just want read
a certain Consecutive records. can any one please give me
the procedure division Coding for this. I have coded the
below coding but the READ-PARA is performing only 1 time
even though I have 14 records in my input file (i.e FILE-1):

PROCEDURE DIVISION.
A000-SECTION.
MOVE 0 TO I.
OPEN INPUT FILE-1.
IF CHECK-KEY1 > 0
DISPLAY "OPEN ERROR FOR FILE-1, CODE IS:" CHECK-KEY1
END-IF.
OPEN EXTEND NEWFILE-1
IF CHECK-KEY3 > 0
DISPLAY "OPEN ERROR FOR NEWFILE-1 COD IS" CHECK-KEY3
END-IF.
PERFORM READ-PARA THRU EXIT-PARA UNTIL EOF-REC = 'YES'.
DISPLAY " FINALLY OUT OF LOOP"
CLOSE FILE-1
CLOSE NEWFILE-1
STOP RUN.
READ-PARA.
ADD 1 TO I
READ FILE-1
AT END MOVE 'YES' TO EOF-REC
IF I > 3 AND < 10
PERFORM WRITE-PARA
ELSE
DISPLAY "NOT IN RANGE"
END-IF.
EXIT-PARA.
EXIT.
WRITE-PARA.
WRITE NEW-REC FROM FILE1-REC.


Answer Posted / satishk

HI FRIENDS,
AS U MENTIONED THAT, IT WAS A PS-FILE,SO IN UR COBOL
PROGRAM, U HAVE DECLARED AN KEY-VARIABLE IN INPUT-PS-FILE.
WELL, SO, YOUR WAY OF APPROACH WAS WRONG.
HERE IS THE RIGHT CONCEPT:
In a PS-FILE, you cannot use any key-variable. only record-
number if you have defined for a particular record can be
moved, so that,a particular record can be moved with its
record-number.
In order to move your choice of records to be moved to any
other file, try to make use of VSAM-Files, which enables
you to define your own set of records to be moved from one
dataset to other, by using either IDCAMS utility, SKIP AND
COUNT in your JCL, (OR) making your cobol code using the
key-variables set to your fixed number of choice of record-
index between the range of your choice of records.

well, these are the only possibilities to move records from
one file to other file.

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How do you reference the following file formats from cobol programs?

691


What guidelines should be followed to write a structured cobol prgm?

663


IDENTIFICATION DIVISION. PROGRAM-ID. UPDT. AUTHOR.anbu. DATE-WRITTEN. AUG 13. ENVIRONMENT DIVISION. INPUT-OUTPUT SECTION. FILE-CONTROL. SELECT CMSTR ASSIGN TO CINP1 ORGANIZATION IS INDEXED ACCESS IS SEQUENTIAL RECORD KEY CM2-KEY FILE STATUS IS WS-CMSTR-FST. SELECT CTAB ASSIGN TO CINP2 ORGANIZATION IS ACCESS IS SEQUENTIAL RECORD KEY VSAM-WHSE- KEY FILE STATUS IS WS-CTAB- FST. DATA DIVISION. FILE SECTION. FD CMSTR. COPY RXCYFC20. FD CTAB. COPY AITYWHSE. ************************************************************ ****** *** WORKING STORAGE VARIABLES *** ************************************************************ ****** WORKING-STORAGE SECTION. 01 WS- VARIABLES. 05 WS-EB PIC X(02) VALUE ZEROES. 05 WS-DIV PIC 9(03) VALUE ZEROES. 05 WS-CMF-RECS-REWRITTEN PIC 9(01) VALUE ZERO. *** FILE STATUS VARIABLES *** 05 WS- FILESTATUS. 10 WS-CMSTR-FST PIC 9(02) VALUE ZEROES. 10 WS-CTAB-FST PIC 9(02) VALUE ZEROES. *** END OF FILE VARIABLES *** 05 WS-CMSTR-EOF PIC X(01) VALUE 'N'. 88 WS-CMSTR-EOF-YES VALUE 'Y'. 88 WS-CMSTR-EOF-NO VALUE 'N'. 05 WS-CTAB-EOF PIC X(01) VALUE 'N'. 88 WS-CTAB-EOF-YES VALUE 'Y'. 88 WS-CTAB-EOF-NO VALUE 'N'. **** ERROR VARIABLES **** 05 WC-ABEND-900 PIC 9(03) VALUE 900. 05 WE-ERR-CODE PIC 9(02) VALUE ZEROES. 05 WE-ABEND-CODE PIC 9(03) VALUE ZEROES. ************************************************************ **** ********* PROCEDURE DIVISON ********** ************************************************************ **** PROCEDURE DIVISION. 0000- BEGIN. PERFORM 1000-INITIALISE THRU 1000- EXIT. PERFORM 2000-PROCESS THRU 2000- EXIT UNTIL WS-CMSTR-EOF- YES. DISPLAY 'WS-CMF-RECS-REWRITTEN :' WS-CMF-RECS- REWRITTEN. PERFORM 5000-CLOSE THRU 5000- EXIT. GOBACK. 0000- EXIT. EXIT. 1000- INITIALISE. OPEN I-O CMSTR. EVALUATE WS-CMSTR- FST WHEN 00 WHEN 97 CONTINUE WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CMSTR-FST MOVE WS-CMSTR-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE. OPEN INPUT CTAB. EVALUATE WS-CTAB-FST WHEN 00 WHEN 97 CONTINUE WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CTAB-FST MOVE WS-CTAB-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE. 1000-EXIT. EXIT. 2000-PROCESS. READ CMSTR. EVALUATE WS-CMSTR-FST WHEN 00 CONTINUE WHEN 10 SET WS-CMSTR-EOF-YES TO TRUE GO TO 2000-EXIT WHEN OTHER DISPLAY 'ERROR IN READING INPUT FILE: ' DISPLAY WS-CMSTR-FST MOVE WS-CMSTR-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END-EVALUATE IF CM2-RECORD-TYPE-SOLD-TO MOVE CM2-ENTERING-BRANCH TO WS-EB PERFORM 3000-READ THRU 3000-EXIT UNTIL WS-CTAB-EOF-YES END-IF. 2000-EXIT. EXIT. 3000-READ. MOVE WS-EB TO VSAM-WHSE-CD. MOVE 'WHSE' TO VSAM-WHSE-ID. READ CTAB. EVALUATE WS-CTAB-FST WHEN 00 MOVE WHSE-DIV-CODE TO WS-DIV PERFORM 4000-REWRITE-CMF THRU 4000-EXIT WHEN 10 SET WS-CTAB-EOF-YES TO TRUE GO TO 3000-EXIT WHEN OTHER DISPLAY 'ERROR IN READING TABLE FILE: ' DISPLAY WS-CTAB-FST MOVE WS-CTAB-FST TO WE-ERR-CODE PERFORM 9999-ABEND-PARA THRU 9999-EXIT END- EVALUATE. 3000- EXIT. EXIT. 4000-REWRITE- CMF. IF WS-DIV = 250 OR 252 MOVE 'F' TO CM2-FREIGHT- TYPE MOVE 1 TO CM2-FREIGHT-THRESHOLD- AMT ADD +1 TO WS-CMF-RECS- REWRITTEN REWRITE CM2-SOLD-TO- RECORD DISPLAY 'RECORD UPDATED' END- IF. * EVALUATE WS-CMSTR- FST * WHEN 00 * CONTINUE * WHEN OTHER * DISPLAY 'FILE NOT UPDATED' * DISPLAY WS-CMSTR- FST * MOVE WS-CMSTR-FST TO WE-ERR-CODE * PERFORM 9999-ABEND-PARA THRU 9999-EXIT * GO TO 4000-EXIT * END-EVALUATE. 4000-EXIT. EXIT. 5000-CLOSE. CLOSE CMSTR CTAB. 5000-EXIT. EXIT. 9999-ABEND-PARA. COMPUTE WE-ABEND-CODE = WC-ABEND-900 + WE-ERR-CODE CALL 'ILBOABN0' USING WE-ABEND-CODE GO TO 5000-CLOSE. 9999-EXIT. EXIT. 5000-CLOSE. CLOSE CMSTR CTAB. 5000-EXIT. EXIT. 9999-ABEND-PARA. COMPUTE WE-ABEND-CODE = WC-ABEND-900 + WE-ERR-CODE CALL 'ILBOABN0' USING WE-ABEND-CODE GO TO 5000-CLOSE. 9999-EXIT. EXIT. //this program is giving maxcc=0, but not updating..

3333


When is inspect verb is used in cobol?

670


How to get the last record in vsam file in cluster? And how can you get the ksds file records into your cobol program?

639






What are the various section in data division and briefly explain them.

688


What is Pic 9v99 Indicates in COBOL?

716


A table has two indexes defined. Which one will be used by the SEARCH?

750


What happens when we move a comp-3 field to an edited (say z (9). Zz-)?

765


How to get the last record in vsam file in cluster? And how can you get the kids file records into your cobol program?

728


How arrays can be defined in COBOL?

658


What are various search techniques in cobol? Explain.

640


how can we apply for HSBC exam(Mainframe) in India??? i went to their site and was told to submit my CV ,. etc..( totally confusing...)

1916


What are the different rules to perform a Search?

613


How do we get current date from system with century in COBOL?

793