COMPILE SUBROUTINE SCHED_RPT3_PRN( FromDate, ThruDate, SchedTable )
! 
* LIST SCHEDULE JUSTLEN '8' BREAK-ON CUST_DIVISION JUSTLEN '30' PO PART_NUM SHIP_DATE TOTAL SHIP_QTY SHIP_PRICE JUSTLEN '12' BREAK-ON INVOICE_IDS JUSTLEN '12' TOTAL SHIP_AMOUNT JUSTLEN '15' LIMIT SHIP_DATE FROM "09/01/95" TO "09/05/95" HEADING " Billings by Customer/Division by Invoice No. 'T' PAGE # 'PP''L' by selected dates from ((09/01/95) TO (09/05/95 ) "
! 
*PRINTER ON
* 
* HEADING/FOOTING
declare function set_printer
Font = 'Courier New,7,L,0'
convert ',' to @fm in Font
TheHeader = " Billings by Customer/Division by Invoice No. 'T' PAGE # 'P' by selected dates from (":oconv( FromDate, 'D2/' ):") Thru (":oconv( ThruDate, 'D2/' ):@fm
HeadPos   = '.64,2.63,1.64,1.14,.75,.75,.89,.64,1.64'
convert ',' to @fm in HeadPos
COLHEADER = ''
ColHeader = "Key" : @vm : "Customer/Division" : @vm : "PO" : @vm : "Part Number" : @vm : "Ship Date" : @vm : "Ship Qty" : @vm : "Ship Price" : @vm : "Invoice IDs" : @vm : "Ship Amount"
Tvar = str( '_', 9):@vm:str( '_', 35):@vm:str( '_', 25):@vm:str( '_', 16):@vm
Tvar:= str( '_', 10):@vm:str( '_', 12):@vm:str( '_', 14):@vm:str( '_', 9):@vm
Tvar:= str( '_', 19)
ColHeader<-1> = Tvar
if SchedTable = 'SCHEDULE_SRL' then
    swap 'Part Number' with 'Description' in ColHeader
end
*THEHEADER = ''
Void = set_printer( 'FONTHEADFOOT', Font )
Void = set_printer( 'HEADER', TheHeader, HeadPos, ColHeader )
Void = set_printer( 'FONT', Font )
*FOOTING ""
* 
@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.CUSTULDIVISION.TOTAL=0
SHIPULQTY.CUSTULDIVISION.COUNT=0
SHIPULQTY.INVOICEULIDS.TOTAL=0
SHIPULQTY.INVOICEULIDS.COUNT=0
SHIPULQTY.GRAND.TOTAL=0
SHIPULQTY.GRAND.COUNT=0
* 
SHIPULAMOUNT.CUSTULDIVISION.TOTAL=0
SHIPULAMOUNT.CUSTULDIVISION.COUNT=0
SHIPULAMOUNT.INVOICEULIDS.TOTAL=0
SHIPULAMOUNT.INVOICEULIDS.COUNT=0
SHIPULAMOUNT.GRAND.TOTAL=0
SHIPULAMOUNT.GRAND.COUNT=0
* 
* NULL PREVIOUS BREAK BUCKETS
* 
PREV.CUSTULDIVISION=''
LAST.CUSTULDIVISION.BREAK = 1
PREV.INVOICEULIDS=''
LAST.INVOICEULIDS.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
* 
CUSTULDIVISION.BREAK=0
INVOICEULIDS.BREAK=0
* 
* 
@FILE.ERROR.MODE=1
READNEXT @ID,WHICH.VALUE ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> EQ 421 THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_6} )
GOTO READRECORD
END
IF @FILE.ERROR<1> NE 111 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
GOTO READRECORD
END
LAST.RECORD=1
CUSTULDIVISION.BREAK=1
CUSTULDIVISION=PREV.CUSTULDIVISION
INVOICEULIDS.BREAK=1
INVOICEULIDS=PREV.INVOICEULIDS
END
@FILE.ERROR.MODE=0
* 
S.ATID=@ID
* 
IF FIRST.PASS AND LAST.RECORD THEN
Void = set_printer( 'TEXT', {RLIST_TEXT_2} )
return
END
* 
IF LAST.RECORD THEN GOTO BREAKS
* 
IF @REDUCTION.DONE THEN
@FILE.ERROR.MODE=1
READO @RECORD FROM FILE.IN,@ID ELSE
@FILE.ERROR.MODE=0
IF STATUS() GT 0 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_5} )
return
END
IF @FILE.ERROR<1> NE 100 THEN
@ANS=@FILE.ERROR<1>
Void = set_printer( 'TEXT', {RLIST_TEXT_4} )
READERR+=1
END
GOTO READRECORD
END
@FILE.ERROR.MODE=0
END
* 
@RECCOUNT+=1
* 
* 
* CALCULATE VALUE(S) FOR COLUMN(S)
* 
S.ATID={@ID}
I.ATID=S.ATID
S.CUSTULDIVISION={CUST_DIVISION}
I.CUSTULDIVISION=S.CUSTULDIVISION
S.PO={PO}
I.PO=S.PO
if SchedTable = 'SCHEDULE' then 
    S.PARTULNUM={PART_NUM}
