Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

re-write in sequential file
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: re-write in sequential file
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: 1187
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 4:11 pm    Post subject:
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    Post subject: Re: re-write in sequential file
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: 1187
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 4:22 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 4:39 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 5:08 pm    Post subject:
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    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 5:37 pm    Post subject:
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: 1187
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 5:38 pm    Post subject:
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    Post subject:
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: 1187
Location: Bangalore,India

PostPosted: Tue Feb 13, 2007 5:45 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Tue Feb 13, 2007 10:03 pm    Post subject:
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    Post subject:
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: 3158
Location: Tucson AZ

PostPosted: Wed Feb 14, 2007 12:29 pm    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Wed Feb 14, 2007 8:20 pm    Post subject:
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
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us