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
 

 

INSERT record into VSAM through COBOL.
Goto page 1, 2  Next
 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Thu Jul 21, 2005 10:08 am    Post subject: INSERT record into VSAM through COBOL.
Reply with quote

hi all,

Is there any way to insert a record into a VSAM file(KSDS).

Example:
file:
1 aaaa
2 dddd
5 cccc

Now i want to insert '3 eeee' after the record '2 dddd'.
Is this possible.If so ,how can i do it?
Please help me.

Regards,
Push.
Back to top
View user's profile Send private message

thanooz

New User


Joined: 28 Jun 2005
Posts: 99

PostPosted: Thu Jul 21, 2005 11:43 am    Post subject:
Reply with quote

yes it is possible

if your ksds file key is record number

you can access ksds file in random mode

the pass 3 into that key field.

write rec.








thanooz
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Thu Jul 21, 2005 12:37 pm    Post subject:
Reply with quote

hi thanooz,

Yes,the record numbers (1,2,5) in above example are
the key fields.

But i am getting "OUT OF SEQUENCE" error.
What can I do?
In what mode should I open the file?
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Fri Jul 22, 2005 1:20 am    Post subject:
Reply with quote

try the i-o mode or extend mode

any comments please....
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Fri Jul 22, 2005 11:42 am    Post subject:
Reply with quote

hi VM,

After your reply.I tried all the combinations.
But no result.

Then what the people are doing if such this has to be done.
I wonder?
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Fri Jul 22, 2005 12:31 pm    Post subject: [solved]
Reply with quote

hi all,

I could insert such values when i tried
with jcl(IDCAMS-REPRO).

But i couldnt do with cobol FILE operations normally.

So if we have to insert,we can just repro the content.
(But I think we should have created the VSAM with REUSE
option).

Correct me if I am wrong anywhere.

Thanks for members who helped me.
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Fri Jul 22, 2005 7:14 pm    Post subject: Hi
Reply with quote

Have u given u r FD ENTRY descriptions correctly.
This link would help

http://publib.boulder.ibm.com/infocenter/pdthelp/index.jsp?topic=/com.ibm.entcobol3.doc/tpqsm28.htm
Back to top
View user's profile Send private message
vijayamadhuri

Active User


Joined: 06 Apr 2005
Posts: 180

PostPosted: Fri Jul 22, 2005 7:50 pm    Post subject: Hi
Reply with quote

The syntax would be

move value into key
read record
---

write_record.
Back to top
View user's profile Send private message
thanooz

New User


Joined: 28 Jun 2005
Posts: 99

PostPosted: Fri Jul 22, 2005 8:48 pm    Post subject:
Reply with quote

hi

pushpagiri


your access mode is in random or dyanmic

you open your file in i-0 mode.

move 3 to key value

write record

thanooz
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Jul 24, 2005 9:41 pm    Post subject:
Reply with quote

Push,

Adding a rec to a VSAM file is trivial, but there can be a variety of reasons for why you're having trouble. Since you don't provide the pertinent code (select stmt, FD, open, R/W stmts), jcl, and IDCAMS data it's difficult to guess at the reason for the problem.

BTW, did you allocate freespace? And please confine your request to ONE thread.
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Mon Jul 25, 2005 3:34 pm    Post subject:
Reply with quote

hi,

this is the cobol prog i used :
(PLS SEE THE HIGHLIGHTED CODES)

INKSDS = FILE FOR INSERTING NEW RECORD.
INSEQ = FILE FROM WHERE INSERTING RECORDS ARE TAKEN FROM.


IDENTIFICATION DIVISION.
PROGRAM-ID. INSKSDS.
AUTHOR. PUSHPAGIRI.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INKSDS ASSIGN TO INVSAMF
ACCESS IS SEQUENTIAL
ORGANIZATION IS INDEXED
RECORD KEY IS SLNO
FILE STATUS IS FSTAT-VSAM.

SELECT INSEQ ASSIGN TO INSEQF
ACCESS IS SEQUENTIAL
ORGANIZATION IS SEQUENTIAL
FILE STATUS IS FSTAT-SEQ.

DATA DIVISION.
FILE SECTION.
FD INKSDS.
01 IN-KSDS-REC.
05 SLNO PIC X(1).
05 FILLER PIC X(1).
05 DATA1 PIC X(4).
05 FILLER PIC X(74).
FD INSEQ RECORDING MODE IS F.
01 IN-SEQ-REC.
05 IN-SEQ-SLNO PIC X(1).
05 FILLER PIC X(1).
05 IN-SEQ-DATA1 PIC X(4).
05 FILLER PIC X(74).
WORKING-STORAGE SECTION.
77 FSTAT-VSAM PIC X(2).
77 FSTAT-SEQ PIC X(2).
01 WS-FEOF.
05 WS-KSDS-FEOF PIC 9 VALUE 0.
05 WS-SEQ-FEOF PIC 9 VALUE 0.
05 LNK-ERROR-DATA PIC X(6).
PROCEDURE DIVISION.
MAINLINE-SECTION.
OPEN EXTEND INKSDS.
DISPLAY "OPEN STAT : " FSTAT-VSAM.
OPEN INPUT INSEQ.
MOVE 0 TO WS-SEQ-FEOF.
PERFORM READ-PROCESS UNTIL WS-SEQ-FEOF = 1.
CLOSE INSEQ.
CLOSE INKSDS.
STOP RUN.
READ-PROCESS.
READ INSEQ AT END MOVE 1 TO WS-SEQ-FEOF.
IF WS-SEQ-FEOF = 0 THEN
MOVE IN-SEQ-SLNO TO SLNO
MOVE IN-SEQ-DATA1 TO DATA1
WRITE IN-KSDS-REC

