IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Open a PS in read mode from write mode


IBM Mainframe Forums -> CLIST & REXX
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 184
Location: India

PostPosted: Fri Apr 16, 2010 7:27 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Apr 16, 2010 7:31 pm
Reply with quote

Specifying 'FINIS' as part of an EXECIO statement essentially closes the file:

"EXECIO 0 DISKW ddname (FINIS"
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Fri Apr 16, 2010 7:38 pm
Reply with 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.
Back to top
View user's profile Send private message
Ronald Burr

Active User


Joined: 22 Oct 2009
Posts: 293
Location: U.S.A.

PostPosted: Fri Apr 16, 2010 7:49 pm
Reply with quote

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
View user's profile Send private message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 184
Location: India

PostPosted: Fri Apr 16, 2010 7:54 pm
Reply with quote

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
View user's profile Send private message
superk

Global Moderator


Joined: 26 Apr 2004
Posts: 4652
Location: Raleigh, NC, USA

PostPosted: Fri Apr 16, 2010 8:52 pm
Reply with quote

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
View user's profile Send private message
Pedro

Global Moderator


Joined: 01 Sep 2006
Posts: 2547
Location: Silicon Valley

PostPosted: Sat Apr 17, 2010 1:18 am
Reply with quote

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
View user's profile Send private message
satish.ms10

Active User


Joined: 10 Aug 2009
Posts: 184
Location: India

PostPosted: Mon Apr 19, 2010 2:47 pm
Reply with quote

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
View user's profile Send private message
UmeySan

Active Member


Joined: 22 Aug 2006
Posts: 771
Location: Germany

PostPosted: Mon Apr 19, 2010 4:48 pm
Reply with quote

...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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Mon Apr 19, 2010 10:21 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> CLIST & REXX

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts HILITE on Browse mode? TSO/ISPF 2
No new posts Error to read log with rexx CLIST & REXX 11
No new posts Write line by line from two files DFSORT/ICETOOL 7
No new posts Calling Java method from batch COBOL ... COBOL Programming 5
Search our Forums:

Back to Top