end else
    S.PARTULNUM={DESCRIPTION}
end
I.PARTULNUM=S.PARTULNUM
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.SHIPULPRICE={SHIP_PRICE}<1,WHICH.VALUE> ; P.SHIPULPRICE=1 ; C.SHIPULPRICE=7
* 
* INITIALIZE MULTIVALUE BREAK CHECK VARIABLE
* 
S.SHIPULPRICE = M.SHIPULPRICE
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.CUSTULDIVISION NE PREV.CUSTULDIVISION) OR CUSTULDIVISION.BREAK THEN
CUSTULDIVISION=PREV.CUSTULDIVISION
PREV.CUSTULDIVISION=S.CUSTULDIVISION
CUSTULDIVISION.BREAK+=1
INVOICEULIDS.BREAK=3
END
* 
IF (S.INVOICEULIDS NE PREV.INVOICEULIDS) OR INVOICEULIDS.BREAK THEN
INVOICEULIDS=PREV.INVOICEULIDS
PREV.INVOICEULIDS=S.INVOICEULIDS
INVOICEULIDS.BREAK+=1
END
* 
* 
IF FIRST.PASS THEN
FIRST.PASS=0
GOTO DETAIL
END
* 
* 
! 
BREAKS:
! 
* 
* PRINT BREAK TOTAL(S) AND ACCUMULATE TOTAL(S)
* 
* 
IF INVOICEULIDS.BREAK THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(SHIPULQTY.INVOICEULIDS.TOTAL ,"MD0"):@vm
PRINTLINE:= '':@vm
PRINTLINE:= "***":@vm
PRINTLINE:= OCONV(SHIPULAMOUNT.INVOICEULIDS.TOTAL ,"MD2,$")
TableColInfo = '>+922':@vm:'<+3787':@vm:'<+2362':@vm:'<+1642':@vm:'<+1080':@vm:'>+1080':@vm
TableColInfo:= '>+1282':@vm:'>+922':@vm:'>+1714'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

Void = set_printer( 'TEXT', '' )
* 
SHIPULQTY.CUSTULDIVISION.TOTAL+=SHIPULQTY.INVOICEULIDS.TOTAL
SHIPULQTY.INVOICEULIDS.TOTAL=0
SHIPULQTY.CUSTULDIVISION.COUNT+=SHIPULQTY.INVOICEULIDS.COUNT
SHIPULQTY.INVOICEULIDS.COUNT=0
SHIPULAMOUNT.CUSTULDIVISION.TOTAL+=SHIPULAMOUNT.INVOICEULIDS.TOTAL
SHIPULAMOUNT.INVOICEULIDS.TOTAL=0
SHIPULAMOUNT.CUSTULDIVISION.COUNT+=SHIPULAMOUNT.INVOICEULIDS.COUNT
SHIPULAMOUNT.INVOICEULIDS.COUNT=0
END
* 
IF CUSTULDIVISION.BREAK THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = '':@vm
PRINTLINE:= "***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(SHIPULQTY.CUSTULDIVISION.TOTAL ,"MD0"):@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(SHIPULAMOUNT.CUSTULDIVISION.TOTAL ,"MD2,$")
TableColInfo = '>+922':@vm:'<+3787':@vm:'<+2362':@vm:'<+1642':@vm:'<+1080':@vm:'>+1080':@vm
TableColInfo:= '>+1282':@vm:'>+922':@vm:'>+1714'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

