COMPILE FUNCTION obj_RDS_Makeup(Method,Parms)

/*
	Methods for RDS_Makeup table
    
	09/21/2004 JCH - Initial Coding
     
    Properties:
     
    Methods:
    
	BoxType(RdsNo)								;* Returns 'Makeup Box' or 'Merge Lot' or Null
	RemMUWafers(SrcRDS,DestRDS,DestSlots)		;* Function returns Source Slots used, DestSlot can be multivalued
	
*/


DECLARE FUNCTION Get_Status, Msg, Utility, obj_Tables, Send_Dyn, obj_RDS
DECLARE SUBROUTINE  Set_Status, Msg, obj_Tables, Send_Dyn, obj_RDS

$INSERT MSG_EQUATES
$INSERT RDS_EQU
$INSERT RDS_MAKEUP_EQU

ErrTitle = 'Error in Stored Procedure "obj_RDS_Makeup"'
ErrorMsg = ''

IF NOT(ASSIGNED(Method))	THEN ErrorMsg = 'Unassigned parameter "Method" passed to subroutine'
IF NOT(ASSIGNED(Parms))		THEN Parms = ''

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

Result = ''

BEGIN CASE
	CASE Method = 'BoxType'			; GOSUB BoxType
	CASE Method = 'RemMUWafers'		; GOSUB RemMUWafers
	CASE Method = 'MUWafersRemoved'	; GOSUB MUWafersRemoved
	CASE Method = 'MUWafersAdded'	; GOSUB MUWafersAdded
	CASE 1

END CASE

IF ErrorMsg NE '' THEN
	Set_Status(-1,ErrTitle:@SVM:ErrorMsg)
	RETURN ''
END

RETURN Result


* * * * * * *
RemMUWafers:
* * * * * * *

* This pulls wafers from SrcRDS and adds logging info to Src RDS record

SrcRDS		= Parms[1,@RM]
DestRDS		= Parms[COL2()+1,@RM]
DestSlots	= Parms[COL2()+1,@RM]

IF NOT(ASSIGNED(SrcRDS))		THEN ErrorMsg = 'Unassigned parameter "SrcRDS" passed to routine. (':Method:')'
IF NOT(ASSIGNED(DestRDS))		THEN ErrorMsg = 'Unassigned parameter "DestRDS" passed to routine. (':Method:')'
IF NOT(ASSIGNED(DestSlots))		THEN ErrorMsg = 'Unassigned parameter "DestSlots" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

IF SrcRDS = ''		THEN ErrorMsg = 'Null parameter "SrcRDS" passed to routine. (':Method:')'
IF DestRDS = ''		THEN ErrorMsg = 'Null parameter "DestRDS" passed to routine. (':Method:')'
IF DestSlots = ''	THEN ErrorMsg = 'Null parameter "DestSlots" passed to routine. (':Method:')'

IF ErrorMsg NE '' THEN RETURN

otParms = 'RDS_MAKEUP':@RM:SrcRDS
RdsSrcRec = obj_Tables('ReadRec',otParms)	;* Reads and sets lock

IF RdsSrcRec = '' THEN
	obj_Tables('LockRec',otParms)			;* Set a lock for the new record
	Set_Status(0)
END

SchedWfrs	= obj_RDS('SchedWfrQty',SrcRds)
RejWfrs		= obj_RDS('TestRejWfrQty',SrcRds)
AvailWfrs	= SchedWfrs - RejWfrs

IF RdsSrcRec<RDS_MAKEUP_CASS_SLOT$> = '' THEN
	FOR I = 1 TO AvailWfrs
		RdsSrcRec<RDS_MAKEUP_CASS_SLOT$,I> = (AvailWfrs + 1 - I)
	NEXT I
END

SlotCnt = COUNT(DestSlots,@VM) + (DestSlots NE '')

FOR I = AvailWfrs TO 1 STEP -1
UNTIL RdsSrcRec<RDS_MAKEUP_DEST_SLOT$,I> = ''
NEXT I

NextFullSlotPointer = I

SrcSlots = ''
FOR I = 1 TO SlotCnt
	NextFullSlotNumber = AvailWfrs - NextFullSlotPointer + 1
	SrcSlots<1,I> = NextFullSlotNumber
	RdsSrcRec<RDS_MAKEUP_DEST_SLOT$,NextFullSlotPointer>	= DestSlots<1,I>
	RdsSrcRec<RDS_MAKEUP_DEST_RDS$,NextFullSlotPointer>		= DestRDS
	RdsSrcRec<RDS_MAKEUP_MAKEUP_BY$,NextFullSlotPointer>	= @USER4
	RdsSrcRec<RDS_MAKEUP_MAKEUP_DTM$,NextFullSlotPointer>	= ICONV(OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS'),'DTM')
	NextFullSlotPointer -= 1
NEXT I

otParms = FIELDSTORE(otParms,@RM,4,0,RdsSrcRec)
obj_Tables('WriteRec',otParms)

Result = SrcSlots:@FM:OCONV(Date(),'D4/'):' ':OCONV(Time(),'MTS')

RETURN


* * * * * * *
BoxType:
* * * * * * *

RdsNo = Parms[1,@RM]

IF NOT(ASSIGNED(RdsNo))	THEN RETURN
IF RdsNo = ''			THEN RETURN

RdsMakeupRec = XLATE('RDS_MAKEUP',RdsNo,'','X')
MakeupBoxFlag = XLATE('RDS',RdsNo,RDS_MAKEUP_BOX$,'X')

SrcRDS = RdsMakeupRec<RDS_MAKEUP_SRC_RDS$>
DestRDS = RdsMakeupRec<RDS_MAKEUP_DEST_RDS$>

CONVERT @VM TO '' IN SrcRDS
CONVERT @VM TO '' IN DestRDS

BEGIN CASE
	CASE MakeupBoxFlag
		Result = 'Makeup Box'
		
	CASE SrcRDS NE ''
		Result = 'Merged Lots'
		
	CASE DestRDS NE ''
		Result = 'Makeup Box'
		
	CASE 1
		Null	;* Result is already set to null
END CASE


RETURN

* * * * * * *
MUWafersAdded:
* * * * * * *

RDSNo = Parms[1,@RM]

IF NOT(ASSIGNED(RDSNo)) THEN RETURN
IF RDSNo = '' THEN RETURN

RDSMakeupSrcRDS = XLATE('RDS_MAKEUP',RDSNo,'2','X')
IF RDSMakeupSrcRDS = '' THEN
   Tmp = ''
END ELSE
   Tmp = 0
   FOR I = 1 TO COUNT(RDSMakeupSrcRDS,@VM) + (RDSMakeupSrcRDS NE '')
      IF RDSMakeupSrcRDS<1,I> NE '' THEN Tmp += 1
   NEXT I
END 

Result = Tmp
RETURN


* * * * * * *
MUWafersRemoved:
* * * * * * *

RDSNo = Parms[1,@RM]

IF NOT(ASSIGNED(RDSNo)) THEN RETURN
IF RDSNo = '' THEN RETURN


RDSMakeupDestRDS = XLATE('RDS_MAKEUP',RDSNo,'4','X')
IF RDSMakeupDestRDS = '' THEN
   Tmp = ''
END ELSE
   Tmp = 0
   FOR I = 1 TO COUNT(RDSMakeupDestRDS,@VM) + (RDSMakeupDestRDS NE '')
      IF RDSMakeupDestRDS<1,I> NE '' THEN Tmp += 1
   NEXT I
END 

Result = Tmp

RETURN

