compile function RDS_RPT1()
begin condition
pre:
post:
end condition
declare function getprinterlist, getprofilestring, writeprofilestring, extdevicemode
declare function msg, set_property, send_event, dialog_box, utility, get_property
declare function set_printer, Printer_Select
declare subroutine rlist, or_view, activate_save_select, yield
declare subroutine rds_rpt1_prn
$insert rlist_equates
$insert msg_equates

Params = dialog_box( 'RDS_RPT1', @window, '*CENTER' )
if Params = 'CANCEL' or Params = '' then
    return 0
end
open 'SYSLISTS' to SysListsTable else
    MsgInfo = ''
    MsgInfo<mcol$> = -2
    MsgInfo<mrow$> = -2
    MsgInfo<mtext$> = 'Unable to open SYSLISTS...' 
    Void = msg( '', MsgInfo )
    return 0
end
ListsId = 'RDS_RPT1*':@station
write '' on SysListsTable, ListsId else
    MsgInfo = ''
    MsgInfo<mcol$> = -2
    MsgInfo<mrow$> = -2
    MsgInfo<mtext$> = 'Unable to clear SYSLISTS ':ListsId:'...'
    Void = msg( '', MsgInfo )
    return 0
end
convert '*' to @fm in Params
DateInFrom   = Params<1>
DateInThru   = Params<2>
DirToPrinter = Params<3>
Custs        = Params<4>
DetSum       = Params<5>
Reactors     = Params<6>
if DetSum = 'Summary' then
    DetSum = 'DET-SUPP'
end else
    DetSum = ''
end    

Stat = utility( 'CURSOR', 'H' )
Stmt = 'SELECT RDS BY REACTOR BY CUST_CITY BY ENTRY_DATE'
if DateInFrom and DateInThru then
   Stmt :=  " WITH DATE_IN FROM ":QUOTE(DateInFrom):' TO ':QUOTE(DateInThru)
end else
	if DateInFrom then
	    Stmt :=  " WITH DATE_IN GE ":QUOTE(DateInFrom)
	end
	if DateInThru then
	    Stmt := " WITH DATE_IN LE ":QUOTE(DateInThru)
	end
end
if Custs then
    swap @vm with "' '" in Custs
    Custs = "'":Custs:"'"
    Stmt := ' AND WITH CUST_NO = ':Custs
end
if Reactors then
    swap @vm with "' '" in Reactors
    Reactors = "'":Reactors:"'"
    Stmt := ' AND WITH REACTOR = ':Reactors
end

Void = set_status(0)
rlist( Stmt, target_savelist$, ListsId, '', '' )

activate_save_select( ListsId )

if @reccount then
   Cmd = "LIST RDS ":DetSum:" ID-SUPP BREAK-ON REACTOR ":quote( "'V'" ):" JUSTLEN 7 BREAK-ON ABBREV_OR_CO_NAME "
   Cmd:= quote( "'V'" ):" JUSTLEN 20 SEQ JUSTLEN 8 COLHEAD 'RDS' TOTAL WAFERS_IN TOTAL WFRS_OUT "
   Cmd:= "TOTAL LSL_PRE_EPI_REJ TOTAL LSL_POST_EPI_REJ TOTAL LSL_TOT_REJ "
   Cmd:= "TOTAL CUST_PRE_EPI_REJ TOTAL CUST_POST_EPI_REJ TOTAL CUST_TOT_REJ "
   Cmd:= "TOTAL TOT_REJ TIME_IN TIME_OUT TOTAL ELAPSED_HOURS COLHEAD 'Elapsed Hours' TOTAL MAINT_HOURS DATE_IN DATE_OUT "
   Cmd:= " OPERATOR_IN OPERATOR_OUT"
   Cmd:= " HEADING ":'"':" Run Date: 'TS39'Page'P''LS17'Wafer Process History from "
   Cmd:= DateInFrom:' To ':DateInThru:'"'
   if DirToPrinter = 'Yes' then
   		PrintPath = Printer_Select('',1)	;* Select Default Printer
       Void = set_printer( 'INIT', '', '', '':@fm:1.5, 1, '',PrintPath )
       rds_rpt1_prn( iconv( DateInFrom, 'D' ), iconv( DateInThru, 'D' ), DetSum )
       Void = set_printer( 'TERM' )
       Void = set_printer( 'INIT', '', '', '', 0, '' )
       Void = set_printer( 'TERM' )
   end else
       or_view( '', Cmd )
       Void = set_property( 'ORPRV.PRINT', 'ENABLED', 0 )
       WinId = 'ORPRV'
       loop
         while get_property( WinId, 'HANDLE' )
          yield()
       repeat
       ToPrint = ''
       MsgInfo = ''
       MsgInfo<mtext$> = 'Do you want to print this report?'
       MsgInfo<micon$> = '?'
       MsgInfo<mtype$> = 'BNY'
       MsgInfo<mcol$>  = -2
       MsgInfo<mrow$>  = -2
       MsgInfo<mdefbtn$> = 2 ;* default to no
       ToPrint = msg( @window, MsgInfo )
       if ToPrint then
           activate_save_select( ListsId )
           Void = set_printer( 'INIT', '', '', '':@fm:1.5, 1, '' )         
           rds_rpt1_prn( iconv( DateInFrom, 'D' ), iconv(DateInThru, 'D' ), DetSum )
           Void = set_printer( 'TERM' )
           Void = set_printer( 'INIT', '', '', '', 0, '' )
           Void = set_printer( 'TERM' )
       end
   end 
end else
   MsgInfo = ''
   MsgInfo<mcol$>  = -2
   MsgInfo<mrow$>  = -2
   MsgInfo<mtext$> = 'NO Records meeting your date criteria!!'
   MsgInfo<micon$> = '!'
   Void = MSG( '', MsgInfo )
end
write '' on SysListsTable, ListsId else
    MsgInfo = ''
    MsgInfo<mcol$>  = -2
    MsgInfo<mrow$>  = -2
    MsgInfo<mtext$> = 'Unable to clear SYSLISTS ':ListsId:'...'
    Void = msg( '', MsgInfo )
    return 0
end
return 0

