IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

re-write in sequential file


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Tue Feb 13, 2007 4:03 pm
Reply with quote

Hi...


How to rewrite/update a particular record in a sequential file......... i have 5 records in a file & i have to update the 3rd record ....
(organisation & access is sequential)



Thx in advance..
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 4:11 pm
Reply with quote

Hi There,

U can use

Code:
OPEN I-O IN-FILE
       :

     READ IN-FILE
     MOVE 1 TO WS-CNT
     PERFORM  UNTIL END-OF-FILE OR WS-CNT=4
        IF WS-CNT = 3
          Update the record
          REWRITE RECORD-IN
        END-IF
        ADD 1 TO WS-CNT
        READ IN-FILE
     END-PERFORM
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Tue Feb 13, 2007 4:20 pm
Reply with quote

hi.

i read in the document that if we want to rewrite a record in a sequential file we have to write a read statement before that rewrite statement & if we do so it will rewrite the first record irrespective of the condition.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 4:22 pm
Reply with quote

Hi swathi,
Its not like that it will rewrite the record which is pointed by file-pointer
Back to top
View user's profile Send private message
donevin

New User


Joined: 07 Jun 2005
Posts: 70
Location: South Africa

PostPosted: Tue Feb 13, 2007 4:27 pm
Reply with quote

I don't think rewrite is supported for line sequential files 'cause it cannot be opened in I-O mode and it doesn't have a key. Therefore you will have to (1) Read from input file (2) have same attribute file open as output (3) write to output unchanged records (4) change record three as required in working storage (5) write changed record to output (6) repeat (1) - (3) 'till end.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 4:39 pm
Reply with quote

donevin wrote:
I don't think rewrite is supported for line sequential files 'cause it cannot be opened in I-O mode
The Fine Manual:
Quote:
The I-O phrase is not valid for line-sequential files.
Donevin,
Do you know what a line-sequential file is?
Back to top
View user's profile Send private message
prav_06
Warnings : 1

Active User


Joined: 13 Dec 2005
Posts: 154
Location: The Netherlands

PostPosted: Tue Feb 13, 2007 4:57 pm
Reply with quote

Quote:
Donevin,
Do you know what a line-sequential file is?


And this is wat u get from Bill if ya go wrong icon_lol.gif

Donevin,
A line sequential file can be opened in I-O mode, output mode, Extend mode and of course input mode.

And for Swathi,
Quote:
i read in the document that if we want to rewrite a record in a sequential file we have to write a read statement before that rewrite statement & if we do so it will rewrite the first record irrespective of the condition.

U r absolutely rite, but before re-write u should position the cursor to the appropriate record, check this example

READ IN-FILE.
IF IN-REC-KEY = 100
Move To inrec variable
Move To inrec variable
Rewrite IN-REC.

This piece of code shd be in a loop to check for all the records in a Seq. File .

Cheer's,

Thamilzan.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 5:08 pm
Reply with quote

prav_06 wrote:
A line sequential file can be opened in I-O mode, output mode, Extend mode and of course input mode.
OK, then please explain this, the
Enterprise COBOL for z/OS and OS/390 Language Reference; 6.2.26 OPEN statement clearly states:
Quote:
I-O
Permits opening the file for both input and output operations. The I-O phrase can be specified only for files assigned to direct access devices.
The I-O phrase is not valid for line-sequential files.
Back to top
View user's profile Send private message
donevin

New User


Joined: 07 Jun 2005
Posts: 70
Location: South Africa

PostPosted: Tue Feb 13, 2007 5:18 pm
Reply with quote

Right back at ya prav_06. I don't want to bicker about this remove the line from my line sequential post and yes I know what line sequential files are.
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Tue Feb 13, 2007 5:31 pm
Reply with quote

prav_06 wrote:
Quote:
Donevin,
Do you know what a line-sequential file is?


And this is wat u get from Bill if ya go wrong icon_lol.gif

Donevin,
A line sequential file can be opened in I-O mode, output mode, Extend mode and of course input mode.

And for Swathi,
Quote:
i read in the document that if we want to rewrite a record in a sequential file we have to write a read statement before that rewrite statement & if we do so it will rewrite the first record irrespective of the condition.

U r absolutely rite, but before re-write u should position the cursor to the appropriate record, check this example

READ IN-FILE.
IF IN-REC-KEY = 100
Move To inrec variable
Move To inrec variable
Rewrite IN-REC.

This piece of code shd be in a loop to check for all the records in a Seq. File .

