View previous topic :: View next topic
|
Author |
Message |
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Hi
I am a newbie to MAINFRAMES, so i need some help on my current task.
I have to write a cobol program which will do following :
Read an input file which looks like this :
Code: |
123456788 XP 20100701 000000002
123456788 XP 20100707 000002006
123456788 XP 20100702 000000014
123456788 XP 20100706 000000002
123456788 YP 20100701 000000004
123456789 XP 20100701 000000002
123456789 XP 20100707 000002006
123456789 XP 20100702 000000014
123456789 XP 20100706 000000002
123456789 YP 20100701 000000004
|
where : 123456789 - admin key
X - code1
P - code2
20100701 - date
000000002 - count
The task is to create a VSAM file to store that the admin has been recieved and when it was received.
In the first run, empty VSAM file will be read.
So as it is not going to find any record, it must insert one record in it.
The record which must be inserted/moved should have the latest date for an admin key.
Thus output VSAM file will have records with unique admin key with the latest date.
Finally output must be like this :
Code: |
123456788 XP 20100707 000002006
123456789 XP 20100707 000002006
|
i would also like to know how will I go ahead and create a new VSAM file to be usied in this program.
Any help would be highly appreciated and it will help me learn. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
Create a cobol layout for the new file (possibly/probably make this a COPY member so other programs can use it).
Use IDCAMS to delete/define the new vsam file.
Write code to read the sequential input and write the output into the vsam file. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
In the first run, empty VSAM file will be read. |
Be careful here -- a VSAM file that has never had a record in it cannot be opened for input; you must write a record and delete that record to be able to open an empty VSAM file. So expecting to define the VSAM file, then read it will cause your program to fail. |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Hello Dick,
Thanks for taking your time to help me with this task. Could you please elaborate on this ?
Thanks again. |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Robert Sample wrote: |
Quote: |
In the first run, empty VSAM file will be read. |
Be careful here -- a VSAM file that has never had a record in it cannot be opened for input; you must write a record and delete that record to be able to open an empty VSAM file. So expecting to define the VSAM file, then read it will cause your program to fail. |
How do I do this ? Please guide.
Thanks |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hello,
I'm not sure why the first run should read an empty vsam file. . . There is no business reason to do this. . .
To make sure there is one record in the file use REPRO to load a record into the file.
What elaboration is needed? Do what is needed for each "step" and the job will be done. You should be able to find everything you need on your system - what you need to do is clone these and modify for your specifics. There are also many examples in our forum.
Suggest you also download the Redbook called VSAM Demystified:
www.redbooks.ibm.com/abstracts/sg246105.html?Open
We will help you work on the code and utility control statements if needed, but will not write them. . . |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Thanks Dick for that manual on VSAM. it will help me a lot. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
You're welcome - good luck
Someone will be here if there are questions,
d |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Hi
I have a VSAM file with a single record say,
Code: |
123456789 20100701 20100707
|
where :
123456789 => admin-id
20100701 => first date
20100707 => last date
Now in my cobol program I read an input sequential file :
say, I have read a record for the same admin :
Code: |
123456789 20100701 20100709
|
But this record has last date higher than the last date of vsam record.
All I want to do is update the VSAM file's last-date, whenever the last date read from sequential file is greater than last-date read of VSAM file.
How do I write this update code for VSAM. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Quote: |
I have a VSAM file |
ESDS VSAM?
KSDS VSAM?
RRDS VSAM?
LDS VSAM?
You are not starting by providing enough information.
The solution will depend upon which kind of VSAM file you have. |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
@Robert Sample
I have a KSDS VSAM file. |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Use REWRITE then. |
|
Back to top |
|
|
techslam
New User
Joined: 03 Dec 2010 Posts: 87 Location: India
|
|
|
|
Hi I have my VSAM definition in cobol program as :
Code: |
FILE-CONTROL.
SELECT INPT-FILE ASSIGN TO FILE1.
SELECT VSAM-FILE ASSIGN TO FILE2.
ORGANIZATION IS INDEXED
ACCESS MODE IS RANDOM
RECORD KEY IS OP-ADMIN-KEY3.
|
But after compilation, I end up with error
Code: |
"ORGANIZATION" WAS INVALID. SCANNING WAS RESUMED AT THE NEXT AREA "A" ITEM, LEVEL-NUMBER, OR THE START OF THE NEXT CLAUSE.
|
What am I doing wrong here ? |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8700 Location: Dubuque, Iowa, USA
|
|
|
|
Code: |
SELECT VSAM-FILE ASSIGN TO FILE2. |
Take the period off -- the other clauses must be part of the SELECT statement.
And why is there no FILE STATUS clause? |
|
Back to top |
|
|
|