Search code examples
openedgeprogress-4gl

Algorithm for skipping or deleting "mirror" data


I am reading in a file that looks like this:


line#        person-pin   reciprocal-person-pin  relationship   reciprocal-relationship
1             2942         3911                   son            mother                     
2             3911         2560                   client         financial advisor
3             3911         1195                   employee       employer
4             3911         1190                   church member  church
5             3911         2942                   mother         son
6             3911         3910                   mother         daughter
7             3911         3912                   mother         daughter
8             3911         5062                   wife           husband

As you see in this data, line 5 is a "mirror" of line 1 (same values but flip-flopped). I want to skip one of these rows, not both. Either the first 2942 - 3911 (line 1) can be retained, or 3911 - 2942 (5) can be retained. I'd kind of prefer the "mirror" line 5 to stay but it's not that important.

I tried this algorithm below, but it deletes/skips over all the rows - the pair and its mirror - rather than just skipping one of them.

Any thoughts?? I will keep working on this, but I'm stumped and would love some clever ideas.

FOR EACH ttRelationshipData:

    FIND FIRST ttRelationshipData2 WHERE ttRelationshipData.person-pin EQ ttRelationshipData2.reciprocal-person-pin
                                     AND ttRelationshipData.reciprocal-person-pin EQ ttRelationshipData2.person-pin NO-LOCK NO-ERROR.

    IF AVAILABLE ttRelationshipData2 THEN NEXT.
    ELSE DO:
        CREATE ttRelationship.
        ASSIGN
            ttRelationship.alpha-pin = ttRelationshipData.constituent-pin
            ttRelationship.alpha-role = ttRelationshipData.constituent-relationship-name
            ttRelationship.bravo-pin =  ttRelationshipData.related-constituent-pin
            ttRelationship.bravo-role = ttRelationshipData.relatedconstituent-rel-name.
    END.
END.

The output would look like this:


line#        person-pin   reciprocal-person-pin  relationship   reciprocal-relationship
                  
1             3911         2560                   client         financial advisor
2             3911         1195                   employee       employer
3             3911         1190                   church member  church
4             3911         2942                   mother         son
5             3911         3910                   mother         daughter
6             3911         3912                   mother         daughter
7             3911         5062                   wife           husband


Solution

  • Your test will be true for both rows 1 and 5, so both are skipped, test for the ttRelationShip table instead.

    I made some other changes to your code

    • NO-LOCK does not apply to temp-tables
    • alternate styling to avoid horizontal scrollbars
    • after then next you don't need the else block
    • use labels on next
    CreateLoop:
    FOR EACH ttRelationshipData:
    
        FIND ttRelationship
            WHERE ttRelationship.alpha-pin = ttRelationshipData.related-constituent-pin
              AND ttRelationship.bravo-pin = ttRelationshipData.constituent-pin
            NO-ERROR.
    
        IF AVAILABLE ttRelationship THEN NEXT CreateLoop.
    
        CREATE ttRelationship.
        ASSIGN
            ttRelationship.alpha-pin = ttRelationshipData.constituent-pin
            ttRelationship.alpha-role = ttRelationshipData.constituent-relationship-name
            ttRelationship.bravo-pin =  ttRelationshipData.related-constituent-pin
            ttRelationship.bravo-role = ttRelationshipData.relatedconstituent-rel-name.
    
    END.