0

I have a question about removing duplicates in a table (rexx language), I am on netphantom applications that are using the rexx language.
I need a sample on how to remove the duplicates in a table.

I do have a thoughts on how to do it though, like using two loops for these two tables which are A and B, but I am not familiar with this.

My situation is:

rc = PanlistInsertData('A',0,SAMPLE)

TABLE A (this table having duplicate data)

123   
1   
1234   
12   
123   
1234   

I need to filter out those duplicates data into TABLE B like this:

123   
1234   
1   
12    
zx485
  • 28,498
  • 28
  • 50
  • 59
lye yan nian
  • 143
  • 2
  • 12

2 Answers2

3

You can use lookup stem variables to test if you have already found a value. This should work (note I have not tested so there could be syntax errors)

no=0;
yes=1

lookup. = no   /* initialize the stem to no, not strictly needed */
j=0
do i = 1 to in.0
   v = in.i
   if lookup.v <> yes then do
       j = j + 1
       out.j = v
       lookup.v = yes
   end
end
out.0 = j
Bruce Martin
  • 10,358
  • 1
  • 27
  • 38
  • That's a nice way to use a Rexx-y idiom instead of merely writing something loop-y that you could write in any language. – Ross Patterson Jan 21 '17 at 17:54
  • 1
    thanks Ross, as well as being shorter, it should be faster for large table (provided the stem lookup is efficient). Stem variables where always one of the features of Rexx so might as well use them – Bruce Martin Jan 22 '17 at 03:02
0

You can eliminate the duplicates by :

  1. If InStem first element, Move the element to OutStem Else check all the OutStem elements for the current InStem element
  2. If element is found, Iterate to the next InStem element Else add InStem element to OutStem

Code Snippet :

/*Input Stem - InStem.
  Output Stem - OutStem.
  Array Counters - I, J, K */

J = 1
DO I = 1 TO InStem.0
   IF I = 1 THEN
      OutStem.I = InStem.I
   ELSE
      DO K = 1 TO J
         IF (InStem.I ?= OutStem.K) & (K = J) THEN
         DO
            J = J + 1
            OutStem.J = InStem.I
         END
         ELSE
         DO
            IF (InStem.I == OutStem.K) THEN
               ITERATE I
         END
      END
END
OutStem.0 = J

Hope this helps.

Ross Patterson
  • 9,527
  • 33
  • 48
learner66666666
  • 167
  • 1
  • 1
  • 15