View previous topic :: View next topic |
Author |
Message |
Pudah Beginner
Joined: 20 Jun 2003 Posts: 27 Topics: 8 Location: East of the Rock, West of the Hard Place
|
Posted: Sat Feb 17, 2007 9:35 am Post subject: Help with ALTERNATE INDEX |
|
|
I'm trying to write a COBOL program to process a VSAM file that uses an alternate index. The program reads a flat file that contains a list of customer numbers and invoice numbers. I need to take a customer number from the input file and look up that customer on a VSAM file of invoices and get all invoices for that customer number. There can be multiple invoices for a given customer.
Assume the following FB LRECL=225 file INVOICES.REPRO:
Code: |
A12345678 1111111111111 AJ CUWYGEN 76;LM VIW LDJTK8RF25 K982NM APQ
A23456789 4444444444444 0MI3R 4IOHJBM JHN GN FIJH OIUHERU4T59 IJEF
B12345678 4444444444444 OKND84NV 4804B V984 R894 IU8MV MI95M 95Y I5
B22222221 3333333333333 AKLM 5UERY7 0N 873 POJK39R JNC894N DUH37
B22222222 3333333333333 MOPJV 8945N VUIHA33 UWE734 95N EUH8 IREJ9
B22222223 3333333333333 3MD 6P58 E9UN Z893 80 OIJR84 IRJTN I39UT
B22222224 3333333333333 OLX RKGINH EWJIHT KDFRT09I 9I3 IEWJ34 IOU34
B22222225 3333333333333 34 JRGT RKJG840 90RNMG9IY5 904MV094U 094M IK
C12345678 4444444444444 OKND84NV 4804B V984 R894 IU8MV MI95M 95Y I5
C23456789 5555555555555 54IKV RIU4 BIJR 9IR595M L48UTKJN 094T OPUT
N00200200 2222222222222 LJDFG 45 KJ76 N 4UHT 37Y5H58H WEIHJR58 984
N11111111 1111111111111 KDNGFUIVHF HEV JHSY KEJFO UWHR VJBVKLMJBI
R11111111 1111111111111 7MPSOJR YOIJND74 IJ5IT H4 T OI54 IH4 4940V
|
I have used it to load up my VSAM file as follows:
Code: |
//DELDEF EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DELETE (INVOICES.TABLE) CLUSTER
DEFINE CLUSTER -
(NAME (INVOICES.TABLE) -
SPEED -
NOREUSE -
CYLINDERS (3 1) -
FREESPACE (0 0) -
KEYS (26 0) -
RECORDSIZE (225 225) -
INDEXED) -
DATA -
(NAME (INVOICES.TABLE.DATA) ) -
INDEX -
(NAME (INVOICES.TABLE.INDEX) )
/*
//REPRO EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSUT1 DD DSN=INVOICES.REPRO,DISP=SHR
//SYSIN DD *
REPRO INFILE(SYSUT1) OUTDATASET(INVOICES.TABLE)
/*
//AIX EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE ALTERNATEINDEX -
(NAME (INVOICES.TABLE.AIX) -
RELATE (INVOICES.TABLE) -
KEYS (10 13) -
RECORDSIZE (38 13015) -
NONUNIQUEKEY)
/*
//DEFPATH EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//SYSIN DD *
DEFINE PATH -
(NAME (INVOICES.TABLE.APATH) -
PATHENTRY (INVOICES.TABLE) )
/*
//BLDINDX EXEC PGM=IDCAMS
//SYSPRINT DD SYSOUT=*
//BASEDD DD DSN=INVOICES.TABLE,DISP=SHR
//AIXDD DD DSN=INVOICES.TABLE.AIX,DISP=SHR
//SYSIN DD *
BLDINDEX INFILE(BASEDD) OUTFILE(AIXDD)
/*
|
The FILE-CONTROL entry for my VSAM file is:
Code: |
SELECT INVOICE-TABLE ASSIGN TO UT-V-INVTABLE
ORGANIZATION IS INDEXED
ACCESS IS DYNAMIC
RECORD KEY IS INVOICE-ACCOUNT
ALTERNATE RECORD KEY IS
ACCOUNT-NUMBER
WITH DUPLICATES
FILE STATUS IS
INVOICE-FILE-STATUS
INVOICE-VSAM-STATUS.
|
The FILE-SECTION entry is:
Code: |
FD INVOICE-TABLE.
01 INVOICE-TABLE-RECORD.
05 INVOICE-ACCOUNT.
10 INVOICE-NUMBER PIC X(012).
10 FILLER PIC X(001).
10 ACCOUNT-NUMBER PIC X(010).
10 ACCOUNT-NUMBER-SFX PIC X(003).
05 FILLER PIC X(199).
|
The code that I am using to get an invoice from the VSAM file is as follows:
Code: |
RECORD-LOOKUP.
MOVE SPACES TO INVOICE-ACCOUNT.
MOVE IN-ACCOUNT-NUMBER(1:10) TO ACCOUNT-NUMBER.
DISPLAY 'SEARCH KEY: ' ACCOUNT-NUMBER.
READ INVOICE-TABLE KEY IS ACCOUNT-NUMBER.
DISPLAY 'READ STATUS: ' INVOICE-FILE-STATUS.
IF INVOICE-READ-NOT-FOUND
PERFORM NOT-FOUND-RTN
THRU NOT-FOUND-RTN-EXIT
ELSE
PERFORM FOUND-RTN
THRU FOUND-RTN-EXIT
END-IF.
|
The FOUND and NOT-FOUND routines are just DISPLAY statements.
When I run this program, it doesn't find records that I know to be on the file. Here is my execution JCL:
Code: |
//STEP01 EXEC PGM=ALTINDEX
//STEPLIB DD DSN=MY.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSABOUT DD SYSOUT=*
//*
//INPUTLST DD *
3333333333333 B22222223
5555555555555 C23456789
6666666666666 R00000000
//*
//INVTABLE DD DSN=INVOICES.TABLE,DISP=OLD
//INVTABL1 DD DSN=INVOICES.TABLE.APATH,DISP=OLD
//*
|
Here are the DISPLAYs produced by the program when I run it:
Code: |
********************************* TOP OF DATA **********************************
GOT TO PROCESS-INPUTLST
SEARCH KEY: 3333333333
READ STATUS: 23
RECORD NOT FOUND: 3333333333333 B22222223
SEARCH KEY: 5555555555
READ STATUS: 23
RECORD NOT FOUND: 5555555555555 C23456789
SEARCH KEY: 6666666666
READ STATUS: 23
RECORD NOT FOUND: 6666666666666 R00000000
******************************** BOTTOM OF DATA ********************************
|
This says that file status 2 is an invalid key and 3 means that "An attempt was made to randomly access a record that does not exist in the file, or a START or random READ statement was attempted on an optional input file that was not present." But I don't understand what is invalid about my key, and the records I am looking for are definitely on the VSAM file.
I have read thru the Enterprise COBOL Programming Guide. I've read thru lots of threads here at the forum. But I cannot figure out what I have done wrong that is causing the program not to work. I'm sure I must be looking past something obvious but I just can't see the problem. I would be grateful if any of you look over this and help me get this to work. |
|
Back to top |
|
 |
shakkia Beginner
Joined: 05 Apr 2006 Posts: 9 Topics: 3 Location: India
|
Posted: Mon Feb 19, 2007 11:53 pm Post subject: |
|
|
As per your declarartion,RECORD KEY IS INVOICE-ACCOUNT and ALTERNATE RECORD KEY IS ACCOUNT-NUMBER. So your read statement cannot have account number as the reord key , it should be the Alternate record key.
Change it as READ INVOICE-TABLE ALETRNATE RECORD KEY IS ACCOUNT-NUMBER.
I hope this is the problem and it helps |
|
Back to top |
|
 |
Pudah Beginner
Joined: 20 Jun 2003 Posts: 27 Topics: 8 Location: East of the Rock, West of the Hard Place
|
Posted: Tue Feb 20, 2007 5:04 am Post subject: |
|
|
Thanks shakkia, but that produces a compiler error. |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Tue Feb 20, 2007 3:29 pm Post subject: |
|
|
I hope you are using the PATH dataset name in your run JCL? _________________ Regards,
Programmer |
|
Back to top |
|
 |
Pudah Beginner
Joined: 20 Jun 2003 Posts: 27 Topics: 8 Location: East of the Rock, West of the Hard Place
|
Posted: Tue Feb 20, 2007 7:37 pm Post subject: |
|
|
Execution JCL is shown above. Here is is again:
Code: |
//STEP01 EXEC PGM=ALTINDEX
//STEPLIB DD DSN=MY.LOADLIB,DISP=SHR
//SYSOUT DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSUDUMP DD SYSOUT=*
//SYSABOUT DD SYSOUT=*
//*
//INPUTLST DD *
3333333333333 B22222223
5555555555555 C23456789
6666666666666 R00000000
//*
//INVTABLE DD DSN=INVOICES.TABLE,DISP=OLD
//INVTABL1 DD DSN=INVOICES.TABLE.APATH,DISP=OLD
//* |
|
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Tue Feb 20, 2007 8:01 pm Post subject: |
|
|
Change the SELECT statement in your program as follows:
SELECT INVOICE-TABLE ASSIGN TO UT-V-INVTABL1 _________________ Regards,
Programmer |
|
Back to top |
|
 |
Pudah Beginner
Joined: 20 Jun 2003 Posts: 27 Topics: 8 Location: East of the Rock, West of the Hard Place
|
Posted: Wed Feb 21, 2007 5:44 am Post subject: |
|
|
Thanks for the suggestion Programmer. Making that change does not alter the output of the program. It is getting status code 23 on all attempts to read from the VSAM file with the alternate key. |
|
Back to top |
|
 |
kolusu Site Admin

Joined: 26 Nov 2002 Posts: 12378 Topics: 75 Location: San Jose
|
Posted: Wed Feb 21, 2007 9:16 am Post subject: |
|
|
programmer1 wrote: | Change the SELECT statement in your program as follows:
SELECT INVOICE-TABLE ASSIGN TO UT-V-INVTABL1 |
I just curious as to what exactly do you think will the above statement make any difference?
Kolusu _________________ Kolusu
www.linkedin.com/in/kolusu |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Wed Feb 21, 2007 11:25 am Post subject: |
|
|
I somehow thought that we need to use the PATH dataset as the physical file for a Cobol program. Now I know for sure that I was wrong. _________________ Regards,
Programmer |
|
Back to top |
|
 |
programmer1 Beginner
Joined: 18 Feb 2004 Posts: 138 Topics: 14
|
Posted: Wed Feb 21, 2007 1:21 pm Post subject: |
|
|
Quote: |
DEFINE PATH -
(NAME (INVOICES.TABLE.APATH) -
PATHENTRY (INVOICES.TABLE) )
|
Change the above statements to:
DEFINE PATH -
(NAME (INVOICES.TABLE.APATH) -
PATHENTRY (INVOICES.TABLE.AIX) ) _________________ Regards,
Programmer |
|
Back to top |
|
 |
Pudah Beginner
Joined: 20 Jun 2003 Posts: 27 Topics: 8 Location: East of the Rock, West of the Hard Place
|
Posted: Wed Feb 21, 2007 6:15 pm Post subject: |
|
|
Programmer, that did the trick. I am now getting the expected status codes:
Code: | GOT TO PROCESS-INPUTLST
SEARCH KEY: 3333333333
READ STATUS: 02
RECORD FOUND: B22222221 3333333333333
SEARCH KEY: 5555555555
READ STATUS: 00
RECORD FOUND: C23456789 5555555555555
SEARCH KEY: 6666666666
READ STATUS: 23
RECORD NOT FOUND: 6666666666666 R00000000
|
I'll have to reread the manuals to see what I missed, as I don't recall seeing things set up this way. But thanks a ton for your help. It is greatly appreciated! |
|
Back to top |
|
 |
|
|