SUBROUTINE SCHED_RPT2_PRN( FromDate, ThruDate, SchedTable )
* LIST SCHEDULE JUSTLEN 9 BREAK-ON CUST_CITY "'V'" JUSTLEN 55 PO JUSTLEN 20 SHIP_DATE TOTAL SHIP_QTY JUSTLEN 6  COLHEAD 'Qty' BY INVOICE_IDS INVOICE_IDS JUSTLEN 10 COLHEAD  'Invoice No' TOTAL SHIP_AMOUNT JUSTLEN  14 LIMIT SHIP_DATE FROM "09/01/95" TO "09/04/95" HEADING " Billings by Company 'T' PAGE # 'PP''L' for Selected Dates From (09/01/95 ) Thru (09/04/95)"  ID-SUPP
* 
DECLARE FUNCTION SET_STATUS, SET_FSERROR, SEND_DYN, SEND_INFO, SET_ROWDEF, SET_PRINTER
declare function msg

TheHeader = " Billings by Company 'D' 'T' PAGE # 'P' for Selected Dates From (":oconv( FromDate, 'D2/' ):") Thru (":oconv( ThruDate, 'D2/' ):")"
HeadPos   = '3.5,2,1,1,1.25,1.5'
convert ',' to @fm in HeadPos
ColHeader = "Customer/City" : @vm : "PO" : @vm : "Ship Date" : @vm : "Qty" : @vm : "Invoice No" : @vm : "Ship Amount"
ColHeader<-1> = str( '-', 40 ):@vm:str( '-', 19 ):@vm:str( '-', 9 ):@vm:str( '-', 11 ):@vm:str( '-', 14 ):@vm:str( '-', 17 )
Void = set_printer( 'FONTHEADFOOT' )
Void = set_printer( 'HEADER', TheHeader, HeadPos, ColHeader )
* 
@RECCOUNT=0
FIRST.PASS=1
LAST.RECORD=0
READERR=0
* 
* OPEN DICT AND DATA FILES
* 
OPEN "DICT",SchedTable TO @DICT ELSE RETURN
OPEN "",SchedTable TO FILE.IN ELSE RETURN
* 
* MAKE COLUMN HEADING
* 
* 
* ZERO ACCUMULATORS FOR EACH BREAK
* 
SHIPULQTY.CUSTULCITY.TOTAL=0
SHIPULQTY.CUSTULCITY.COUNT=0
SHIPULQTY.GRAND.TOTAL=0
SHIPULQTY.GRAND.COUNT=0
* 
SHIPULAMOUNT.CUSTULCITY.TOTAL=0
SHIPULAMOUNT.CUSTULCITY.COUNT=0
SHIPULAMOUNT.GRAND.TOTAL=0
SHIPULAMOUNT.GRAND.COUNT=0
* 
* NULL PREVIOUS BREAK BUCKETS
* 
PREV.CUSTULCITY=''
LAST.CUSTULCITY.BREAK = 1
* 
* DEFINE DATE CONSTANTS FOR PRINT LIMITING
* 
TODAY = DATE()
SUNDAY = TODAY - MOD(TODAY,7)
LAST.SUNDAY = TODAY - ( MOD(TODAY-1,7) + 1 )
* 
* 
READRECORD:
* 
* 
* ZERO BREAK FLAGS TO FALSE
* 
CUSTULCITY.BREAK=0
* 
*
READNEXT @ID, WHICH.VALUE ELSE
 IF STATUS() GT 0 THEN
	 STATX = SET_FSERROR()
	 RETURN
 END
 IF @FILE.ERROR<1> EQ 421 THEN
	 STATX = SET_FSERROR()
	 GOTO READRECORD
 END
 IF @FILE.ERROR<1> NE 111 THEN
     @ANS = @FILE.ERROR<1>
	 STATX = set_printer( 'TEXT', {RLIST_TEXT_4} ) 
	 READERR += 1
	 GOTO READRECORD
 END
 LAST.RECORD=1
 CUSTULCITY.BREAK=1
 CUSTULCITY=PREV.CUSTULCITY
END
@FILE.ERROR.MODE=0
* 
S.ATID = @ID
* 
IF FIRST.PASS AND LAST.RECORD THEN
 STATX = set_printer( 'TEXT', {RLIST_TEXT_2} )
 RETURN
END
* 
IF LAST.RECORD THEN GOTO BREAKS
* 
IF @REDUCTION.DONE THEN
 READO @RECORD FROM FILE.IN, @ID ELSE
	 @FILE.ERROR.MODE = 0
	 IF STATUS() GT 0 THEN
	     STATX = SET_FSERROR()
	     RETURN
	 END
	 IF @FILE.ERROR<1> NE 100 THEN
	     READERR += 1
	 END
	 GOTO READRECORD
 END
