COMPILE FUNCTION TEST_CONVERT_PO(RawPO,CompNo)

DECLARE SUBROUTINE Send_Dyn
DECLARE FUNCTION Get_Status

IF NOT(ASSIGNED(RawPO)) THEN RETURN ''
IF NOT(ASSIGNED(CompNo)) THEN RETURN ''

PONo	= ''
LineNo 	= ''
RelNo	= ''

POIn = TRIM(RawPO)
RawPO = POIn

IF POIn[1,3] = 'GG-' THEN
	SWAP 'GG-' WITH 'GG' IN POIn
END

IF POIn[1,1] = '-' THEN
	Result = POIn
	GOTO Bail
END

CONVERT ' ' TO '' IN POIn

IF POIn[1,2] = 'S-' THEN
	Result = POIn
	GOTO Bail
END

IF INDEX(POIn,'-',1) AND NOT(INDEX(POIn,'-',2))  THEN
	
	TestPOIn	= POIn[1,'F-']
	Suffix		= POIn[-1,'B-']
	
	IF LEN(POIn) = 1 OR NOT(NUM(Suffix))  OR LEN(Suffix) > LEN(TestPOIn) THEN
		CONVERT ' ' TO '' IN RawPO
		Result = RawPO
		GOTO Bail
	END
	
	IF LEN(Suffix) < 5 AND Suffix[1,1] NE '0' THEN
		POIn = POIn[1,'F-']	
		
		PONo = POIn
		IF CompNo = '6495' OR CompNo = '506' THEN
			RelNo = Suffix
		END
	END ELSE
		BEGIN CASE
			CASE LEN(Suffix) = 5
				RelNo = '0':Suffix
				Dummy = POIn[-1,'B-']
				POIn[COL1()-1,99] = ''
				
			CASE LEN(Suffix) = 7
				RelNo = '0':Suffix
				Dummy = POIn[-1,'B-']
				POIn[COL1()-1,99] = ''
				
			CASE LEN(Suffix) = 6
				RelNo = Suffix
				Dummy = POIn[-1,'B-']
				POIn[COL1()-1,99] = ''
				
			CASE LEN(Suffix) = 8
				RelNo = Suffix
				Dummy = POIn[-1,'B-']
				POIn[COL1()-1,99] = ''
				
			CASE  1
				Null
				
		END CASE
		PONo = POIn
	END
END ELSE
	PONo = POIn
END


IF INDEX(POIn,'LINE',1) THEN
	SWAP 'LINE' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'Line#',1) THEN
	SWAP 'Line#' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'Line',1) THEN
	SWAP 'Line' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'Item',1) THEN
	SWAP 'Item' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'=L',1) THEN
	SWAP '=L' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'*L',1) THEN
	SWAP '*L' WITH @FM IN POIn
	LineNo = POIn<2>
	PONo = POIn<1>
END

IF INDEX(POIn,'Rel',1) THEN
	SWAP 'Rel' WITH @FM IN POIn
	RelNo = POIn<2>
	PONo = POIn<1>
END

Result = PONo:@vm:LineNo:@VM:RelNo

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

RETURN Result
