how to insert,update,view,delete records in a KSDS file.

This is a Mainframe COBOL forum - you can post your queries on Mainframe COBOL, VS COBOL II, COBOL/370 , Enterprise COBOL

Moderators: dbzTHEdinosauer, Moderator Group

Post Reply
sowjanya
Member
Posts: 7
Joined: Tue Nov 11, 2008 10:47 am

how to insert,update,view,delete records in a KSDS file.

Post by sowjanya » Thu Oct 13, 2011 3:52 pm

Hi,

Can any one please help me out in giving a sample code for insertion, deletion, updation,viewing records in file using a cobol program with only one output file which is KSDS file and accepting inputs from JCL and write the records in that output KSDS file.

RECORD KEY IS ENO

We tried inserting the file as below code but it wasnt writing into the file.
******************************************************************
* INPUT-OUTPUT SECTION *
******************************************************************
INPUT-OUTPUT SECTION.

******************************************************************
* FILE-CONTROL *
******************************************************************
FILE-CONTROL.

SELECT ENTRADA1
ASSIGN TO FILE1
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS ENO
FILE STATUS IS FS-ENTRADA1.

******************************************************************
* D A T A D I V I S I O N *
******************************************************************
DATA DIVISION.

******************************************************************
* FILE SECTION *
******************************************************************
FILE SECTION.

FD ENTRADA1.
01 RG-ENTRADA1.
05 ENO PIC X(5).
05 ENAME PIC X(10).
05 ESAL PIC 99999.

******************************************************************
* W O R K I N G S T O R A G E S E C T I O N *
******************************************************************
WORKING-STORAGE SECTION.

******************************************************************
* VARIABLES PARA EL CONTROL DE ERRORES *
******************************************************************
01 FS-FILE-STATUS.
05 FS-ENTRADA1 PIC X(02) VALUE SPACES.

01 TXNCODE PIC 9.
88 INS VALUE 1.
88 UPD VALUE 2.
88 DEL VALUE 3.
88 CALSAL VALUE 4.
88 VIEW VALUE 5.
88 EXIT1 VALUE 0.

01 CH1 PIC X VALUE 'Y'.
01 FIELD PIC X(6) VALUE ALL SPACE.
01 PFAMT PIC 9(5) VALUE ALL ZEROS.
01 RESULT PIC 9(9) VALUE ALL ZEROS.
01 EOF PIC X VALUE 'Y'.

01 CANCELAR PIC X(8) VALUE 'CANCELAR'.

******************************************************************
* *
* P R O C E D U R E D I V I S I O N *
* *
******************************************************************
PROCEDURE DIVISION.

PERFORM PARA-1.

******************************************************************
* 2000-PROCESO *
* *
* PROCESO PARA HACER LA ELIMINACIÓN DE CONSOLIDACIÓN Y PROCESOS *
******************************************************************
PARA-1.

OPEN I-O ENTRADA1

PERFORM UNTIL CH1 EQUAL 'N'

DISPLAY 'WHICH TRANSACTION DO YOU WANT TO PERFORM'
DISPLAY '1-INSERT'
DISPLAY '2-UPDATE'
DISPLAY '3-DELETE'
DISPLAY '4-CALCULATE SALARY'
DISPLAY '5-VIEW'
DISPLAY '0-EXIT'
DISPLAY 'ENTER NUMBER TO PERFORM TRANSACTION:'
ACCEPT TXNCODE

EVALUATE TRUE

WHEN INS PERFORM INS-PARA
WHEN UPD PERFORM UPD-PARA
WHEN DEL PERFORM DEL-PARA
WHEN CALSAL PERFORM CAL-SAL-PARA
WHEN VIEW PERFORM VIEW-PARA
WHEN EXIT1 PERFORM EXIT-PARA

END-EVALUATE

END-PERFORM.

CLOSE ENTRADA1.

STOP RUN.

******************************************************************
* INS-PARA *
******************************************************************
INS-PARA.

DISPLAY 'INSERTING EMP RECORD'.
DISPLAY 'ENTER EMP NUMBER : '.
ACCEPT ENO.

