View previous topic :: View next topic
|
Author |
Message |
satish.ms10
Active User
Joined: 10 Aug 2009 Posts: 184 Location: India
|
|
|
|
Hi,
I have REXX program which is writing some data into a new PS file.
Sometimes its is creating empty file.
Now I need to avoid creating empty file.
To do this, I am planning to
1. Close already opened file which is in Write mode.
2. Open the file in read mode.
3. Read all the records into array.
4. Check the count.
4. 1 If Count is ZERO then delete the file.
Please let me know how to close a file in REXX.
I have coded for 2-4 points. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Specifying 'FINIS' as part of an EXECIO statement essentially closes the file:
"EXECIO 0 DISKW ddname (FINIS" |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
Why not just keep a count of the records written and delete the file if the count is zero? This would avoid the extra opening, reading, closing of the file. |
|
Back to top |
|
|
Ronald Burr
Active User
Joined: 22 Oct 2009 Posts: 293 Location: U.S.A.
|
|
|
|
Why read ALL of the records into an array to determine if the file is EMPTY? Why not read just ONE record - if not EOF on the first read, the file is not empty. |
|
Back to top |
|
|
satish.ms10
Active User
Joined: 10 Aug 2009 Posts: 184 Location: India
|
|
|
|
Thanks for your quick reply.
This program is copying joblog from spool by taking jobname and jobid as input.
To do this task, couple of TSO commands are QUEUED and those are executed. Then joblog is getting copied to the PS.
If jobname name or jobid is not present in spool it is creating empty dataset.
Hi Kevin,
I have coded below commands.
Code: |
"ALLOC F(TEMPPRT) DA("XDCNAME") NEW CATALOG REU "
.....
.....
.....
.....
"EXECIO * DISKW TEMPPRT(FINIS"
"ALLOC DD(INFILE) DSN("XDCNAME") OLD"
"EXECIO * DISKR INFILE(FINIS STEM MYVAR."
Say MYVAR.0
If MYVAR.0 = 0 Then
Do
Say 'Either JOBNAME or JOBID is not present in SPOOL'
"DELETE "||XDCNAME
Say 'DELETED.............!: 'XDCNAME
Exit
End |
Here XDCNAME contains 'ABCD.USERID.JOBNAME.JOBLOG' PS name.
It is giving below error message and is creating the file.
Code: |
DATA SET ABCD.USERID.JOBNAME.JOBLOG NOT ALLOCATED, FILE IN US
E |
Please suggest me how to resolve this error and how can I delete if the file is empty. |
|
Back to top |
|
|
superk
Global Moderator
Joined: 26 Apr 2004 Posts: 4652 Location: Raleigh, NC, USA
|
|
|
|
Not really a REXX issue, but anyway ...
You coded:
"ALLOC F(TEMPPRT) DA("XDCNAME") NEW CATALOG REU"
which is a TSO command that allocates the dataset name held in the variable 'XDCNAME' to the TEMPPRT DD name. A disposition of NEW gives exclusive access to the dataset (I presume you already know this).
Then, you coded:
"EXECIO * DISKW TEMPPRT (FINIS"
which, as I mentioned, closes the DD TEMPPRT for WRITE access.
Then, you coded:
"ALLOC DD(INFILE) DSN("XDCNAME") OLD"
which is going to cause a problem. You already have the dataset contained in the variable 'XDCNAME' allocated to the DD name TEMPPRT from above, which as I stated with the NEW disposition has an exclusive lock on that resource. You already have the dataset allocated, so why bother to perform another allocation? But, you're the programmer, so that's your call. You can just forget about performing another allocation, or you have to remove the exclusive lock, either by issuing a TSO FREE command ("FREE F(TEMPPRT)") and/or by remembering to use the REUSE parameter for your subsequent allocate command:
"ALLOC DD(INFILE) DSN("XDCNAME") OLD REU" |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
You did not answer Craq's question:
Quote: |
Why not just keep a count of the records written and delete the file if the count is zero? This would avoid the extra opening, reading, closing of the file. |
I would amend to say: Why allocate and write to it if you have no records to write? That is, why not delay allocating until you know you have data to write?
Use the QUEUED() function to determine if there are records in the queue. |
|
Back to top |
|
|
satish.ms10
Active User
Joined: 10 Aug 2009 Posts: 184 Location: India
|
|
|
|
Thank you very much Kevin and all,
It's working.
I just deleted "ALLOC DD(INFILE) DSN("XDCNAME") OLD" line form code and changed "EXECIO * DISKR INFILE(FINIS STEM MYVAR." line to "EXECIO * DISKR TEMPPRT(FINIS STEM MYVAR.".
Now it is working as expected.
Once again thank you for help. |
|
Back to top |
|
|
UmeySan
Active Member
Joined: 22 Aug 2006 Posts: 771 Location: Germany
|
|
|
|
...just one hint:
If you have Beta Products for JobLog and PrintOut installed, you could use the batch programm BSS01RFF to collect the informations you want. |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
You completely ignored Craq's question and Pedro's remarks:
Pedro wrote: |
You did not answer Craq's question:
Quote: |
Why not just keep a count of the records written and delete the file if the count is zero? This would avoid the extra opening, reading, closing of the file. |
I would amend to say: Why allocate and write to it if you have no records to write? That is, why not delay allocating until you know you have data to write?
Use the QUEUED() function to determine if there are records in the queue. |
Although you've got your result, your program is definitely badly written. |
|
Back to top |
|
|
|