Compile function Copy_REACT_RUN_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given REACT_RUN record to the MSSQL database.
	
	History
	-------
	06/22/2010    KRF   Original Programmer
\*****************************************************************************/

$insert REACT_RUN_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(77)
MatParse Record into Rec
					    
// List of key names and their values
Keys = "RDS_NO":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = "WO_NO"               :@VM:SQL_Format(Rec(REACT_RUN_WO_NO$),                  "INT"):@FM
DataFields := "WO_STEP"             :@VM:SQL_Format(Rec(REACT_RUN_WO_STEP$),                "INT"):@FM
DataFields := "CASS_NO"             :@VM:SQL_Format(Rec(REACT_RUN_CASS_NO$),                "INT"):@FM
DataFields := "REACTOR"             :@VM:SQL_Format(Rec(REACT_RUN_REACTOR$),                "INT"):@FM
* DataFields := "PRE_CI_KEY"          :@VM:SQL_Format(Rec(REACT_RUN_PRE_CI_KEY$),             "STR"):@FM
* DataFields := "WFR_CI_KEY"          :@VM:SQL_Format(Rec(REACT_RUN_WFR_CI_KEY$),             "STR"):@FM
* DataFields := "POST_CI_KEY"         :@VM:SQL_Format(Rec(REACT_RUN_POST_CI_KEY$),            "STR"):@FM
DataFields := "VER_WFR_CNT"         :@VM:SQL_Format(Rec(REACT_RUN_VER_WFR_CNT$),            "INT"):@FM
DataFields := "LOAD_WFR_CNT"        :@VM:SQL_Format(Rec(REACT_RUN_LOAD_WFR_CNT$),           "INT"):@FM
DataFields := "ENTER_BY"            :@VM:SQL_Format(Rec(REACT_RUN_ENTER_BY$),               "STR"):@FM
DataFields := "ENTER_DTM"           :@VM:SQL_Format(Rec(REACT_RUN_ENTER_DTM$),              "DATETIME"):@FM
DataFields := "VER_SIG"             :@VM:SQL_Format(Rec(REACT_RUN_VER_SIG$),                "STR"):@FM
DataFields := "VER_SIG_DTM"         :@VM:SQL_Format(Rec(REACT_RUN_VER_SIG_DTM$),            "DATETIME"):@FM
DataFields := "PRE_SIG"             :@VM:SQL_Format(Rec(REACT_RUN_PRE_SIG$),                "STR"):@FM
DataFields := "PRE_SIG_DTM"         :@VM:SQL_Format(Rec(REACT_RUN_PRE_SIG_DTM$),            "DATETIME"):@FM
DataFields := "LOAD_SIG"            :@VM:SQL_Format(Rec(REACT_RUN_LOAD_SIG$),               "STR"):@FM
DataFields := "LOAD_SIG_DTM"        :@VM:SQL_Format(Rec(REACT_RUN_LOAD_SIG_DTM$),           "DATETIME"):@FM
DataFields := "WFR_SIG"             :@VM:SQL_Format(Rec(REACT_RUN_WFR_SIG$),                "STR"):@FM
DataFields := "WFR_SIG_DTM"         :@VM:SQL_Format(Rec(REACT_RUN_WFR_SIG_DTM$),            "DATETIME"):@FM
DataFields := "UNLOAD_SIG"          :@VM:SQL_Format(Rec(REACT_RUN_UNLOAD_SIG$),             "STR"):@FM
DataFields := "UNLOAD_SIG_DTM"      :@VM:SQL_Format(Rec(REACT_RUN_UNLOAD_SIG_DTM$),         "DATETIME"):@FM
DataFields := "POST_SIG"            :@VM:SQL_Format(Rec(REACT_RUN_POST_SIG$),               "STR"):@FM
DataFields := "POST_SIG_DTM"        :@VM:SQL_Format(Rec(REACT_RUN_POST_SIG_DTM$),           "DATETIME"):@FM
DataFields := "FINAL_SIG"           :@VM:SQL_Format(Rec(REACT_RUN_FINAL_SIG$),              "STR"):@FM
DataFields := "FINAL_SIG_DTM"       :@VM:SQL_Format(Rec(REACT_RUN_FINAL_SIG_DTM$),          "DATETIME"):@FM
DataFields := "SCHED_DT"            :@VM:SQL_Format(Rec(REACT_RUN_SCHED_DT$),               "DATE"):@FM
DataFields := "BL_DEFECTS"          :@VM:SQL_Format(Rec(REACT_RUN_BL_DEFECTS$),             "INT"):@FM
DataFields := "STACK_FAULTS"        :@VM:SQL_Format(Rec(REACT_RUN_STACK_FAULTS$),           "INT"):@FM
DataFields := "SPIKES"              :@VM:SQL_Format(Rec(REACT_RUN_SPIKES$),                 "INT"):@FM
Convert '/' to '?' in Rec(REACT_RUN_SPECIAL_INST$)
DataFields := "SPECIAL_INST"        :@VM:SQL_Format(Rec(REACT_RUN_SPECIAL_INST$),           "STR", 1):@FM
DataFields := "REACT_IDLE_TIME"     :@VM:SQL_Format(Rec(REACT_RUN_REACT_IDLE_TIME$),        "DEC", "2"):@FM
DataFields := "SHIFT"               :@VM:SQL_Format(Rec(REACT_RUN_SHIFT$),                  "STR"):@FM
DataFields := "LAST_WAFER_RHO"      :@VM:SQL_Format(Rec(REACT_RUN_LAST_WAFER_RHO$),         "DEC", "2"):@FM
DataFields := "LOAD_LOCK_SIDE"      :@VM:SQL_Format(Rec(REACT_RUN_LOAD_LOCK_SIDE$),         "STR"):@FM
DataFields := "ADE_READ"            :@VM:SQL_Format(Rec(REACT_RUN_ADE_READ$),               "STR"):@FM
DataFields := "FIN_WFR_CNT"         :@VM:SQL_Format(Rec(REACT_RUN_FIN_WFR_CNT$),            "INT"):@FM
DataFields := "INJECTORS"           :@VM:SQL_Format(Rec(REACT_RUN_INJECTORS$),              "STR"):@FM
DataFields := "TUBE_ID"             :@VM:SQL_Format(Rec(REACT_RUN_TUBE_ID$),                "STR"):@FM
DataFields := "TUBE_GRADE"          :@VM:SQL_Format(Rec(REACT_RUN_TUBE_GRADE$),             "INT"):@FM
DataFields := "SUSCEPTOR_ID"        :@VM:SQL_Format(Rec(REACT_RUN_SUSCEPTOR_ID$),           "STR"):@FM
DataFields := "SUPP_INST"           :@VM:SQL_Format(Rec(REACT_RUN_SUPP_INST$),              "STR", 1):@FM
DataFields := "SUPP_ENTRY_ID"       :@VM:SQL_Format(Rec(REACT_RUN_SUPP_ENTRY_ID$),          "STR"):@FM
DataFields := "SUPP_ENTRY_DTM"      :@VM:SQL_Format(Rec(REACT_RUN_SUPP_ENTRY_DTM$),         "DATETIME"):@FM
DataFields := "SUPP_SIG"            :@VM:SQL_Format(Rec(REACT_RUN_SUPP_SIG$),               "STR"):@FM
DataFields := "SUPP_SIG_DTM"        :@VM:SQL_Format(Rec(REACT_RUN_SUPP_SIG_DTM$),           "DATETIME"):@FM
DataFields := "REACT_ACT_ESC_DTM"   :@VM:SQL_Format(Rec(REACT_RUN_REACT_ACT_ESC_DTM$),      "DATETIME"):@FM
DataFields := "CANCELLED"           :@VM:SQL_Format(Rec(REACT_RUN_CANCELLED$),              "BIT"):@FM
DataFields := "VOID"                :@VM:SQL_Format(Rec(REACT_RUN_VOID$),                   "BIT"):@FM
DataFields := "PRE_CI_NO"           :@VM:SQL_Format(Rec(REACT_RUN_PRE_CI_NO$),              "INT"):@FM
DataFields := "WFR_CI_NO"           :@VM:SQL_Format(Rec(REACT_RUN_WFR_CI_NO$),              "INT"):@FM
DataFields := "POST_CI_NO"          :@VM:SQL_Format(Rec(REACT_RUN_POST_CI_NO$),             "INT"):@FM
DataFields := "SCHED_WFR_QTY"       :@VM:SQL_Format(Rec(REACT_RUN_SCHED_WFR_QTY$),          "INT"):@FM
DataFields := "BACK_SEAL"           :@VM:SQL_Format(Rec(REACT_RUN_BACK_SEAL$),              "BIT"):@FM
DataFields := "BURIED_LAYER"        :@VM:SQL_Format(Rec(REACT_RUN_BURIED_LAYER$),           "BIT"):@FM
DataFields := "PHOS_DOPED_SUBSTRATE":@VM:SQL_Format(Rec(REACT_RUN_PHOS_DOPED_SUBSTRATE$),   "BIT"):@FM
DataFields := "VER_COMMENT"         :@VM:SQL_Format(Rec(REACT_RUN_VER_COMMENT$),            "STR"):@FM
DataFields := "LOAD_COMMENT"        :@VM:SQL_Format(Rec(REACT_RUN_LOAD_COMMENT$),           "STR"):@FM
DataFields := "UNLOAD_COMMENT"      :@VM:SQL_Format(Rec(REACT_RUN_UNLOAD_COMMENT$),         "STR"):@FM
DataFields := "FINAL_COMMENT"       :@VM:SQL_Format(Rec(REACT_RUN_FINAL_COMMENT$),          "STR"):@FM