DISPLAY 'ENTER EMP NAME : '.
ACCEPT ENAME.

DISPLAY 'ENTER EMP SALARY : '.
ACCEPT ESAL.

WRITE RG-ENTRADA1
INVALID KEY DISPLAY 'REC ALREADY EXIST WITH EMP NO'
END-WRITE.

******************************************************************
* UPD-PARA *
******************************************************************
UPD-PARA.

DISPLAY 'UPDATING EMP RECORD'
DISPLAY 'WHICH RECORD YOU WANT TO UPDATE : '
DISPLAY 'ENTER EMP NUMBER TO UPDATE : '
ACCEPT ENO.

READ ENTRADA1
INVALID KEY DISPLAY 'RECORD DOES NOT EXIST'
NOT INVALID KEY
DISPLAY 'WHICH FIELD YOU WANT TO UPDATE'
DISPLAY '1-NAME OR 2-SALARY'

ACCEPT FIELD

IF FIELD EQUAL 1
DISPLAY 'ENTER VALUE FOR NAME : '
ACCEPT ENAME
ELSE
IF FIELD EQUAL 2
DISPLAY 'ENTER VALUE FOR SALARY : '
ACCEPT ESAL
END-IF
END-IF

REWRITE RG-ENTRADA1
DISPLAY 'RECORD HAS BEEN UPDATED'
END-READ.

******************************************************************
* DEL-PARA *
******************************************************************
DEL-PARA.

DISPLAY 'DELETING EMP RECORD'
DISPLAY 'WHICH RECORD YOU WANT TO DELETE : '
ACCEPT ENO.

DELETE ENTRADA1
INVALID KEY DISPLAY 'RECORD DOES NOT EXIST'
NOT INVALID KEY
DISPLAY 'RECORD HAS BEEN DELETED'
END-DELETE.

******************************************************************
* CAL-SAL-PARA *
******************************************************************
CAL-SAL-PARA.

DISPLAY 'CALCULATE SALARY OF EMP RECORD'

DISPLAY 'WHICH RECORD YOU WANT TO CALCULATE THE SAL : ' 00967104
DISPLAY 'ENTER EMP NUMBER TO CALCULATE : ' 00967204
ACCEPT ENO. 00968003
00969003
READ ENTRADA1 00969103
INVALID KEY DISPLAY 'RECORD DOES NOT EXIST' 00969203
NOT INVALID KEY 00969303
DISPLAY 'ENTER THE PF-AMOUNT TO BE ADDED TO SAL' 00969404
ACCEPT PFAMT 00969604
00969703
ADD PFAMT, ESAL GIVING RESULT 00970204
00970404
DISPLAY 'RESULT IS EQUAL ' RESULT 00970804
00970903
REWRITE RG-ENTRADA1 00971003
DISPLAY 'PF AMOUNT IS ADDED TO SALARY' 00971104
END-READ. 00971203
00971303
******************************************************************
* VIEW-PARA *
******************************************************************
VIEW-PARA. 00972006

DISPLAY 'VIEW EMP RECORD' 00980002
00981002
DISPLAY 'WHICH RECORD YOU WANT TO VIEW' 00990002
ACCEPT ENO. 01000002
01001002
READ ENTRADA1 01010002
INVALID KEY DISPLAY 'RECORD DOES NOT EXIST' 01020002
NOT INVALID KEY 01030002
DISPLAY 'EMP-NO ->' ENO 01040002
DISPLAY 'EMP-NAME->' ENAME 01050002
DISPLAY 'EMP-SAL ->' ESAL 01060002
END-READ. 01070002
01080001
******************************************************************
* EXIT-PARA *
******************************************************************
EXIT-PARA. 01090002

MOVE 'N' TO CH1. 01100004



I will be very helpfull if i get help as soon as possible.

Thanks in advance,
sowjanya.[code][/code]

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Thu Oct 13, 2011 7:43 pm

actually you will be very glad to have someone else do your work for you.
I doubt you will be helpful at all for our endevors.

