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

How to update records in KSDS file through cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Thu Jul 31, 2008 12:07 am
Reply with quote

I have a KSDS file whose structure is

EMPNO EMPNAME EMPADD

2000 suresh bangalore
4001 ravi pune
3005 amit chennai

I want to update the empname field. Wherever ravi comes in this field should be updated to
sonu. How can I acheive this.
Back to top
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Thu Jul 31, 2008 12:22 am
Reply with quote

1.10.3.6 Replacing records in a VSAM file.
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10873
Location: italy

PostPosted: Thu Jul 31, 2008 12:23 am
Reply with quote

is that an update based on the key, or a patterned update...

like in ispf edit
Code:
change "ravi" "sonu" all


just to get a hint about the logic

if my assumption is right the quickest thing would be
use dfsort/syncsort to carry on a change creating a new file and then
rebuild the vsam whit the changed data
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: Thu Jul 31, 2008 12:23 am
Reply with quote

Hello,

1. Read the vsam file.
2. Compare for "ravi".
3. If "ravi" move "sonu".
4. Rewrite the record.

Tht is all. . .
Back to top
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Thu Jul 31, 2008 12:57 am
Reply with quote

From the link given by superk, it says "For indexed files, move the record key to the RECORD KEY data item and then issue the REWRITE."

Suppose I have defined RECORD KEY key1 in Select assign clause, the how I have to use the code in procedure division?

Thanks.
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: Thu Jul 31, 2008 1:26 am
Reply with quote

Hello,

Please post your SELECT and the FD for the file.
Back to top
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Thu Jul 31, 2008 2:04 am
Reply with quote

This is what I am using -

SELECT FILE1 ASSIGN TO EMPFILE
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY key1

DATA DIVISION.
FILE SECTION.
FD FILE1.
01 FILE1-REC.
05 EMPNO PIC X(5).
05 EMPNAME PIC X(6).
05 EMPADD PIX X(10).


Thanks.
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: Thu Jul 31, 2008 2:08 am
Reply with quote

Hello,

Is EMPNO the key to the file?

If yes, change the RECORD KEY to
Code:
RECORD KEY IS EMPNO
Back to top
View user's profile Send private message
Select-mf

New User


Joined: 11 May 2007
Posts: 42
Location: bangalore

PostPosted: Thu Jul 31, 2008 2:43 am
Reply with quote

Ok I did. Could you please tell me what I have to use in procedure division?

Is this code correct -

OPEN I/O FILE1
READ FILE1 INTO WS-FILE1-REC.
MOVE '4001' TO EMPNO.
IF EMPNO=WS-EMPNO
MOVE 'SONU' TO WS-EMPNAME-REC.
REWRITE FILE1-REC FROM WS-FILE1-REC.
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: Thu Jul 31, 2008 2:51 am
Reply with quote

Hello,

You need to move the 4001 to empno before the read - you have specified random (which is what you want) so you need to provide the key before the read.

The IF should probably compare the name, rather than the empno. . . By definition, you will have the 4001 record (if one exists).
Back to top
View user's profile Send private message
hanucob

New User


Joined: 15 Jul 2008
Posts: 3
Location: bangalore

PostPosted: Mon Aug 04, 2008 11:36 am
Reply with quote

dear friend,
whenever an updation is to be done,first the correspondin record is to be read and next updation is to be made.
--------------------------------------------------------
INPUT-OUTPUT SECTION..............
SELECT FILE-1 ASSIGN TO .......
ORGANIZATION IS INDEXED
RECORD KEY IS EMP-NO
FILE STATUS FS1
FILE SECTIO.....
FD FILE-1.
01 KSDS-RECORD.
05 EMP-NO PIC........
05 EMP-NAME PIC.......
05 EMP-ADR PIC........
WORING-STORAGE...................
01 EMP-UPD-NAME PIC........
01 FS1 PIC.......
PROCEDURE DIVISION..........
...............
.................
READ FILE-1 .........
INVALID KEY DISPLAY ' NO RECORD FOUND '

ACCEPT EMP-UPD-NAME
MOVE EMP-UPD-NAME TO EMP-NAME
REWRITE FILE-1..............
............................
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
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
Search our Forums:

Back to Top