// Symbolics
DataFields := "CURR_WFR_CNT"        :@VM:SQL_Format({CURR_WFR_CNT},                               "INT"):@FM
DataFields := "CURR_WFR_CNT_REJ"    :@VM:SQL_Format({CURR_WFR_CNT_REJ},                           "INT"):@FM
DataFields := "CUST_CAPTIVE"        :@VM:SQL_Format({CUST_CAPTIVE},                               "BIT"):@FM
DataFields := "CUST_NAME"           :@VM:SQL_Format({CUST_NAME}[1,50],                            "STR"):@FM
DataFields := "CUST_NO"             :@VM:SQL_Format({CUST_NO},                                    "STR"):@FM
DataFields := "LOT_NO"              :@VM:SQL_Format({LOT_NO},                                     "STR"):@FM
DataFields := "PART_NO"             :@VM:SQL_Format({PART_NO},                                    "STR"):@FM
DataFields := "PS_NO"               :@VM:SQL_Format({PS_NO},                                      "STR"):@FM
DataFields := "REACTOR_TYPE"        :@VM:SQL_Format(OConv({REACTOR_TYPE}, "[REACTOR_TYPE_CONV]"), "STR"):@FM
DataFields := "RECIPE_NAME"         :@VM:SQL_Format({RECIPE_NAME},                                "STR"):@FM
DataFields := "RECIPE_NO"           :@VM:SQL_Format({RECIPE_NO},                                  "INT"):@FM
DataFields := "SPEC_TYPE"           :@VM:SQL_Format(OConv({SPEC_TYPE}, "[SPEC_TYPE_CONV]"),       "STR"):@FM
DataFields := "WFR_UNLOAD_DAYS"     :@VM:SQL_Format({WFR_UNLOAD_DAYS},                            "INT"):@FM
DataFields := "WFR_UNLOAD_NIGHTS"   :@VM:SQL_Format({WFR_UNLOAD_NIGHTS},                          "INT"):@FM
DataFields := "WFR_UNLOAD_QTY"      :@VM:SQL_Format({WFR_UNLOAD_QTY},                             "INT"):@FM
DataFields := "CASS_ID_SAP"         :@VM:SQL_Format({CASS_ID_SAP},                                "STR"):@FM
DataFields := "REACT_TOOL_ID"       :@VM:SQL_Format({REACT_TOOL_ID},                              "STR"):@FM
DataFields := "RUN_STATUS"			:@VM:SQL_Format({RUN_STATUS},								  "STR")


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

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


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

