|
#1
|
|||
|
|||
|
File handling using CL
I have to create a report on a weekly basis.
I have created a temporary file TSTCLWL which contains the data along with the transaction date. This file is read to generate the report. This is the CL pgm which invokes the CBL pgm PGM DCLF TSTCLWL RCVF TSTCLWL OVRDBF FILE(CLM50) OPNQRYF FILE((CLM50)) QRYSLT(&QRY) CALL PGM(CLMLODREP) CLOF OPNID(CLM50) DLTOVR FILE(CLM50) ENDPGM NOTE: TSTCLWL is read to get the transaction date, the report would be generated for the records created between this date and the current date. The current date would be updated in the file after the report is generated. In the COBOL pgm CLMLODREP, I have opened the file TSTCLWL in output mode to write the new records. During execution this is the error I get when I open the file in OUTPUT mode; Member TSTCLWL already in use. File TSTCLWL cannot be opened OUTPUT. Pointer not set for location referenced. Instead if I open the file I-O, there is no problem Could anyone help me out with this? |
|
#2
|
|||
|
|||
|
File Handling using CL
Kavitha,
When you open a file in OUTPUT mode, the system does a CLRPFM behind the scenes which requires an exclusive lock on the file. Since you already have it open by the CL program it is "in-use" and can't be cleared. If your trying to read a single record via CL from the TSTCLWL file to get the date range then you need to do a CLOF prior to calling CLMLODREP. Of course, you also need to pass these parameters to your program. Terry |
|
#3
|
|||
|
|||
|
Terry,
I tried giving CLOF for TSTCLWL before invoking CLMLODREP, but i get the error "No file open with the identifier TSTCLWL". If I'm not wrong, CLOF can be used only when OPNQRYF & OPNDBF are used, isn't it? Kavitha |
|
#4
|
|||
|
|||
|
Correct
You're correct, CLOF closes an OPNQRYF or an OPNDBF, it does not close a file that's opened for reading in a CL program.
There's no way to explicitly close a file in a CL program. The file will be closed either when the program returns (ends) or when you reach the end of the file with RCVF and get a CPF0864 error. If the TSTCLWL file has only one record in it (that's what it sounds like from your description) you should be able to simply read it again to close it, if that makes sense... |
|
#5
|
|||
|
|||
|
Kavitha,
You are correct! I could have sworn that you could do this via the CLOF command. Sorry for misleading you - next time I'll read the help panel thoroughly :( Another way of accomplishing this is to open TSTCLWL as an input file, read the first record, close it, then open it as an output file. I know this works because I've done it plenty of times :) Is there any reason you need to read the TSTCLWL file from the CL program? If so, you could also create a small stub program in RPG/Cobol to read the file and return the values to your CL program via parameters. Terry |
|
#6
|
|||
|
|||
|
Or...
If this is the only place where this is used, or few other programs that access the file.
Put the dates into a DATAAREA Use RTVDTAAARA, etc. in the CL Use appropriate opcodes in other languages G. Peter |
|
#7
|
|||
|
|||
|
Forcing a file closed
Assuming you need to read the first record and then close the file which contains more records, this should work.
DCLF FILE(TSTCLWL) OVRDBF FILE(TSTCLWL) SHARE(*YES) OPNDBF FILE(TSTCLWL) OPTION(*INP) RCVF POSDBF OPNID(TSTCLWL) POSITION(*END) RCVF MONMSG MSGID(CPF0864) CLOF OPNID(TSTCLWL) DLTOVR FILE(TSTCLWL) |
| Thread Tools | |
| Display Modes | |
|
|