View previous topic :: View next topic |
Author |
Message |
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Wed Aug 11, 2004 12:21 pm Post subject: Delete all records from dataset |
|
|
I have a REXX program that reads records from an input file. If the record meets certain criteria, the program writes (EXECIO DISKW) the record to an output file. Since the output file is allocated with DISP=OLD, the old records in the output file will be overwritten. However, if none of the records satisfies the criteria, I want to delete all the old records from the output file (file with 0 record). I can write an EDIT macro to delete all the records:
Code: |
address ISPEXEC
"LMINIT DATAID(ID) DDNAME(OUTFILE)"
"EDIT DATAID(&ID) MACRO(EMPTYDS)"
"LMFREE DATAID(&ID)"
/* REXX
EMPTYDS macro to delete all records from dataset */
address 'ISREDIT'
'MACRO'
'DELETE ALL .ZFIRST .ZLAST'
'SAVE'
'END'
|
Is there a simpler way to delete all the records? |
|
Back to top |
|
|
superk Advanced
Joined: 19 Dec 2002 Posts: 684 Topics: 5
|
Posted: Wed Aug 11, 2004 2:20 pm Post subject: |
|
|
I prefer SORT to empty a dataset:
Code: |
"ALLOC DD(SORTIN) DA('THE.DATASET') SHR REU"
"ALLOC DD(SORTOUT) DA('THE.DATASET') SHR REU"
"ALLOC DD(SYSOUT) DA(*) REU"
"ALLOC DD(SYSIN) NEW REU RECFM(F B) LRECL(80)"
Queue " OPTION COPY"
Queue " OMIT COND=ALL"
Queue ""
"EXECIO * DISKW SYSIN (FINIS"
"CALL *(SORT)"
"FREE DD(SORTIN SORTOUT SYSIN SYSOUT)"
|
|
|
Back to top |
|
|
ofer71 Intermediate
Joined: 12 Feb 2003 Posts: 358 Topics: 4 Location: Israel
|
Posted: Wed Aug 11, 2004 2:42 pm Post subject: |
|
|
Here is a function I wrote while ago:
Code: | /*------------------------------- REXX -------------------------------
* PROGRAM : EMPTYDSN
* FUNCTION : EMPTY DATASET
* AUTHOR : OFER
* DATE : 03/06/03
* HOW TO USE: X = EMPTYDSN(DSNAME)
* :
*------------------------------------------------------------------*/
ARG DSN
IF DSN = ' ' THEN DO
EXITRC = 99
SIGNAL ENDEXEC
END
DSN = STRIP(DSN,"B","'")
D = OUTTRAP('DUMMY.')
ADDRESS TSO "REPRO INDA('"DSN"') OUTDA('"DSN"') COUNT(0)"
D = OUTTRAP('OFF')
EXITRC = RC
ENDEXEC:
EXIT EXITRC
|
O.
________
silversurfer reviews
Last edited by ofer71 on Sat Feb 05, 2011 11:19 am; edited 1 time in total |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Wed Aug 11, 2004 3:46 pm Post subject: |
|
|
Code: |
"EXECIO 0 DISKW myoutdd ... (OPEN"
"EXECIO 0 DISKW myoutdd ... (FINIS"
|
The first one will open and put the 'file-pointer' before the first record. Next, one will write an EOF marker and close the dataset. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Wed Aug 11, 2004 3:51 pm Post subject: |
|
|
Maybe, this will work too.
Code: |
"EXECIO 0 DISKW myoutdd ... (OPEN FINIS"
|
_________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
semigeezer Supermod
Joined: 03 Jan 2003 Posts: 1014 Topics: 13 Location: Atlantis
|
Posted: Thu Aug 12, 2004 1:12 am Post subject: |
|
|
If you are already doing the LMINIT, just use an LMOPEN for output instead of the EDIT.
(You don't need to code the LMCLOSE --LMFREE will do that for you)
I suspect Cogito-Ergo-Sum's solution is a little faster, but it would not be significant. |
|
Back to top |
|
|
danm Intermediate
Joined: 29 Jun 2004 Posts: 170 Topics: 73
|
Posted: Thu Aug 12, 2004 8:35 am Post subject: |
|
|
Thank you all for the excellent solutions. |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Thu Aug 12, 2004 2:15 pm Post subject: |
|
|
You are welcome. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
coolman Intermediate
Joined: 03 Jan 2003 Posts: 283 Topics: 27 Location: US
|
Posted: Fri Aug 13, 2004 4:12 pm Post subject: |
|
|
Cogito,
Do you still need a "OPEN" out there?
________
DT175
Last edited by coolman on Sat Feb 05, 2011 1:39 am; edited 1 time in total |
|
Back to top |
|
|
Cogito-Ergo-Sum Advanced
Joined: 15 Dec 2002 Posts: 637 Topics: 43 Location: Bengaluru, INDIA
|
Posted: Fri Aug 13, 2004 4:22 pm Post subject: |
|
|
Which one? My second post? (Not sure I understood you correctly...)
That post is just another suggestion; a follow-up to the first one.
In either case, the idea is to open and read zero records. Then, write 0 records again leading to deletion of records.
It is in the manual. _________________ ALL opinions are welcome.
Debugging tip:
When you have eliminated all which is impossible, then whatever remains, however improbable, must be the truth.
-- Sherlock Holmes. |
|
Back to top |
|
|
|
|