Doubt in writing multiple records to VSAM.



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Doubt in writing multiple records to VSAM.

Postby Viswanathchandru » Thu Mar 10, 2011 9:33 pm

Hi folks,
I have a piece of COBOL code which tend to write records from a flat file to a KSDS cluster. But unfortunately it writes only one record and other records are not written. I tried with File status it show 00 for both read and write. I'm attaching the code i have written. Please anyone help me where do i go wrong. Thanks a lot for your time. Apologies if m wrong.
000100        IDENTIFICATION DIVISION.         
000200        PROGRAM-ID. PGM.               
000300        ENVIRONMENT DIVISION.             
000400        INPUT-OUTPUT SECTION.             
000500        FILE-CONTROL.                     
000600            SELECT INFILE ASSIGN TO DD1   
000700            ORGANIZATION IS SEQUENTIAL   
000800            FILE STATUS IS FS1.           
000900            SELECT OUTFILE ASSIGN TO DD2 
001000            ORGANIZATION IS INDEXED       
001100            RECORD KEY IS SNO1           
001200            ACCESS IS SEQUENTIAL         
001300            FILE STATUS IS FS2.           
001400        DATA DIVISION.                   
001500        FILE SECTION.                       
001600        FD INFILE.                         
001700        01 STUD.                           
001800            02 SNO PIC 9(4).               
001900            02 FILLER PIC X(5).             
002000            02 SNAME PIC X(20).             
002100            02 FILLER PIC X(5).             
002200            02 SADDRE PIC X(30).           
002300            02 FILLER PIC X(5).             
002400            02 FILLER PIC X(11).           
002500        FD OUTFILE.                         
002600        01 STUD1.                           
002700            02 SNO1 PIC 9(4).               
002800            02 FILLER PIC X(5).             
002900            02 SNAME1 PIC X(20).           
003000            02 FILLER PIC X(5).             
003100            02 SADDRE1 PIC X(30).           
003200            02 FILLER PIC X(5).                   
003300            02 FILLER PIC X(11).                 
003400        WORKING-STORAGE SECTION.                 
003500        77 FS1 PIC 9(2).                         
003600        77 FS2 PIC 9(2).                         
003610        77 EOF PIC X(1) VALUE 'N'.               
003800        PROCEDURE DIVISION.                       
004400        OPEN-PARA.                               
004500            OPEN INPUT INFILE.                   
004600            DISPLAY "OPEN INFILE:" FS1.           
004700            OPEN OUTPUT OUTFILE.                 
004800            DISPLAY "OPEN OUTFILE:" FS2.         
005500        READ-PARA.                               
005600            READ INFILE AT END MOVE ' Y ' TO EOF.
005800            DISPLAY "READ STATUS:"FS1.           
005810            MOVE STUD TO STUD1.                   
005900            WRITE STUD1.                         
005910            DISPLAY "WRITE STATUS:"FS2. 
006100        CLOSE-PARA.                     
006200            CLOSE INFILE.               
006300            CLOSE OUTFILE.               
006400            STOP RUN.                   
Code'd

Regards,
Viswa.
Viswanathchandru
 
Posts: 271
Joined: Mon Oct 25, 2010 2:24 pm
Has thanked: 25 times
Been thanked: 0 time

Re: Doubt in writing multiple records to VSAM.

 

Re: Doubt in writing multiple records to VSAM.

Postby BillyBoyo » Thu Mar 10, 2011 9:42 pm

You are only reading one record, so only one is written. You are falling all the way from top to bottom of your program. It is how someone who knows about report-writer-style things might write their first Cobol program. You have to do the "loop" that reads the input file. Cobol isn't going to do it automatically for you.

Also, since you have the file statuses, you should test them after IO operations and stop further processing if you get an unexpected code.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Doubt in writing multiple records to VSAM.

Postby Robert Sample » Thu Mar 10, 2011 9:43 pm

One read, one write -- the program did EXACTLY what you told it to do. If you want to write more than one record, read more than one record.

And please -- learn how to click the Code button and paste your code with it instead of the way you did.
Robert Sample
Global moderator
 
Posts: 3367
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 222 times

Re: Doubt in writing multiple records to VSAM.

Postby Viswanathchandru » Thu Mar 10, 2011 9:47 pm

Thanks a lot billy and robert.. I'm a beginner in COBOL programming. trying to learn small things. Thanks a lot for your comments.
Robert: apologies for that. I will attach the codes hereafter in that way.

Regards,
Viswa
Viswanathchandru
 
Posts: 271
Joined: Mon Oct 25, 2010 2:24 pm
Has thanked: 25 times
Been thanked: 0 time

Re: Doubt in writing multiple records to VSAM.

Postby BillyBoyo » Thu Mar 10, 2011 10:10 pm

There is an example program clipped to the top of this forum. Although it reads two files and matches keys, it might be useful for you to look at it.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 264 times

Re: Doubt in writing multiple records to VSAM.

Postby Viswanathchandru » Fri Mar 11, 2011 2:46 pm

Thanks a lot Billy. Thanks for your suggestions.

Regards,
Viswa
Viswanathchandru
 
Posts: 271
Joined: Mon Oct 25, 2010 2:24 pm
Has thanked: 25 times
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post