View previous topic :: View next topic
|
Author |
Message |
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
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 |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Please post your SELECT and the FD for the file. |
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
Is EMPNO the key to the file?
If yes, change the RECORD KEY to
Code: |
RECORD KEY IS EMPNO |
|
|
Back to top |
|
|
Select-mf
New User
Joined: 11 May 2007 Posts: 42 Location: bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
hanucob
New User
Joined: 15 Jul 2008 Posts: 3 Location: bangalore
|
|
|
|
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 |
|
|
|