Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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.


Answers were Sorted based on User's Feedback



I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / vinayagamoorthy

Hi ,

You don't need a oobol Program itself for this instead you
could use IDCAMS PROGRAM and REPRO Coomand with the control
parameters like SKIP and COUNT to achieve the above task.

//J1 JOB NOTFIFY=TCHN003
//S1 EXEC PGM=IDCAMS
//F1 DD DSN=FILE1,DISP=SHR ---> INP FILE
//F2 DD DSN=FILE2,DISP=SHR ---> OUT FILE
//SYSIN DD *
REPRO INFILE(F1) OUTFILE(F2) -
SKIP(3) -
COUNT(6)
/*
//

Is This Answer Correct ?    23 Yes 2 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / swetha

could nt we use just a sort step?

//SPLITFLS EXEC PGM=SORT
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SORTIN DD DSN=FILE1...,DISP=SHR
//SORTOF02 DD DSN=OUTPUTFILE2..............,
// DISP=(NEW,CATLG,DELETE),UNIT=SYSDA,
// SPACE=(CYL,(1,1),RLSE),
// RECFM=FB,LRECL=20
//SYSIN DD *
sort fields=copy
outfil files=file2,startrec=4,endrec=9
/*

please correct me if i missed a point.

Is This Answer Correct ?    13 Yes 1 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / vikas

Hi ,,,, i think here you need to include one more line i.e.
NOT AT END in READ statement.
Beacuse it is taking all loops under READ as part of AT END
condition.

like...

READ FILE-1
AT END
MOVE 'YES' TO EOF-REC
NOT AT END
IF I > 3 AND < 10
PERFORM WRITE-PARA
ELSE
DISPLAY "NOT IN RANGE"
END-IF
END-READ.


try this ....

Is This Answer Correct ?    5 Yes 1 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / praveen bejjanki

In order to achieve this, simply we can use sort utility as
shown below.
//stepname exec pgm=sort
//sortin dd dsn=inputfile,disp=-do-
//sortout dd dsn=outputfile,disp=-do-
//sysprint dd sysout=*
//sysin dd *
sort fields=copy
skiprec=3
stopaft=6
/*
I hope this will answer your question, if it is related to
JCL

Is This Answer Correct ?    4 Yes 1 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / mike

you are missing a period after AT END MOVE 'YES' TO EOF-REC

The if statement IF I > 3 and < 10 is considered part of
the AT END condition.

Is This Answer Correct ?    4 Yes 4 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / 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

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / guest

at the end of the Read stmt u need to put end-if or period.
juz try it after mentioning any one of the above.

Is This Answer Correct ?    0 Yes 1 No

I have PS flat file with 14 records. I want to read from 4th to 9th record and want to write those..

Answer / gowd

AS YOU ARE USING NORMAL PS FILE U CANT ACCESS THE RECORD
FROM THE MIDDLE. THE SEQUENTIAL FILE PROCESS IN SEQUENCE
ORDER FROM FIRST RECORD ONWARDS. U MENTIONED A KEY IN THE
PROGRAM IT DOES NOT ALLOW ANY KEY IN THE SEQUENTIAL FILE.
THROUGH COBOL U CANT ACCESS THIS. FROM JCL U CAN GET IT AS
ONE OF OUR FRIEND CODED THROUGH THE "REPRO".

Is This Answer Correct ?    0 Yes 1 No

Post New Answer

More COBOL Interview Questions

ID DIVISION. PROGRAM-ID. PLO. DATA DIVISION. WORKING-STORAGE SECTION. 01 VAR1 PIC 9(2). 01 VAR2 PIC X(2). PROCEDURE DIVISION. ACCEPT VAR2. MOVE VAR2 TO VAR1. STOP RUN. if i give 'PI' in var2 then what will b output of progr. any abend?????

6 Answers   TCS,


I HAVE FOLLOWING DECLARATION. 02. A PIC X(10) VALUE 'XXXXXXXXXX'. 02. B REDEFINES A. 05. C PIC X(3). 05. D PIC X(3). 05. E PIC 9(3). IN MY PROG, I HAVE MOVE 1 TO E. DISPLAY A. WHAT WILL BE DISPLAYED AS A RESULT OF THIS? PLEASE EXPLAIN THE ANSWER. THANKS.

7 Answers   Amdocs,


what is qualification on occurs clause?

2 Answers  


What do you understand by passing by reference and passing by content?

1 Answers  


Can printer files (having 133 characters) be of variable length?

3 Answers  


What is an in-line perform ?

4 Answers   Accenture,


what is jcl approach for programming?

4 Answers   IBM,


how will u find out 3rd week's 2nd day using occurs ?

3 Answers   L&T,


How do you do in-line PERFORM?

4 Answers   Accenture,


Write some characteristics of cobol as means of business language.

0 Answers  


What is the difference between a binary search and a sequential search? What are the pertinent cobol commands?

0 Answers  


how we sort two input files based on a common column and giving one o/p file please send me the coding logic?

0 Answers   Valtech,


Categories