// REACT_RUN_POCKET
If Ans EQ "" AND Rec(REACT_RUN_POCKET$) NE "" then
    
    // List of data fields and their values
    MvFields  = "POCKET"      :@FM:SQL_Format(Rec(REACT_RUN_POCKET$),       "STR"):@RM
    MvFields := "POCKET_CHAR" :@FM:SQL_Format(Rec(REACT_RUN_POCKET_CHAR$),  "STR"):@RM
    MvFields := "ZONE"        :@FM:SQL_Format(Rec(REACT_RUN_ZONE$),         "STR"):@RM
    MvFields := "IN_CASS_NO"  :@FM:SQL_Format(Rec(REACT_RUN_IN_CASS_NO$),   "STR"):@RM
    MvFields := "IN_SLOT_NO"  :@FM:SQL_Format(Rec(REACT_RUN_IN_SLOT_NO$),   "STR"):@RM
    MvFields := "OUT_CASS_NO" :@FM:SQL_Format(Rec(REACT_RUN_OUT_CASS_NO$),  "STR"):@RM
    MvFields := "OUT_SLOT_NO" :@FM:SQL_Format(Rec(REACT_RUN_OUT_SLOT_NO$),  "STR"):@RM
    MvFields := "WAFER_CHAR"  :@FM:SQL_Format(Rec(REACT_RUN_WAFER_CHAR$),   "STR"):@RM
    MvFields := "WAFER_SCRIBE":@FM:SQL_Format(Rec(REACT_RUN_WAFER_SCRIBE$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACT_RUN_POCKET", Keys, MvFields);
    
end


// REACT_RUN_UNLOAD
If Ans EQ "" AND Rec(REACT_RUN_EX_UNLOAD$) NE "" then
    
    // List of data fields and their values
    MvFields  = "EX_UNLOAD"       :@FM:SQL_Format(Rec(REACT_RUN_EX_UNLOAD$),        "STR"):@RM
    MvFields := "EX_UNLOAD_DTM"   :@FM:SQL_Format(Rec(REACT_RUN_EX_UNLOAD_DTM$),    "DATETIME"):@RM
    MvFields := "EX_UNLOAD_REASON":@FM:SQL_Format(Rec(REACT_RUN_EX_UNLOAD_REASON$), "STR"):@RM
    MvFields := "EX_LOAD"         :@FM:SQL_Format(Rec(REACT_RUN_EX_LOAD$),          "STR"):@RM
    MvFields := "EX_LOAD_DTM"     :@FM:SQL_Format(Rec(REACT_RUN_EX_LOAD_DTM$),      "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACT_RUN_UNLOAD", Keys, MvFields);
    
end


// REACT_RUN_CI_STAGES
If Ans EQ "" AND Rec(REACT_RUN_CI_NO$) NE "" AND Rec(REACT_RUN_CI_STAGE$) NE "" then
    
    // List of data fields and their values
    MvFields  = "CI_NO"   :@FM:SQL_Format(Rec(REACT_RUN_CI_NO$),    "INT"):@RM
    MvFields := "CI_STAGE":@FM:SQL_Format(Rec(REACT_RUN_CI_STAGE$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "REACT_RUN_CI_STAGES", Keys, MvFields);
    
end



Return Ans


