Originally posted by Dan Satchell:
Here is one approach.
If you are using something like BY HIGHEST 20 in your report program, you may get more than 20 cities when there are ties. This happens in the CAR example below, where BY HIGHEST 10 SALES returns 11 MODELs instead of 10. The -SET Dialogue Manager logic determines where to split the initial output into two columns. In any case, you need to determine both row and column positions for each set of values. If you know your output will always have exactly 20 cities, it becomes a little simpler - you can skip the Dialogue Manager logic and simply replace variable &COL_SWITCH with the number 10.
TABLE FILE IBISAMP/CAR
BY HIGHEST 10 SALES
BY MODEL
ON TABLE HOLD AS CAR_DATA
END
-*
-RUN
-SET &RPT_LINES = &LINES ;
-SET &HALF = &RPT_LINES / 2 ;
-SET &WHOLE = &HALF * 2 ;
-SET &COL_SWITCH = IF (&WHOLE EQ &RPT_LINES) THEN &HALF ELSE (&HALF + 1);
-*
DEFINE FILE CAR_DATA
COUNTER/I5 = LAST COUNTER + 1 ;
ROW_NBR/I5 = IF (COUNTER FROM 1 TO &COL_SWITCH) THEN COUNTER ELSE (COUNTER - &COL_SWITCH);
COL_NBR/I5 = IF (COUNTER FROM 1 TO &COL_SWITCH) THEN 1 ELSE 2 ;
END
-*
TABLE FILE CAR_DATA
SUM MODEL SALES
BY ROW_NBR NOPRINT
ACROSS COL_NBR NOPRINT
END