View previous topic :: View next topic
|
Author |
Message |
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
How can I remove duplicates from an array using DELDUPS in REXX?
Code: |
/* REXX */
"EXECIO * DISKR DDIN (STEM LINENUM. FINIS "
"FREE FI(DDIN)"
TRACE ?R
ADDRESS ISREDIT
'MACRO (BEGCOL ENDCOL)'
IF BEGCOL = '?' THEN DO
ZEDSMSG = 'DELDUPS BEGCOL,ENDCOL'
ZEDLMSG = 'COMMAND SYNTAX: DELDUP BEGINNING COL, ENDING COL'
SIGNAL QUITME
END
NUMCHECK = DATATYPE(BEGCOL,N) /* DETERMINE IF ANY PARMS HAVE */
IF NUMCHECK /= 1 THEN BEGCOL = 1 /* BEEN PASSED. */
NUMCHECK = DATATYPE(ENDCOL,N)
IF NUMCHECK /= 1 THEN 'ISREDIT (ENDCOL) = LRECL'
'ISREDIT (CURRLINE) = LINENUM .ZFIRST' /* SAVE STARTING RECORD # */
'ISREDIT (LASTLINE) = LINENUM .ZLAST' /* SAVE ENDING RECORD # */
'ISREDIT (CL,CC) = CURSOR' /* SAVE CURSOR POSITION */
DUPCNT = 0
DO CURRLINE = 1 TO LASTLINE - 1
IF CURRLINE > (LASTLINE - 1) THEN LEAVE
'ISREDIT (LINE1) = LINE' CURRLINE
LINE1 = SUBSTR(LINE1,BEGCOL,(ENDCOL - BEGCOL) + 1)
NEXTLINE = CURRLINE + 1
'ISREDIT (LINE2) = LINE' NEXTLINE /* GET NEXT RECORD */
LINE2 = SUBSTR(LINE2,BEGCOL,(ENDCOL - BEGCOL) + 1)
IF LINE1 == LINE2 THEN DO
DUPCNT = DUPCNT + 1
"ISREDIT LABEL " CURRLINE " = .A"
"ISREDIT LABEL " NEXTLINE " = .B"
"ISREDIT DELETE " NEXTLINE
CURRLINE = CURRLINE - 1 ; LASTLINE = LASTLINE - 1
END
END
ZEDSMSG = DUPCNT 'DUPS DELETED'
ZEDLMSG = DUPCNT 'DUPLICATE LINES WERE DELETED'
QUITME:
ADDRESS ISPEXEC
'SETMSG MSG(ISRZ000)'
EXIT 0 |
The above code is hitting "Bad arithmetic conversion" in
Code: |
DO CURRLINE = 1 TO LASTLINE - 1 |
because LASTLINE contains the value 'LASTLINE'., that because of
Code: |
'ISREDIT (LASTLINE) = LINENUM .ZLAST' |
How do I overcome this probe? |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
What is DELDUPS ??? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
DELDUPS seems to be in-house utility, if I got it correct, this edit macro will sort a file and delete the duplicate lines from it. (at least, that's what it does at my shop) |
|
Back to top |
|
|
HameedAli
Active User
Joined: 16 Apr 2009 Posts: 151 Location: India
|
|
|
|
Yes, Anuj you are right.
I don't know how to fix that probe of "Bad arithmetic conversion" |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
looks to me that the code posted is a patchwork of things
Code: |
"EXECIO * DISKR DDIN (STEM LINENUM. FINIS "
"FREE FI(DDIN)" |
have nothing to share with the rest of the code
Code: |
'ISREDIT (CURRLINE) = LINENUM .ZFIRST' /* SAVE STARTING RECORD # */ |
but then after three lines You use CURRLINE as a DO iteration count
Code: |
"ISREDIT LABEL " CURRLINE " = .A"
"ISREDIT LABEL " NEXTLINE " = .B"
|
again... have nothing to share with the rest of the code
furthermore inside the DO loop You change the values of the DO control variables
it' s difficult to interpret and understand somebody' s else code,
it' s even more difficult to do it with sloppy code
clean it up and repost it, You will have more chances of getting help |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Anuj Dhawan wrote: |
DELDUPS seems to be in-house utility, if I got it correct, this edit macro will sort a file and delete the duplicate lines from it. (at least, that's what it does at my shop) |
If that is the case, why not just invoke the site SORT product and save all the faffing about ? |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Quote: |
Yes, Anuj you are right.
I don't know how to fix that probe of "Bad arithmetic conversion" |
I'm not the right person to suggest here-- there are better people here in this Forum when it comes to REXX, have patience some one will be around or follow on what Enrico and Expat has suggested...Good Luck. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Please tell me that I have misread the code. Very easy from the lack of indentation
You are going line by line, comparing against all following lines to see if duplicates exist.
Is this going to run in foreground or background ? Well either way, if my interpretation is correct, this is a criminal and incompetant waste of resource.
At one site, they used a sort routine written in REXX, and I had to investigate what was wrong when a user complained of his job taking over 6 hours and was still running. Over 63,000 records to be sorted using a one line by one line process.
I replaced the inhouse sort routine with a call to DFSORT and the job was finished in less than 45 seconds.
It would be oh so easy to create sort cards and invoke your sort product and save a whole lot of problems and resource.
Also consider the foreground option. If the file is too large to open in edit mode ....... what happens then.
I only hope that my interpretation of the code is wrong, PLEASE let it be wrong |
|
Back to top |
|
|
|