at the top of the page is a link to tutorials.
Krishna has gone to a lot of trouble to assemble these tutorials.
inasmuch as you have not bothered to look,
I will save you the trouble and provide you with the link to VSAM Tutorials
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

DikDude
Moderator
Posts: 1001
Joined: Fri Jul 22, 2011 8:39 am
Location: usa

Post by DikDude » Thu Oct 13, 2011 9:07 pm

If after reading the documentation you still have questions/problems, post the specifics of your issue.

Do NOT post "it didn't work" which only wastes everyone's time.
We tried inserting the file as below code but it wasnt writing into the file.
What did happen?
Have a good one

sowjanya
Member
Posts: 7
Joined: Tue Nov 11, 2008 10:47 am

Post by sowjanya » Fri Oct 14, 2011 1:21 pm

SELECT OUTFILE ASSIGN TO DD1
ORGANIZATION IS INDEXED
ACCESS MODE IS DYNAMIC
RECORD KEY IS ENO
FILE STATUS IS FS1.
DATA DIVISION.
FILE SECTION.
FD OUTFILE.
01 EMPREC.
05 ENO PIC X(4).
05 ENAME PIC X(20).
05 ESAL PIC 9(5).
05 FILLER PIC X(56).

WORKING-STORAGE SECTION.
01 FS1 PIC 9(2).
01 OPT PIC X VALUE 'Y'.

PROCEDURE DIVISION.
PERFORM OPEN-PARA.
PERFORM ACC-PARA UNTIL OPT = 'N'.
PERFORM CLOSE-PARA.
STOP RUN.
OPEN-PARA.
OPEN I-O OUTFILE.
DISPLAY 'OPEN FS1: ' FS1.
ACC-PARA.
ACCEPT ENO.
ACCEPT ENAME.
ACCEPT ESAL.
DISPLAY 'ENO :' ENO.
DISPLAY 'ENAME: ' ENAME.
DISPLAY 'ESAL : ' ESAL.
REWRITE EMPREC INVALID KEY DISPLAY 'DUPLICATE RECORD'.
ACCEPT OPT.
DISPLAY 'OPT : ' OPT.
CLOSE-PARA.
CLOSE OUTFILE.
DISPLAY 'CLOSE FS1: ' FS1.

This is my program... the problem is i tried giving opening OUTFILE in OUTPUT and also I-O mode but this always says filestatus code 39.

Please see my spool output:
********************
OPEN FS1: 39
ENO :4444
ENAME: RADHIKAMAIL
ESAL : 44444
OPT : N
CLOSE FS1: 42
********************

and i have created VSAM file as below which is of length 20 and EMPNO is key of length 5
//STEP01 EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE CLUSTER -
(NAME(TCOM.FILE1.KSDS) -
TRACKS(2,1) -
CISZ(4096) -
FREESPACE(5,5) -
KEYS(5,0) -
RECORDSIZE(20,20)) -
DATA -
(NAME(TCOM.FILE1.KSDS.DATA))-
INDEX -
(NAME(TCOM.FILE1.KSDS.INDEX))

as the attributes in program and file are same also am facing this error.
so please help me out in resolving this.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Oct 14, 2011 1:44 pm

you are wasting our time:

FD OUTFILE.
01 EMPREC.
05 ENO PIC X(4).
05 ENAME PIC X(20).
05 ESAL PIC 9(5).
05 FILLER PIC X(56).


how do you imagine that the FD record definition is the same as the DEFINE RECORDSIZE(20,20)) -

AND LEARN TO USE BBCODE
I have no desire to read this garbage without the help of indentation.
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

User avatar
dbzTHEdinosauer
Moderator
Posts: 981
Joined: Mon Oct 02, 2006 8:31 pm

Post by dbzTHEdinosauer » Fri Oct 14, 2011 2:12 pm

you can not open an empty vsam file in I/O mode
learn to use the two dataname file status clause for vsam:
FILE STATUS IS <data1> <data2>
and bookmark this link to QSAM/VSAM File Status Codes
Dick Brenholtz
JCL, SQL and code in programs have an irritating habit of doing what you say,
not what you meant.

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others