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
 

 

How to update records in KSDS file through cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to update records in KSDS file through cobol
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

Moderator Team Head


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

PostPosted: Thu Jul 31, 2008 12:22 am    Post subject: Reply to: How to update records in KSDS file through cobol
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

Global Moderator


Joined: 14 Mar 2007
Posts: 10256
Location: italy

PostPosted: Thu Jul 31, 2008 12:23 am    Post subject: Reply to: How to update records in KSDS file through cobol
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

Site Director


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

PostPosted: Thu Jul 31, 2008 12:23 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Jul 31, 2008 1:26 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Jul 31, 2008 2:08 am    Post subject:
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    Post subject:
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

Site Director


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

PostPosted: Thu Jul 31, 2008 2:51 am    Post subject:
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: 4
Location: bangalore

PostPosted: Mon Aug 04, 2008 11:36 am    Post subject: Reply to: How to update records in KSDS file through cobol
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Converting Variable block file to Fix... bhavana yalavarthi DFSORT/ICETOOL 10 Tue May 16, 2017 2:20 pm
No new posts Fileaid Update Replace with null string descann Compuware & Other Tools 4 Mon May 15, 2017 3:00 pm
This topic is locked: you cannot edit posts or make replies. Cobol GUI (like Editor) Kala Mainframe COBOL Programming 14 Wed May 10, 2017 12:30 pm
No new posts IMS T-Pipe queue counts in a COBOL Pr... Siva NKK Kothamasu IMS DB/DC 0 Tue May 09, 2017 6:31 pm
No new posts Check if any Detail records and extra... V S Amarendra Reddy SYNCSORT 19 Mon May 08, 2017 8:54 pm


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