COMPILE ROUTINE LOAD_EPI_PN(Dummy)
ROWDEF(CHARSTR)

DECLARE SUBROUTINE Send_Dyn,Send_Info, Send_Dyn, Set_Status, RList, ErrMsg
DECLARE FUNCTION Get_Status, Set_Printer

$INSERT RDS_EQU
$INSERT QUOTE_DET_EQU

EQU TARGET_ACTIVELIST$ to 5

debug

OPEN 'EPI_PART' TO EpiPartTable ELSE
	ErrMsg('Unable to open EPI_PART')
	GOTO Bail
END

OPEN 'CUST_PART' TO CustPartTable ELSE
	ErrMsg('Unable to open CUST_PART')
	GOTO Bail
END

OPEN 'QUOTE_DET' TO QuoteDetTable ELSE
	ErrMsg('Unable to open QUOTE_DET table')
	GOTO Bail
END

OPEN 'DICT.QUOTE_DET' TO @DICT ELSE
	ErrMsg('Unable to open DICT.QUOTE_DET')
	GOTO Bail
END

SelectSent = 'SELECT QUOTE_DET WITH QUOTE_STATUS = "O"'

RList(SelectSent,TARGET_ACTIVELIST$, "", "", "")

IF Get_Status(errCode) THEN
	ErrMsg(errCode)
	GOTO Bail
END

EpiPN = 1000


Done = 0
LOOP
	READNEXT @ID ELSE Done = 1
UNTIL Done
	READ @RECORD FROM QuoteDetTable,@ID THEN
		CustNo		= {CUST_NO}
		QuoteDetKey	= @ID
		CustPartNos = {CUST_PART_NO}
		IF CustPartNos = '' THEN
			CustPNs	= {PSN_PART_NO}
		END ELSE
			CustPNs = CustPartNos
		END
		SWAP ', ' WITH @VM IN CustPNs
		CONVERT ',' TO @VM IN CustPNs
		
		EpiPartRec = ''
		EpiPartRec<1> = QuoteDetKey
		
		FOR I = 1 TO COUNT(CustPNs,@VM) + (CustPNs NE '')
			CustPN = CustPNs<1,I>
			CustPN = TRIM(CustPN)
			IF CustPN NE '' THEN
				CustPartRec = ''
				CustPartRec<1> = EpiPN
				CustPartRec<2> = {PROC_PSN}
				
				LOCATE @ID IN CustPartRec<3> USING @VM Setting Pos ELSE
					CustPartRec = INSERT(CustPartRec,3,Pos,0,@ID)
				END
				CustPartKey = CustNo:'*':CustPN
				WRITE CustPartRec ON CustPartTable,CustPartKey ELSE DEBUG
			END
			LOCATE CustPartKey IN EpiPartRec<3> USING @VM Setting Pos1 ELSE
				EpiPartRec = INSERT(EpiPartRec,3,Pos1,0,CustPartKey)
			END
		NEXT I
		WRITE EpiPartRec ON EpiPartTable,EpiPN ELSE DEBUG
		EpiPN += 1
		
	END	;* End of QuoteDet record read
REPEAT



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

END
