Page 1 of 1

confused with functionality of INITIALIZE

PostPosted: Fri Feb 08, 2013 11:34 am
by mrinmoy
i am trying to edit a file in I-O open mode and using rewrite, when I am using both initialize and rewrite for a record it is working fine , but when I am initializing record variable for each iteration and rewriting only one record it is putting blank in places of other record.

condition 1
 4000-FILE-REWRITE-PARA.                         
     OPEN I-O OUT-FILE                           
     PERFORM UNTIL FILE-STAT2 = 10               
     READ OUT-FILE                               
     IF IDS OF FILE-REC2 = 1  THEN               
        MOVE "HIGH VALUE ." TO PRTY OF FILE-REC2 
        REWRITE FILE-REC2                         
        INITIALIZE     FILE-REC2                 
     END-IF                                       
     END-PERFORM.                                 
     CLOSE OUT-FILE.                             

output in file
 ****** ***************************** Top of Data ****
 000200 DIPAYAN   UNITECH   000002                   
 000300 AYAN      TCPX      000003                   
 000400 DIPRA     TCHX      000004                   
 000500 BAPPA     GTP       000005                   
 000510 MRINMOY   UNITECH   000001HIGH VALUE .       
 000600 PUSHPA    GTP       000006                   
 000700 SHRUTHY   BIPL      000007                   
 000800 TINA      BIPL      000008                   
 000900 ANISH     TPLS      000009                   
 001000 RIYA      TPLS      000010                   
 ****** **************************** Bottom of Data **


condition 2
****************************************************
 4000-FILE-REWRITE-PARA.                           
     OPEN I-O OUT-FILE                             
     PERFORM UNTIL FILE-STAT2 = 10                 
     READ OUT-FILE                                 
     IF IDS OF FILE-REC2 = 1  THEN                 
        MOVE "HIGH VALUE ." TO PRTY OF FILE-REC2   
        REWRITE FILE-REC2                           
     END-IF                                         
        INITIALIZE     FILE-REC2                   
     END-PERFORM.                                   
     CLOSE OUT-FILE.                               
****************************************************

output in file
 ****** ***************************** Top of Data
 000200                     000000               
 000300                     000000               
 000400                     000000               
 000500                     000000               
 000510 MRINMOY   UNITECH   000001HIGH VALUE .   
 000600                     000000               
 000700                     000000               
 000800                     000000               
 000900                     000000               
 001000                     000000               
 ****** **************************** Bottom of Data

Re: confused with functionality of INITIALIZE

PostPosted: Fri Feb 08, 2013 12:53 pm
by BillyBoyo
The code shown has not produced that output.

You have created the output with the editor, or someone is tricking you by doing that while you are not looking. See the "000510"?

Troll? Or Tricked?

Re: confused with functionality of INITIALIZE

PostPosted: Fri Feb 08, 2013 1:09 pm
by mrinmoy
[Shouting Removed]


You want to try again without the shouting?

Re: confused with functionality of INITIALIZE

PostPosted: Fri Feb 08, 2013 5:22 pm
by Robert Sample
Let me give you a COBOL rule of thumb that will save you a great deal of problems in the future:

DO NOT EVER, UNDER ANY CIRCUMSTANCES, USE INITIALIZE ON AN FD 01 THAT IS OPEN INPUT OR I-O.

When you read the file, the data being read from the file will replace everything in the FD 01 -- so why use INITIALIZE anyway? All you are doing is wasting CPU time, and the time of everyone who has to maintain the program in the future and figure out why you did such a meaningless thing.