× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi,

you can get the relative record no with the scalar function RRN(MyTable).
If you want to delete the selected duplicate rows with native I/O, you can
use the relative record no.

As already mentioned in previous threads when deleting a record in SQL by
specifying the relative record no in the where clause, a table scan will be
performed for each record.

An other way would be to delete by using the cursor.
C/EXEC SQL
C+ DECLARE TEST Dynamic SCROLL CURSOR
C+ FOR SELECT
C+ TANUM,
C+ DGID,
C+ DATEX,
C+ LITYPE,
C+ PYAMTP
C+ FROM TIN/TDNTRNMAR
C+ WHERE LITYPE = 'PAYMENT'
C+ ORDER BY TANUM, PYAMTP
C+ FOR Update Of
C/END-EXEC

/Free
Exec SQL Open Test;
Dow 1=1;
Exec SQL Fetch Next from Text
into :TANUM, :DGID, :DATEX, :LITYPE, :PYAMTP;

If SQLSTT = '02000';
Leave;
EndIF;

If TANUM <> :CompTANUM or DGID <> CompDGID or DATEX <> :CompDATEX
Or LITYPE <> :CompLITYPE or PYAMTP <> CompPYATMP;
CompTANUM = TANUM;
CompDGID = DGID;
CompDATEX = DATEX;
CompLITYPE = LITYPE;
CompPYATMP = PYATMP;
Iter;
EndIf;

Exec SQL Delete from TIN/TDNTRNMAR Where current Of Test;
EndDo;

Exec SQL Close Test;
/End-Free


Mit freundlichen Grüßen / Best regards

Birgitta Hauser

"Shoot for the moon, even if you miss, you'll land among the stars." (Les
Brown)
"If you think education is expensive, try ignorance." (Derek Bok)
"What is worse than training your staff and losing them? Not training them
and keeping them!"


-----Ursprüngliche Nachricht-----
Von: rpg400-l-bounces@xxxxxxxxxxxx [mailto:rpg400-l-bounces@xxxxxxxxxxxx] Im
Auftrag von Jim Lowary
Gesendet: Friday, 09. January 2009 17:50
An: rpg400-l@xxxxxxxxxxxx
Betreff: Using SQLRPGLE to find Dup Records and do Delete?

I have a program that is written in SQLRPGLE to find dup records in a
large file (below is the mainline and select routine). Can I get the
RRN of the record from the fetch of the SQL record? If so I can do a
delete that way.

I'd appreciate any help or suggestions (as I'm not much of an SQL person
and have not played one on TV).

Thanks,
-- Jim Lowary

*

* STEP 5: A LOOP IS CREATED IN ORDER TO READ ALL RECORDS FROM

* THE RESULT SET AND PRINT THE DETAILS TO THE REPORT.

C SQLSTT DOWNE '02000'

C SQLSTT ANDNE '24501'

*

C #TANUM IfNE svTANUM

C MoveL(p) #TANUM ckTANUM 1

C MoveL(p) #TANUM svTANUM

C MoveL(p) #PYAMTP svPYAMTP

C Z-Add 0 Kount

C EndIF

C*

C #PYAMTP IfEQ svPYAMTP

C ckTANUM AndEQ '9'

C Kount AndGT 0

C '99998' Scan #DGID Pos 3 0

C If Pos <> 0

C Add #PYAMTP aPYAMTP

C Else
C Add #PYAMTP cPYAMTP
C EndIF
C Add #PYAMTP TPYAMTP
C ExSR ChkHeadings
C Except ErrOrgin
C*
C EndIF
*
C EXSR FETCH
C Add 1 Kount
C ENDDO

**************************************************************
C DECLAR BEGSR
**************************************************************
C/EXEC SQL
C+ DECLARE TEST SCROLL CURSOR FOR SELECT
C+ TANUM,
C+ DGID,
C+ DATEX,
C+ LITYPE,
C+ PYAMTP
C+ FROM TIN/TDNTRNMAR
C+ WHERE LITYPE = 'PAYMENT'
C+ ORDER BY TANUM, PYAMTP
C+ FOR READ ONLY
C/END-EXEC
C ENDSR
*
**************************************************************
C FETCH BEGSR
**************************************************************
* CLEAR THE WORKING FIELDS BEFORE THE SQL STMT POPULATES THEM
C MOVEL *BLANKS #TANUM
C MOVEL *BLANKS #DGID
C MOVEL *BLANKS #DATEX
C MOVEL *BLANKS #LITYPE
C MOVEL *BLANKS #PYAMTP
* READ THE NEXT RECORD FROM THE SQL STMT
C/EXEC SQL
C+ FETCH NEXT FROM TEST INTO
C+ :#TANUM,
C+ :#DGID,
C+ :#DATEX,
C+ :#LITYPE,
C+ :#PYAMTP
C/END-EXEC
C ENDSR


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.