Void = set_printer( 'TEXT', '' )
* 
SHIPULQTY.GRAND.TOTAL+=SHIPULQTY.CUSTULDIVISION.TOTAL
SHIPULQTY.CUSTULDIVISION.TOTAL=0
SHIPULQTY.GRAND.COUNT+=SHIPULQTY.CUSTULDIVISION.COUNT
SHIPULQTY.CUSTULDIVISION.COUNT=0
SHIPULAMOUNT.GRAND.TOTAL+=SHIPULAMOUNT.CUSTULDIVISION.TOTAL
SHIPULAMOUNT.CUSTULDIVISION.TOTAL=0
SHIPULAMOUNT.GRAND.COUNT+=SHIPULAMOUNT.CUSTULDIVISION.COUNT
SHIPULAMOUNT.CUSTULDIVISION.COUNT=0
END
* 
* PERFORM LAST RECORD OUTPUT IF DONE
* 
IF LAST.RECORD THEN
Void = set_printer( 'TEXT', '' )
PRINTLINE = "***":@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(SHIPULQTY.GRAND.TOTAL ,"MD0"):@vm
PRINTLINE:= '':@vm
PRINTLINE:= '':@vm
PRINTLINE:= OCONV(SHIPULAMOUNT.GRAND.TOTAL ,"MD2,$")
TableColInfo = '>+922':@vm:'<+3787':@vm:'<+2362':@vm:'<+1642':@vm:'<+1080':@vm:'>+1080':@vm
TableColInfo:= '>+1282':@vm:'>+922':@vm:'>+1714'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

* PRINT
* @ANS=@RECCOUNT
* PRINT {RLIST_TEXT_1}
IF READERR THEN
@ANS=READERR
Void = 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.SHIPULPRICE GE PREVIOUS.MARK.LEVEL THEN
REMOVE I.SHIPULPRICE FROM M.SHIPULPRICE AT P.SHIPULPRICE SETTING C.SHIPULPRICE
S.SHIPULPRICE=I.SHIPULPRICE
END
IF C.SHIPULPRICE GT NEW.MARK.LEVEL THEN NEW.MARK.LEVEL=C.SHIPULPRICE
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.SHIPULPRICE NE "" THEN S.SHIPULPRICE=OCONV(S.SHIPULPRICE,"MD2,$")
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.SHIPULPRICE=''
I.SHIPULPRICE=''
S.INVOICEULIDS=''
I.INVOICEULIDS=''
S.SHIPULAMOUNT=''
I.SHIPULAMOUNT=''
* 
ENDLIMIT:
* 
* ACCUMULATE TOTAL(S)
* 
IF NUM(I.SHIPULQTY) AND I.SHIPULQTY NE "" THEN
SHIPULQTY.INVOICEULIDS.TOTAL+=I.SHIPULQTY
SHIPULQTY.INVOICEULIDS.COUNT+=1
I.SHIPULQTY=''
END
IF NUM(I.SHIPULAMOUNT) AND I.SHIPULAMOUNT NE "" THEN
SHIPULAMOUNT.INVOICEULIDS.TOTAL+=I.SHIPULAMOUNT
SHIPULAMOUNT.INVOICEULIDS.COUNT+=1
I.SHIPULAMOUNT=''
END
* 
* PRINT DETAIL LINE
* 
PRINTLINE = S.ATID:@vm
PRINTLINE:= S.CUSTULDIVISION:@vm
PRINTLINE:= S.PO:@vm
PRINTLINE:= S.PARTULNUM:@vm
PRINTLINE:= S.SHIPULDATE:@vm
PRINTLINE:= S.SHIPULQTY:@vm
PRINTLINE:= S.SHIPULPRICE:@vm
PRINTLINE:= S.INVOICEULIDS:@vm
PRINTLINE:= S.SHIPULAMOUNT:@vm
TableColInfo = '>+922':@vm:'<+3787':@vm:'<+2362':@vm:'<+1642':@vm:'<+1080':@vm:'>+1080':@vm
TableColInfo:= '>+1282':@vm:'>+922':@vm:'>+1714'
Void = set_printer( 'ADDTABLE', TableColInfo, '', PRINTLINE, '', '', 1, TB_NONE ) 

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