Cheer's,

Thamilzan.




if i dont know the key value how will it work.
i have a pgm with 2 files where i compare the emp-number of 1st record in the 1st file with all the records in the 2nd file. if it is found then i have to rewrite that record...
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 5:37 pm
Reply with quote

swathi.a wrote:
if i dont know the key value how will it work.
i have a pgm with 2 files where i compare the emp-number of 1st record in the 1st file with all the records in the 2nd file. if it is found then i have to rewrite that record...
There is no key, just read until you find the record that you want to update, update the record and rewrite it.

Simple icon_biggrin.gif
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 5:38 pm
Reply with quote

Hi there,

First sort both the files on the basis of emp-number then

Code:
Read filea
Read fileb
perform until end-of-filea
   if emp-num of filea =emp-num of file b
      update the record
      rewrite fileb
      read filea
      read fileb
   else
      if emp-num of filea < emp-num of fileb
         read filea
      else
         read fileb
     end-if
  end-if
end-perform
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Tue Feb 13, 2007 5:41 pm
Reply with quote

what does "update the record" mean...is it jus a comment or a statement...
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 5:45 pm
Reply with quote

Hi swati ,

Its just a comment befor rewriting u want to do some changes in the record thats why u r rewriting.

Hope it's clear now
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Tue Feb 13, 2007 6:39 pm
Reply with quote

thx ekta..i'll try it & i'll get back to u if i dont get....
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 13, 2007 10:03 pm
Reply with quote

Hello,

If you want to be really sure that your code will work in your environment with your specific file definition, you might make a copy of the file then put together a VERY small program that will attempt to read the existing records and re-write them with some constant value - no matching files or any computations.

When the run ends (or abends) look in the test file and see what has happened. If you isloate testing the re-write you will not have to concern yourself with any of the other processing the "real" program needs to do. You will see how re-write works for your situation.
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Wed Feb 14, 2007 12:21 pm
Reply with quote

guptae wrote:
Hi there,

First sort both the files on the basis of emp-number then

Code:
Read filea
Read fileb
perform until end-of-filea
   if emp-num of filea =emp-num of file b
      update the record
      rewrite fileb
      read filea
      read fileb
   else
      if emp-num of filea < emp-num of fileb
         read filea
      else
         read fileb
     end-if
  end-if
end-perform




Hi,

rewrite in this way is not working...
its not giving any error and also its not updating the file...
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Wed Feb 14, 2007 12:29 pm
Reply with quote

swathi.a wrote:
rewrite in this way is not working...
its not giving any error and also its not updating the file...
How do you know it's not updating?
Post your code.
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Wed Feb 14, 2007 4:31 pm
Reply with quote

Code:
MOVE EMP-NUMBERT TO EMP-NUMBER1                     
MOVE BASIC-PAYT TO BASIC-PAY1                       
MOVE HOUSE-ALLOWT TO HOUSE-ALLOW1                   
MOVE CONVEY-ALLOWT TO CONVEY-ALLOW1                 
MOVE DESG-CODET TO DESG-CODE1                       
COMPUTE HOUSE-ALLOW2 = 0.5 * BASIC-PAY1             
COMPUTE CONVEY-ALLOW2 = 0.3 * BASIC-PAY1             
IF CONVEY-ALLOW2 < 2500                             
  MOVE 2500 TO CONVEY-ALLOW2                         
ELSE IF CONVEY-ALLOW2 > 6000                         
  MOVE 6000 TO CONVEY-ALLOW2                         
END-IF                                               
DISPLAY CONVEY-ALLOW2                               
 IF EMP-NUMBER1 > 100001 AND EMP-NUMBER1 IS <= 999999
    IF DESG-CODE1 > 01 AND DESG-CODE1 IS <= 15         
           IF BASIC-PAY1 > 5000 AND BASIC-PAY1 IS <= 15000 
               IF HOUSE-ALLOW1 = HOUSE-ALLOW2 AND     
               CONVEY-ALLOW1 = CONVEY-ALLOW2     
             MOVE TRANS-FILE TO EMP-FILE         
             [b]RE-WRITE EMP-FILE                       [/b]
             ELSE                                 
             MOVE TRANS-FILE TO EMP-FILE         
             MOVE CONVEY-ALLOW2 TO CONVEY-ALLOW   
             MOVE HOUSE-ALLOW2 TO HOUSE-ALLOW     
             RE-WRITE EMP-FILE                       
          END-IF                                 
        ELSE                                     
         DISPLAY "INVALID BASIC PAY "             
        END-IF                                   
      ELSE                                       
       DISPLAY "INVALID DESG CODE "               
      END-IF                                     
     ELSE                                           
      DISPLAY "INVALID EMPLOYEE NUMBER " EMP-NUMBER1
     END-IF.



