confused with functionality of INITIALIZE



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

confused with functionality of INITIALIZE

Postby mrinmoy » Fri Feb 08, 2013 11:34 am

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
mrinmoy
 
Posts: 2
Joined: Thu Feb 07, 2013 10:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: confused with functionality of INITIALIZE

Postby BillyBoyo » Fri Feb 08, 2013 12:53 pm

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?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: confused with functionality of INITIALIZE

Postby mrinmoy » Fri Feb 08, 2013 1:09 pm

[Shouting Removed]


You want to try again without the shouting?
mrinmoy
 
Posts: 2
Joined: Thu Feb 07, 2013 10:09 pm
Has thanked: 0 time
Been thanked: 0 time

Re: confused with functionality of INITIALIZE

Postby Robert Sample » Fri Feb 08, 2013 5:22 pm

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.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post