compile subroutine wo_valid(ConvType, DataIo, SupErr, ReturnedValue)
begin condition
pre:
post:
end condition

$insert logical
$insert quote_equ
$insert msg_equates
$insert wo_log_equ
$insert prod_spec_equ
$insert wo_step_equ

declare function msg, get_property, set_property, fieldcount

equ valid$         to 0    ;* successful
equ invalid_msg$   to 1    ;* bad data       -   print error message window
equ invalid_conv$  to 2    ;* bad conversion -          "         "
equ invalid_nomsg$ to 3    ;* bad but do not print the error message window
equ CrLf$          to char(13):char(10)

* IF SUPERR IS TRUE THEN WE WILL SUPPRESS THE ERROR MESSAGES AND RETURN ONLY THE WO INFO
* AND NO COMMENTS
if assigned(SupErr) else
   SupErr = false$   
end
ReturnedValue = DataIo       
status() = Valid$              


BEGIN CASE
	CASE ConvType = 'ICONV'
	
	TDataIo = DataIo
	if SupErr then
		* CLEAR OUT DATAIO CAUSE WE ARE GOING TO RETURN ONLY THE WO INFO
		DataIo = ''
	end
	Comments = field( TdataIo, '|', 2 )
	TDataIo = field( TdataIo, '|', 1 )
	swap "52nd" with '' in TDataIo      
	Convert ';' to @fm in TDataIo
	convert @upper_case to '' in TDataIo
	convert @lower_case to '' in TDataIO
	convert " `~!@#$%^&*()_+-=\][{}|';:/?.>,<" to '' in TDataIo
	convert '"' to '' in TDataIo
	Dcnt = fieldcount( TDataIo, @fm )
	
	FOR I = 1 TO Dcnt
		IF LEN(TDataIo<i>) = 7 THEN
			WONo = TDataIo<i>[1,6]:'.':TDataIo<i>[-1,1]												;* JCH 7/27/2006
			WOStepKey = WONo
			CONVERT '.' TO '*' IN WOStepKey
		END ELSE
			WONo = TDataIo<I>
			WOStepKey = TDataIo<I>:'*1'
		END
		
		WoStepRec = xlate( 'WO_STEP', WOStepKey, '', 'X' )
		*ReactorType = xlate( 'PROD_SPEC', WoStepRec<wo_step_prod_spec_id$>, prod_spec_reactor_type$, 'X' )	;* EpiPro Reinstallation JCH 4/30/2006
		*if ReactorType = "P" then ;* THIS IS FOR EPI PRO 5000 DO NOT LET THEM USE
			
			*MsgInfo = ''
			*MsgInfo<mtext$> = 'WO_Step ':WONo:' is an EpiPro 5000 PSN...This can not run on the ASM reactors.'
			*MsgInfo<micon$> = 'H'
			*Void = msg( '', MsgInfo )
			*swap WONo with '' in DataIo
			*status() = invalid_nomsg$
		*end else
			if ( WoStepRec = '' ) and not( SupErr ) then
				MsgInfo = ''
				MsgInfo<mtext$> = WONo:' is not a valid Work Order No...' 
				MsgInfo<micon$> = '!'
				* let it be valid just warn
				Void = msg( '', MsgInfo )
			end else
				if ( SupErr ) and ( WoStepRec <> '' ) then
					* ERROR SUPPRESSSION SO ONLY RETURN THE ACTUAL WO
					* MOST LIKELY CALLED FROM WO_MAST_SCHED_COMM - USED TO 
					* GET ALL UNIQUE WOs AND WRITE 1 TO SCHEDULED
					DataIo:= WONo:';'
				end
			end
		*end
	         
		
	NEXT I
      if Comments and not( SupErr ) then
         ReturnedValue = DataIo:'|':Comments
      end else
         if DataIo[-1,1] = ';' then
            DataIo[-1,1] = ''
         end
         ReturnedValue = DataIo
      end      
      * let it be valid just warn
      
      
   CASE ConvType = 'OCONV'
      IF DataIo <> '' THEN
         IF DataIo = 'Open' THEN
            ReturnedValue = DataIo
         END ELSE
            TdataIo = DataIo
            Comments = field( TdataIo, '|', 2 )
            TdataIo = field( TdataIo, '|', 1 )
            swap "52nd" with '' in TDataIo            
            Convert ';' to @fm in TDataIo
            convert @upper_case to '' in TDataIo
            convert @lower_case to '' in TDataIO
            convert " `~!@#$%^&*()_+-=\][{}|';:/?.>,<" to '' in TDataIo
            convert '"' to '' in TDataIo
            NewDataIo = ''
            Dcnt = fieldcount( TDataIo, @fm )
           
            FOR i = 1 TO Dcnt
	            IF LEN(TDataIo<i>) = 7 THEN
	            	WONo = TDataIo<i>[1,6]:'.':TDataIo<i>[-1,1]
				END ELSE
					WONo = TDataIo<i>
				END
				
				if num( WONo ) then
					CustNo = xlate( 'WO_LOG', WONo[1,6], wo_log_cust_no$, 'X' )
					NewDataIo<i> = WONo:' ':xlate( 'COMPANY', CustNo, 'ABBREV_OR_CO_NAME', 'X' )
				end
            NEXT I
            convert @fm to ';' in NewDataIo
            if Comments then
               NewDataIo := '|':Comments
            end
            DataIo = NewDataIo
            ReturnedValue = DataIo
         END
      END
      
  CASE otherwise$
      ReturnedValue = ''
      status() = invalid_conv$
end case
return
