Compile subroutine Copy_WO_STEP_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given WO_STEP record to the MSSQL database.
	
	History
	-------
	04/05/2010    KRF   Original Programmer
\*****************************************************************************/

$insert ASM_PART_EQUATES

Declare function SQL_Write, SQL_Format, SQL_Write_MV
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(22)
MatParse Record into Rec

// List of key names and their values
Keys  = "WO_NO":@VM:SQL_Format(Field(Key, "*", 1, 1), "INT"):@FM
Keys  := "PROC_STEP_NO":@VM:SQL_Format(Field(Key, "*", 2, 1), "INT")

// List of data fields and their values
DataFields  = "PROC_SPEC_ID":@VM:SQL_Format(Rec(1), "INT"):@FM
DataFields := "CYCLE_TIME":@VM:SQL_Format(Rec(3), "STR"):@FM
DataFields := "NOTES" :@VM:SQL_Format(Rec(5), "STR"):@FM
DataFields := "ORG_WO":@VM:SQL_Format(Rec(7), "STR"):@FM
DataFields := "PROC_STEP_DESC":@VM:SQL_Format(Rec(8), "STR"):@FM
DataFields := "SCHEDULED":@VM:SQL_Format(Rec(14), "BIT"):@FM
DataFields := "SCHED_DTM":@VM:SQL_Format(Rec(17), "DATETIME"):@FM
DataFields := "PRE_SURFSCAN_RECIPE":@VM:SQL_Format(Rec(19), "STR"):@FM
DataFields := "FIRST_SURFSCAN_RECIPE":@VM:SQL_Format(Rec(20), "STR"):@FM
DataFields := "POST_CLEAN_SURFSCAN_RECIPE":@VM:SQL_Format(Rec(21), "STR"):@FM

// Write the data to the SQL database
Ans = SQL_Write(Connection, "WO_STEP", Keys, DataFields);

//-------------------------------------------------------------------------------------------------
// Multi-valued Fields

// WO_STEP_REACTORS
If Ans EQ "" AND Rec(2) NE "" then
    
    // List of data fields and their values
    MvFields  = "REACTORS":@FM:SQL_Format(Rec(2), "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_REACTORS", Keys, MvFields);
end

// WO_STEP_SCHED_ID
If Ans EQ "" AND Rec(4) NE "" then
    
    // List of data fields and their values
    MvFields  = "SCHED_ID":@FM:SQL_Format(Rec(4), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_SCHED_ID", Keys, MvFields);
end

// WO_STEP_RDS_KEYS
If Ans EQ "" AND Rec(6) NE "" then
    
    // List of data fields and their values
    MvFields  = "RDS_KEYS":@FM:SQL_Format(Rec(6), "INT"):@RM
    MvFields  = "HOT_LOT":@FM:SQL_Format(Rec(9), "BIT"):@RM
    MvFields  = "MAKEUP_BOX":@FM:SQL_Format(Rec(10), "BIT"):@RM
    MvFields  = "SCHED_DT":@FM:SQL_Format(Rec(11), "DATE")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_RDS_KEYS", Keys, MvFields);
end

// WO_STEP_RDS_CURR_STATUS
If Ans EQ "" AND Rec(13) NE "" then
    
    // List of data fields and their values
    MvFields  = "RDS_CURR_STATUS":@FM:SQL_Format(Rec(13), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_RDS_CURR_STATUS", Keys, MvFields);
end

// WO_STEP_WM_IN_KEYS
If Ans EQ "" AND Rec(15) NE "" then
    
    // List of data fields and their values
    MvFields  = "WM_IN_KEYS":@FM:SQL_Format(Rec(15), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_WM_IN_KEYS", Keys, MvFields);
end

// WO_STEP_WM_OUT_KEYS
If Ans EQ "" AND Rec(16) NE "" then
    
    // List of data fields and their values
    MvFields  = "WM_OUT_KEYS":@FM:SQL_Format(Rec(16), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_WM_OUT_KEYS", Keys, MvFields);
end

// WO_STEP_BLOCKED_REACTORS
If Ans EQ "" AND Rec(18) NE "" then
    
    // List of data fields and their values
    MvFields  = "BLOCKED_REACTORS":@FM:SQL_Format(Rec(18), "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_STEP_BLOCKED_REACTORS", Keys, MvFields);
end


Return Ans