DISPLAY "WRITE STAT : " FSTAT-VSAM
END-IF.
Back to top
View user's profile Send private message
shobam

New User


Joined: 18 Jul 2005
Posts: 34
Location: CN

PostPosted: Mon Jul 25, 2005 4:01 pm    Post subject:
Reply with quote

Sorry , If I am asking you a stupid question.

I think you are just copying the contents of the sequential file to the KSDS file. Where you are trying to INSERT the record "3 eeee" ?.

The file being copied to KSDS has to be in SORTED order.So the input sequential files should have the records in sorted order. If not you will get the OUT OF SEQUENCE error to my knowledge.
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Mon Jul 25, 2005 5:29 pm    Post subject:
Reply with quote

Hi Shobam,

The sequential file contains the record '3 eeee' (assume like this)
And if i have to insert that record into inksds file,what can i do?

Please give your suggestion.
Back to top
View user's profile Send private message
dneufarth

Active User


Joined: 27 Apr 2005
Posts: 236
Location: Cincinnati OH USA

PostPosted: Mon Jul 25, 2005 7:16 pm    Post subject:
Reply with quote

heed thanooz advice on random and I/O

you are attempting to load file rather than insert.

Dave
Back to top
View user's profile Send private message
thanooz

New User


Joined: 28 Jun 2005
Posts: 99

PostPosted: Mon Jul 25, 2005 8:24 pm    Post subject:
Reply with quote

hi pushp

you need to opemn your file in input and output mode

and access mode is random thn only you can solve that problem other wise you can't solve.

because in above your open a file in extend means it is appending records at end.if you want insert record in middle means it gives what you have mentioned that error becuse after 4 you want write 3 rd record means that is at end it gives out of seqence error. to solve that proble means first you write one record into the file then waht i have mentiond above you have to do like that only.
Back to top
View user's profile Send private message
thanooz

New User


Joined: 28 Jun 2005
Posts: 99

PostPosted: Mon Jul 25, 2005 10:12 pm    Post subject:
Reply with quote

hi


befor inserting record into vsam ksds you have to sort the input file then

apply what you have writen that cobol logic only inthis time never gives warnings.



thanooz
Back to top
View user's profile Send private message
saanjieev

New User


Joined: 25 Jul 2005
Posts: 4
Location: Mumbai, India

PostPosted: Mon Jul 25, 2005 10:32 pm    Post subject: It's good to be precise
Reply with quote

Hi Pushpagiri,

It helps to reply fast if we have precise information available. If you could provide all the inforamtion at first, it could save your time and efforts.

Well! simply, always check FILE CONTROL stmts for access mode, if you get problem in reading or writing a file. If it's right then OPEN mode can be in error. Already it has been suggested by thanooz and others.

Well! sequential access can be used for writing a KSDS only when we write in ascending order of key. So, it is required to have your input file SORTed. If you don't want to SORT input file, change the KSDS access mode to RANDOM. And as you want to write only, open mode OUTPUT is enough.

Reading a record and then updating the same record needs Input/Output OPEN mode. Or reading a record and writing another record in same KSDS needs Input/Output OPEN mode.


And it can help you a lot, if you collect the details of error message.
Back to top
View user's profile Send private message
pushpagiri

New User


Joined: 07 Jul 2005
Posts: 51

PostPosted: Tue Jul 26, 2005 12:17 pm    Post subject: [solved]
Reply with quote

hi,

Finally my fault is in the access mode and open mode.

So in order to insert a record I have to
ACCESS in RANDOM mode
and OPEN in I-O mode.

Thankz to all who have helped me.
Back to top
View user's profile Send private message
praveendon

New User


Joined: 09 Jul 2005
Posts: 2

PostPosted: Sun Jul 31, 2005 4:03 pm    Post subject: How can a JOB be abended thru COBOL program
Reply with quote

Can u please say How can a JOB be abended thru COBOL program.

Advance thanks for u r help

Bye
Praveen
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Mon Aug 01, 2005 12:27 am    Post subject:
Reply with quote

Hi praveendon,

The forum rules state that a new topic be generated for each new ques.

Press the "new topic" button below the text window and re-enter your ques.
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
Goto page 1, 2  Next
Page 1 of 2

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm
No new posts BWO option in VSAM blayek CICS 3 Sat Nov 05, 2016 10:47 am
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


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