I have a Physical file and this phisical have this field:
&SPLDAT *CHAR 6 SUBSTR(WRKSPLF,89,2)|| SUBSTR(WRKSPLF,86
I need read this file and compare if the field &SPLDAT is equal the variable Sysdate, if this information is equal, only copy this records.
Thanks for Your help
Can you explain exactly what your question is?
Wow, there is a lot wrong with your program! I suspect that you have been dropped in at the deep end.
I assume that the RUNQRY populates your DLTOLDSPLF/REC_SFT file from the QTEMP/WRKSPLF file.
First, you need to clear (CLRPFM) the DLTOLDSPLF/REC_SFT file before you do the RUNQRY, unless you intend to ADD records to those already in that file.
Next, although you declare the file, you are not reading it in the program. You need to do a RCVF command, like this:
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(ENDDATA))
The label ENDDATA: will be on your line 3500.
Now when you test the dates, your &SPLDAT variable will not be empty.
Next, you don’t need the ELSE at line 2700, or the ENDDO at line 3400. The IF by itself is enough to skip for the next record when the dates don’t match.
Next, you don’t need the FMTOPT parameter on the CPYF command, since the TO file will be an exact copy of the FROM file.
Now, your loop to read the file will loop around until it finds a record where the spooled file date matches the system date, and then it will do the CPYF, the CPYTOPCD and the SNDDST and then end.
BUT, if it does NOT find any matching dates, it will STILL do all those things. Your CPYF may fall over if the QTEMP file already exists and there are no records to copy. If the QTEMP file does NOT exist, it will be created and will be empty.
I would suggest that there is no need to read the DLTOLDSPLF/REC_SFT file in your program. There is no need for a loop – you just do the copy. In which case, that part of your program will be a lot simpler.
If you don’t want to email an empty file, then after the CPYF you can use the RTVMBRD command with the NBRCURRCD parameter, which takes a numeric CL variable. If that variable is zero, the file is empty and you can do something different, like sending an email which says ‘There are no spooled files for today’.
That’s pretty much it.
However, I am puzzled that the program title seems to show that this program is to delete old spooled files, but the code extracts information about today’s spooled files and sends the information in an email. Really, you ought to make sure that comments accurately reflect the purpose of a program – otherwise when you come back to it in six months, you will get very confused!
If you DO want to delete old spooled files, one way is to use the “Move Spooled Files using BRM” (MOVSPLFBRM) command to move the spooled files you select to a ‘junk’ output queue, then just clear that queue using the CLROUTQ command.