END
* 
@RECCOUNT += 1
* 
* 
* CALCULATE VALUE(S) FOR COLUMN(S)
* 
S.ATID={@ID}
I.ATID=S.ATID
S.CUSTULCITY={CUST_CITY}
I.CUSTULCITY=S.CUSTULCITY
S.PO={PO}
I.PO=S.PO
M.SHIPULDATE={SHIP_DATE}<1,WHICH.VALUE> ; P.SHIPULDATE=1 ; C.SHIPULDATE=7
* 
* INITIALIZE MULTIVALUE BREAK CHECK VARIABLE
* 
S.SHIPULDATE = M.SHIPULDATE
M.SHIPULQTY={SHIP_QTY}<1,WHICH.VALUE> ; P.SHIPULQTY=1 ; C.SHIPULQTY=7
* 
* INITIALIZE MULTIVALUE BREAK CHECK VARIABLE
* 
S.SHIPULQTY = M.SHIPULQTY
M.INVOICEULIDS={INVOICE_IDS}<1,WHICH.VALUE> ; P.INVOICEULIDS=1 ; C.INVOICEULIDS=7
* 
* INITIALIZE MULTIVALUE BREAK CHECK VARIABLE
* 
S.INVOICEULIDS = M.INVOICEULIDS
M.SHIPULAMOUNT={SHIP_AMOUNT}<1,WHICH.VALUE> ; P.SHIPULAMOUNT=1 ; C.SHIPULAMOUNT=7
* 
* INITIALIZE MULTIVALUE BREAK CHECK VARIABLE
* 
S.SHIPULAMOUNT = M.SHIPULAMOUNT
* 
PREVIOUS.MARK.LEVEL=0
* 
* TEST FOR CONTROL BREAK(S)
* 
IF (S.CUSTULCITY NE PREV.CUSTULCITY) OR CUSTULCITY.BREAK THEN
CUSTULCITY=PREV.CUSTULCITY
PREV.CUSTULCITY=S.CUSTULCITY
CUSTULCITY.BREAK+=1
END
* 
* 
IF FIRST.PASS THEN
FIRST.PASS=0
GOTO DETAIL
END
* 
* 
BREAKS:
* 
* PRINT BREAK TOTAL(S) AND ACCUMULATE TOTAL(S)
* 
* 
IF CUSTULCITY.BREAK THEN
STATX = set_printer('TEXT', "")
PRINTLINE = ""
PRINTLINE := CUSTULCITY:@vm
PRINTLINE := '':@vm
PRINTLINE := '':@vm
PRINTLINE := OCONV(SHIPULQTY.CUSTULCITY.TOTAL ,"MD0,"):@vm
PRINTLINE := '':@vm
PRINTLINE := OCONV(SHIPULAMOUNT.CUSTULCITY.TOTAL ,"MD2,$")
TableColInfo = '<+5040':@vm:'<+2880':@vm:'<+1440':@vm:'>+1440':@vm:'>+1800':@vm:'>+2160'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

