Focal Point
Sorting Problem

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/3121019331

November 02, 2005, 06:16 PM
Vickie
Sorting Problem
I need to fill 2 buckets. One that has all people WITH apples and with other fruits. The other that has people WITHOUT apples and with other fruits.

File contains:

John, apples
John, bananas
John, peaches
Sue, bananas
Sue, peaches
Fred, apples
Fred, oranges

Sorting by fruit, then by name will give me output showing John, Sue and Fred displayed multiple times for each type of fruit available.

How do I test for the existence of an apple which will determine which bucket a person and ALL his fruit will dump into?

Would appreciate any help anyone can give me.

Thanks! vickie
November 02, 2005, 06:42 PM
ET
Here is one way. Mainframe focus 7.11. I'm sure there are many others that are better. Using the Car file, this creates a report separating cars that have coupes and cars that do not have coupes.

TABLE FILE CAR
PRINT BODYTYPE BY CAR UNDER-LINE
BY MODEL
END

PAGE 1


CAR MODEL BODYTYPE
--- ----- --------
ALFA ROMEO 2000 GT VELOCE COUPE
2000 SPIDER VELOCE ROADSTER
2000 4 DOOR BERLINA SEDAN
--------------------------------------------------------
AUDI 100 LS 2 DOOR AUTO SEDAN
--------------------------------------------------------
BMW 2002 2 DOOR SEDAN
2002 2 DOOR AUTO SEDAN
3.0 SI 4 DOOR SEDAN
3.0 SI 4 DOOR AUTO SEDAN
530I 4 DOOR SEDAN
530I 4 DOOR AUTO SEDAN
--------------------------------------------------------
DATSUN B210 2 DOOR AUTO SEDAN
--------------------------------------------------------
JAGUAR V12XKE AUTO CONVERTIBLE
XJ12L AUTO SEDAN
--------------------------------------------------------
JENSEN INTERCEPTOR III SEDAN
--------------------------------------------------------
MASERATI DORA 2 DOOR COUPE
--------------------------------------------------------
PEUGEOT 504 4 DOOR SEDAN
--------------------------------------------------------
TOYOTA COROLLA 4 DOOR DIX AUTO SEDAN
--------------------------------------------------------
TRIUMPH TR7 HARDTOP
--------------------------------------------------------


DEFINE FILE CAR
COUPECNT/I1=IF BODYTYPE EQ 'COUPE' THEN 1 ELSE 0;
END
TABLE FILE CAR
SUM COUPECNT
BY CAR
PRINT BODYTYPE BY CAR UNDER-LINE
BY MODEL
ON TABLE HOLD
END
DEFINE FILE HOLD
MSG1/A30=IF COUPECNT GT 0 THEN 'CARS LINES WITH COUPES' ELSE
'CARS LINES WITH WITHOUT COUPES' ;
END
TABLE FILE HOLD
PRINT BODYTYPE BY MSG1 NOPRINT BY CAR UNDER-LINE
BY MODEL
ON MSG1 SUBHEAD
"<MSG1 </1"
END


CAR MODEL BODYTYPE
--- ----- --------
CARS LINES WITH COUPES

ALFA ROMEO 2000 GT VELOCE COUPE
2000 SPIDER VELOCE ROADSTER
2000 4 DOOR BERLINA SEDAN
--------------------------------------------------------
MASERATI DORA 2 DOOR COUPE
--------------------------------------------------------
CARS LINES WITH WITHOUT COUPES

AUDI 100 LS 2 DOOR AUTO SEDAN
--------------------------------------------------------
BMW 2002 2 DOOR SEDAN
2002 2 DOOR AUTO SEDAN
3.0 SI 4 DOOR SEDAN
3.0 SI 4 DOOR AUTO SEDAN
530I 4 DOOR SEDAN
BMW 530I 4 DOOR AUTO SEDAN
--------------------------------------------------------
DATSUN B210 2 DOOR AUTO SEDAN
--------------------------------------------------------
JAGUAR V12XKE AUTO CONVERTIBLE
XJ12L AUTO SEDAN
--------------------------------------------------------
JENSEN INTERCEPTOR III SEDAN
--------------------------------------------------------
PEUGEOT 504 4 DOOR SEDAN
--------------------------------------------------------
TOYOTA COROLLA 4 DOOR DIX AUTO SEDAN
--------------------------------------------------------
TRIUMPH TR7 HARDTOP
--------------------------------------------------------


END OF REPORT
November 02, 2005, 06:58 PM
Vickie
Thanks! Looks like it's exactly what I need...vickie
November 08, 2005, 01:25 PM
Vickie
Thanks, ET, the above code worked fine. But apparently not what was wanted.

I need to isolate all people who hold ONLY apples and not any other fruit. How would I adjust the code to accomplish this? My sample scenario has no individuals with apples only, but that is what I need to identify.

I've been playing around, hoping to get the right output, but have not been successful.

Any ideas? Thanks, vickie
November 08, 2005, 01:50 PM
mgrackin
Try the following example. This will give you cars that ONLY have a SEDAN bodytype.

The following finds CARs that have other BODYTYPEs and puts their names into a save file.

TABLE FILE CAR
BY CAR
WHERE BODYTYPE NE 'SEDAN'
ON TABLE SAVE AS 'OTHRMODL'
END

The following then uses the save file to EXCLUDE them from a report so that CARs which only offer a BODYTYPE of SEDAN are shown.

TABLE FILE CAR
PRINT BODYTYPE
BY COUNTRY BY CAR BY MODEL
IF CAR NE (OTHRMODL)
END
November 08, 2005, 02:06 PM
JimRice
Here's another idea:

This will give you cars that have only bodytype = coupe.

DEFINE FILE CAR
COUPE_CNT/I5 = IF BODYTYPE EQ 'COUPE' THEN 1 ELSE 0;
OTHER_CNT/I5 = IF BODYTYPE EQ 'COUPE' THEN 0 ELSE 1;
TOTAL_CNT/I5 = 1;
END
TABLE FILE CAR
SUM
COUPE_CNT
OTHER_CNT
TOTAL_CNT
BY CAR
PRINT BODYTYPE
BY CAR
BY MODEL
ON TABLE HOLD AS HOLD1
END
-*
TABLE FILE HOLD1
PRINT
MODEL
BODYTYPE
BY CAR
BY COUPE_CNT
BY OTHER_CNT
BY TOTAL_CNT
WHERE COUPE_CNT GT 0
WHERE OTHER_CNT EQ 0
END

Jim
November 08, 2005, 02:16 PM
mgrackin
Jim's solution could be reduced to one pass and no HOLD file by using the WHERE TOTAL selection statement.

DEFINE FILE CAR
COUPE_CNT/I5 = IF BODYTYPE EQ 'COUPE' THEN 1 ELSE 0;
OTHER_CNT/I5 = IF BODYTYPE EQ 'COUPE' THEN 0 ELSE 1;
TOTAL_CNT/I5 = 1;
END
TABLE FILE CAR
SUM COUPE_CNT OTHER_CNT TOTAL_CNT
BY CAR
PRINT BODYTYPE
BY CAR BY MODEL
WHERE TOTAL COUPE_CNT GT 0
WHERE TOTAL OTHER_CNT EQ 0
END
November 08, 2005, 02:21 PM
Vickie
Thank you both for the quick response! Will try what you've suggested.

vickie