Have a project where need to re-write a datafile but with a slightly different primary key value? Does someone have a working example? Thanks in advance.
I do have the original FD and structure. Field in file is pic 9(8) but was being used by program as pic 9(5) hence numbers were stored as "12345Â Â " but now need to be reformatted as "00012345". Thanks
This is sadly not possible. The only way to do something like this would be to write a new record with the new key, and delete the old one. You would probably want to do this within a transaction, so that either both operations succeed, or they both fail.
------------------------------
Randy Zack
Principal Software Engineer
Rocket Forum Shared Account
------------------------------
This is sadly not possible. The only way to do something like this would be to write a new record with the new key, and delete the old one. You would probably want to do this within a transaction, so that either both operations succeed, or they both fail.
------------------------------
Randy Zack
Principal Software Engineer
Rocket Forum Shared Account
------------------------------
Can we not do something like below? Like two different data files. Then is there a command to swap the data file names?
IDENTIFICATION DIVISION.
PROGRAM-ID. CHANGE-PRIMARY-KEY.
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT OLD-FILE ASSIGN TO DISK "OLD_DATA"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
SELECT NEW-FILE ASSIGN TO DISK "NEW_DATA"
ORGANIZATION IS SEQUENTIAL
ACCESS MODE IS SEQUENTIAL.
DATA DIVISION.
FILE SECTION.
FD OLD-FILE
RECORD CONTAINS 100 CHARACTERS
DATA RECORD IS RECORD-DATA.
FD NEW-FILE
RECORD CONTAINS 100 CHARACTERS
DATA RECORD IS RECORD-DATA.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECORD-DATA.
05 CUSTOMER-ID PIC 9(5).
05 CUSTOMER-NAME PIC X(30).
05 OTHER-DATA PIC X(65).
PROCEDURE DIVISION.
OPEN INPUT OLD-FILE OUTPUT NEW-FILE.
READ OLD-FILE INTO RECORD-DATA AT END
GO TO EXIT-PROCESS.
PERFORM UPDATE-RECORD UNTIL
READ OLD-FILE INTO RECORD-DATA AT END.
CLOSE OLD-FILE NEW-FILE.
EXIT-PROCESS.
EXIT.
UPDATE-RECORD SECTION.
/* Logic to modify the CUSTOMER-ID (primary key) */
COMPUTE CUSTOMER-ID = CUSTOMER-ID + 1.
WRITE RECORD-DATA TO NEW-FILE.
------------------------------
Anup Mistry
Deneb
------------------------------