STATX = set_printer( 'TEXT', '' )
* 
SHIPULQTY.GRAND.TOTAL+=SHIPULQTY.CUSTULCITY.TOTAL
SHIPULQTY.CUSTULCITY.TOTAL=0
SHIPULQTY.GRAND.COUNT+=SHIPULQTY.CUSTULCITY.COUNT
SHIPULQTY.CUSTULCITY.COUNT=0
SHIPULAMOUNT.GRAND.TOTAL+=SHIPULAMOUNT.CUSTULCITY.TOTAL
SHIPULAMOUNT.CUSTULCITY.TOTAL=0
SHIPULAMOUNT.GRAND.COUNT+=SHIPULAMOUNT.CUSTULCITY.COUNT
SHIPULAMOUNT.CUSTULCITY.COUNT=0
END
* 
* PERFORM LAST RECORD OUTPUT IF DONE
* 
IF LAST.RECORD THEN
STATX = set_printer( 'TEXT', "")
PRINTLINE = ""
PRINTLINE := "***":@vm
PRINTLINE := '':@vm
PRINTLINE := '':@vm
PRINTLINE := OCONV(SHIPULQTY.GRAND.TOTAL ,"MD0,"):@vm
PRINTLINE := '':@vm
PRINTLINE := OCONV(SHIPULAMOUNT.GRAND.TOTAL ,"MD2,$")
TableColInfo = '<+5040':@vm:'<+2880':@vm:'<+1440':@vm:'>+1440':@vm:'>+1800':@vm:'>+2160'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* STATX = SEND_DYN("")
* @ANS=@RECCOUNT
* STATX = SEND_DYN( {RLIST_TEXT_1} )
IF READERR THEN
@ANS=READERR
STATX = set_printer( 'TEXT', {RLIST_TEXT_3} )
END
RETURN
END
* 
DETAIL:
* 
* REMOVE APPROPRIATE VALUE FROM MULTI-VALUED COLUMN(S)
* 
NEW.MARK.LEVEL=0
* 
IF C.SHIPULDATE GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.SHIPULDATE FROM M.SHIPULDATE AT P.SHIPULDATE SETTING C.SHIPULDATE
S.SHIPULDATE=I.SHIPULDATE
END
IF C.SHIPULDATE GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.SHIPULDATE
IF C.SHIPULQTY GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.SHIPULQTY FROM M.SHIPULQTY AT P.SHIPULQTY SETTING C.SHIPULQTY
S.SHIPULQTY=I.SHIPULQTY
END
IF C.SHIPULQTY GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.SHIPULQTY
IF C.INVOICEULIDS GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.INVOICEULIDS FROM M.INVOICEULIDS AT P.INVOICEULIDS SETTING C.INVOICEULIDS
S.INVOICEULIDS=I.INVOICEULIDS
END
IF C.INVOICEULIDS GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.INVOICEULIDS
IF C.SHIPULAMOUNT GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.SHIPULAMOUNT FROM M.SHIPULAMOUNT AT P.SHIPULAMOUNT SETTING C.SHIPULAMOUNT
S.SHIPULAMOUNT=I.SHIPULAMOUNT
END
IF C.SHIPULAMOUNT GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.SHIPULAMOUNT
* 
* DO CONVERSIONS IF ANY
* 
IF S.SHIPULDATE NE "" THEN S.SHIPULDATE=OCONV(S.SHIPULDATE,"D2/")
IF S.SHIPULQTY NE "" THEN S.SHIPULQTY=OCONV(S.SHIPULQTY,"MD0,")
IF S.INVOICEULIDS NE "" THEN S.INVOICEULIDS=OCONV(S.INVOICEULIDS,"MD0")
IF S.SHIPULAMOUNT NE "" THEN S.SHIPULAMOUNT=OCONV(S.SHIPULAMOUNT,"MD2,$")
* 
* DO PRINT LIMITING
* 
IF I.SHIPULDATE GE FromDate AND I.SHIPULDATE LE ThruDate  THEN
GOTO ENDLIMIT
END
IF NEW.MARK.LEVEL THEN GOTO DETAIL
IF WHICH.VALUE THEN GOTO READRECORD
IF PREVIOUS.MARK.LEVEL THEN
* 
GOTO READRECORD
* 
END
S.SHIPULDATE=''
I.SHIPULDATE=''
S.SHIPULQTY=''
I.SHIPULQTY=''
S.INVOICEULIDS=''
I.INVOICEULIDS=''
S.SHIPULAMOUNT=''
I.SHIPULAMOUNT=''
* 
ENDLIMIT:
* 
* ACCUMULATE TOTAL(S)
* 
IF NUM(I.SHIPULQTY) AND I.SHIPULQTY NE "" THEN
SHIPULQTY.CUSTULCITY.TOTAL+=I.SHIPULQTY
SHIPULQTY.CUSTULCITY.COUNT+=1
I.SHIPULQTY=''
END
IF NUM(I.SHIPULAMOUNT) AND I.SHIPULAMOUNT NE "" THEN
SHIPULAMOUNT.CUSTULCITY.TOTAL+=I.SHIPULAMOUNT
SHIPULAMOUNT.CUSTULCITY.COUNT+=1
I.SHIPULAMOUNT=''
END
* 
* PRINT DETAIL LINE
*
PRINTLINE = ""
PRINTLINE := S.CUSTULCITY:@vm
PRINTLINE := S.PO:@vm
PRINTLINE := S.SHIPULDATE:@vm
PRINTLINE := S.SHIPULQTY:@vm
PRINTLINE := S.INVOICEULIDS:@vm
PRINTLINE := S.SHIPULAMOUNT
TableColInfo = '<+5040':@vm:'<+2880':@vm:'<+1440':@vm:'>+1440':@vm:'>+1800':@vm:'>+2160'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* 
IF NEW.MARK.LEVEL THEN
S.CUSTULCITY=''
S.PO=''
S.SHIPULDATE=''
S.SHIPULQTY=''
S.INVOICEULIDS=''
S.SHIPULAMOUNT=''
PREVIOUS.MARK.LEVEL=NEW.MARK.LEVEL
GOTO DETAIL
END
* 
GOTO READRECORD
* 
END

