COMPILE ROUTINE LOAD_BATCHES(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE Send_Dyn,ErrMsg, Set_Status, Send_Info, obj_Tables, obj_SAP, Btree.Extract
DECLARE FUNCTION obj_WO_Mat, obj_SAP, 

$INSERT WO_LOG_EQUATES
$INSERT WO_MAT_EQUATES
$INSERT WM_OUT_EQUATES
$INSERT PROD_VER_EQUATES

EQU CRLF$ TO \0D0A\
EQU TAB$ TO \09\

EQU COL$BATCH_NO		TO 2
EQU COL$EPI_LOT			TO 3
EQU COL$WO_NO			TO 4
EQU COL$CASS_NO			TO 5
EQU COL$VEND_LOT_NO		TO 6
EQU COL$VEND_CODE		TO 7
EQU COL$STATUS			TO 8
EQU COL$REVISION		TO 9
EQU COL$LEGACY_ORD_NO	TO 11



debug

OPEN 'RDS' TO RDSTable ELSE
	ErrMsg('Unable to open "RDS" table for import')
	GOTO Bail
END

OPEN 'WO_LOG' TO WOLogTable ELSE
	ErrMsg('Unable to open "WO_LOG" table for import')
	GOTO Bail
END

OPEN 'DICT.WO_MAT' TO DictWOMat ELSE
	GOTO Bail
END


OPEN 'WO_MAT' TO WOMatTable ELSE
	GOTO Bail
END

OSREAD SAPData FROM 'C:\SAPBatch.txt' ELSE GOTO Bail

SWAP \0D0A\ WITH @FM IN SAPData
CONVERT \09\ TO @VM  IN SAPData

SAPData[-1,1] = ''

LineCount = COUNT(SAPData,@FM) + (SAPData NE '')


FOR I = 1 TO LineCount
	LineIn = SAPData<I>
	
	BatchNo 	= LineIn<1,COL$BATCH_NO>
	EpiLot 		= LineIn<1,COL$EPI_LOT>
	WONo		= LineIn<1,COL$WO_NO>
	CassNo		= LineIn<1,COL$CASS_NO>
	VendLot		= LineIn<1,COL$VEND_LOT_NO>
	VendCode	= LineIn<1,COL$VEND_CODE>
	
	IF EpiLot = 'SAPCONV' THEN
	
		IF BatchNo NE '' THEN
			SearchString = 'LOT_NO':@VM:BatchNo:@FM
		END
		
		Option = ''
		Flag = ''

		Btree.Extract(SearchString, 'WO_MAT', DictWOMat, WOMatKeys, Option, Flag)

		IF Get_Status(errCode) THEN 
			ErrMsg(errCode)
			RETURN
		END ELSE
		
			IF WOMatKeys = '' THEN
				*Send_Dyn(BatchNo:' - No WOMatKeys')
			END ELSE
				
				PossibleCassIDS = ''
				
				WOMatKeyCnt = COUNT(WOMatKeys,@VM) + (WOMatKeys NE '')
				
				FOR N = 1 TO WOMatKeyCnt
					WOMatKey = WOMatKeys<1,N>
					IF CassNo = FIELD(WOMatKey,'*',2) THEN
						WOMatRec	= XLATE('WO_MAT',WOMatKey,'','X')
						
						MUFlag 		= WOMatRec<WO_MAT_MAKEUP_BOX$>
						WMOKey		= WOMatRec<WO_MAT_WMO_KEY$>
						
						OMUFlag		= XLATE('WM_OUT',WMOKey,'MAKEUP_BOX','X')
						CurrStatus	= XLATE('WO_MAT',WOMatKey,'REP_STATUS','X')
						
						
						SWAP @VM WITH ', ' IN CurrStatus
						
						Send_Dyn(WOMatKey:' -> ':CurrStatus)
						
					END
				NEXT N
			
				*MUFlags = XLATE('WO_MAT',WOMatKeys,'MU_BOX','X')
				*CurrStatus = XLATE('WO_MAT',WOMatKeys,'CURR_STATUS','X')
				
				*Send_Dyn(BatchNo:' -> ':PossibleCassIDs:' ':CassNo)
			END
		
		END
	
	END

	/*
	IF WONo NE '' AND CassNo NE '' AND BatchNo NE '' THEN
		WOMatRec = XLATE('WO_MAT',WONo:'*':CassNo,'','X')
		CurrBatch = WOMatRec<WO_MAT_SAP_BATCH_NO$>
		
		IF CurrBatch NE BatchNo THEN
		
			Send_Dyn(WONo:'*':CassNo:' -> ':BatchNo:' -> ':CurrBatch)
		END
	END
	*/


NEXT I





* * * * * * *
Bail:
* * * * * * *


END