This is the code i hav written for rewrite..
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Feb 14, 2007 8:20 pm
Reply with quote

Hello,

Please do this
Quote:
If you want to be really sure that your code will work in your environment with your specific file definition, you might make a copy of the file then put together a VERY small program that will attempt to read the existing records and re-write them with some constant value - no matching files or any computations.

When the run ends (or abends) look in the test file and see what has happened. If you isloate testing the re-write you will not have to concern yourself with any of the other processing the "real" program needs to do. You will see how re-write works for your situation.

then report back on what was the outcome.

If your problem IS the "re-write" you need to isloate that and make sure that there really is a re-write problem versus some other logic problem. If you persist in testing with the whole program, you might display more information before and after the 2 places a re-write could occur (i.e the record before the moves and the record after the moves. You would not need to process the whole file - just enough to verify that both paths to the re-write were followed. Actually, if your original post was accurate there are only 5 records - so it would be easy to use them all.

From the bit of code that was posted i believe it likely that there is a logic error somwhere. How do you know the re-write code was ever executed?
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Feb 15, 2007 12:20 am
Reply with quote

swathi.a wrote:
Code:
           IF BASIC-PAY1 > 5000 AND BASIC-PAY1 IS <= 15000 
               IF HOUSE-ALLOW1 = HOUSE-ALLOW2 AND     
                 CONVEY-ALLOW1 = CONVEY-ALLOW2     
                   MOVE TRANS-FILE TO EMP-FILE         
                   RE-WRITE EMP-FILE           
               ELSE                                 
                  MOVE TRANS-FILE TO EMP-FILE         
                  MOVE CONVEY-ALLOW2 TO CONVEY-ALLOW   
                  MOVE HOUSE-ALLOW2 TO HOUSE-ALLOW     
                  RE-WRITE EMP-FILE                       
           END-IF                                 
Kinda looks like you are rewriting in either case from the same "trans-file", which came from where? the emp-file?
Back to top
View user's profile Send private message
swathi.a
Warnings : 1

New User


Joined: 05 Feb 2007
Posts: 10
Location: hyd

PostPosted: Thu Feb 15, 2007 11:33 am
Reply with quote

William Thompson wrote:
swathi.a wrote:
Code:
           IF BASIC-PAY1 > 5000 AND BASIC-PAY1 IS <= 15000 
               IF HOUSE-ALLOW1 = HOUSE-ALLOW2 AND     
                 CONVEY-ALLOW1 = CONVEY-ALLOW2     
                   MOVE TRANS-FILE TO EMP-FILE         
                   RE-WRITE EMP-FILE           
               ELSE                                 
                  MOVE TRANS-FILE TO EMP-FILE         
                  MOVE CONVEY-ALLOW2 TO CONVEY-ALLOW   
                  MOVE HOUSE-ALLOW2 TO HOUSE-ALLOW     
                  RE-WRITE EMP-FILE                       
           END-IF                                 
Kinda looks like you are rewriting in either case from the same "trans-file", which came from where? the emp-file?



if the conditions specified are satisfied it rewrites from trans-file to emp file...
if the house allow & convey allow conditions are not satisfied, it writes from trans-file to emp-file with corrected house allow & convey-allow..
Back to top
View user's profile Send private message
h.dinesh

New User


Joined: 06 Dec 2006
Posts: 46
Location: Chennai

PostPosted: Thu Feb 15, 2007 1:12 pm
Reply with quote

Swati,

Did you check if any of these 'DISPLAY' worked? Just to check if there is any problem with the logic or not.

Code:
       ELSE                                     
         DISPLAY "INVALID BASIC PAY "             
        END-IF                                   
      ELSE                                       
       DISPLAY "INVALID DESG CODE "               
      END-IF                                     
     ELSE                                           
      DISPLAY "INVALID EMPLOYEE NUMBER " EMP-NUMBER1
     END-IF.


Also check the variables used

CONVEY-ALLOW &
HOUSE-ALLOW

before second rewrite are correct.

Dinesh
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 1
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts SFTP Issue - destination file record ... All Other Mainframe Topics 2
Search our Forums:

Back to Top