I'm getting different output for these two sort cards, can someone tell me why?

1.

``INCLUDE COND=((1,3,CH,NE,C'ABC',AND,5,3,CH,NE,C'PQR'),OR,(1,3,CH,NE,C'CAB'),OR,(1,3,CH,NE,C'CBA'),OR,(1,3,CH,NE,C'ABC',AND,5,3,CH,NE,C'PQR'))SORT FIELDS=COPY``

2.

`` OMIT COND=((1,3,CH,EQ,C'ABC',AND,5,3,CH,EQ,C'PQR'),OR,(1,3,CH,EQ,C'CAB'),OR,(1,3,CH,EQ,C'CBA'),OR,(1,3,CH,EQ,C'ABC',AND,5,3,CH,EQ,C'PQR'))SORT FIELDS=COPY``

This is basically, INCLUDE when NOT-EQUAL and OMIT when EQUAL.

The problem is you have not reversed the and's and or's. This means they are very different sort tests so will give different answers

If you look at the first Test, in particular:

``````          (1,3,CH,NE,C'CAB'),OR,
(1,3,CH,NE,C'CBA')
``````

Is always true,

While the following is false when chars 1,3 is anything but CAB or CBA:

``````          (1,3,CH,EQ,C'CAB'),OR,
(1,3,CH,EQ,C'CBA')
``````

with boolean logic, the rules are

`````` not (a and b) = (not A) or (not b)
not (a or b) = (not A) and (not b)
``````

So when changing from omit to include, you must reverse the And & or's

``````OMIT COND=((1,3,CH,EQ,C'ABC',AND,5,3,CH,EQ,C'PQR'),OR,
(1,3,CH,EQ,C'CAB'),OR,
(1,3,CH,EQ,C'CBA'),OR,
(1,3,CH,EQ,C'ABC',AND,5,3,CH,EQ,C'PQR'))
SORT FIELDS=COPY
``````

becomes:

``````INCLUDE COND=((1,3,CH,NE,C'ABC',or,5,3,CH,NE,C'PQR'),and,
(1,3,CH,NE,C'CAB'),and,
(1,3,CH,NE,C'CBA'),and,
(1,3,CH,NE,C'ABC',or,5,3,CH,NE,C'PQR'))
SORT FIELDS=COPY
``````

Top