Compile function Copy_WO_MAT_Record_To_SQL(Connection, Key, Record)

/*****************************************************************************\
	Copies the given WO_MAT record to the MSSQL database.
	
	History
	-------
	05/23/2012    KRF   Original Programmer
\*****************************************************************************/

$insert WO_MAT_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of key names and their values
Keys  = "WO_NO"  :@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
Keys := "CASS_NO":@VM:SQL_Format(Field(Key, "*", 2), "INT")
// Converstions
SubSupplBy = OConv(Rec(WO_MAT_SUB_SUPPL_BY$), "[SUPPLIED_BY_CONV]")
ReactorType = OConv({REACTOR_TYPE}, "[REACT_TYPE_CONV,OPSREF]")

// List of data fields and their values
DataFields  = "LOT_NO"             :@VM:SQL_Format(Rec(WO_MAT_LOT_NO$),              "STR"):@FM
DataFields := "WAFER_QTY"          :@VM:SQL_Format(Rec(WO_MAT_WAFER_QTY$),           "INT"):@FM
DataFields := "CUST_PART_NO"       :@VM:SQL_Format(Rec(WO_MAT_CUST_PART_NO$),        "STR"):@FM
DataFields := "SUB_PART_NO"        :@VM:SQL_Format(Rec(WO_MAT_SUB_PART_NO$),         "STR"):@FM
DataFields := "ORDER_ITEM"         :@VM:SQL_Format(Rec(WO_MAT_ORDER_ITEM$),          "INT"):@FM
DataFields := "SUB_SUPPL_BY"       :@VM:SQL_Format(SubSupplBy,                       "STR"):@FM
DataFields := "SHIP_NO"            :@VM:SQL_Format(Rec(WO_MAT_SHIP_NO$),             "STR"):@FM
DataFields := "PART_NO"            :@VM:SQL_Format(Rec(WO_MAT_PART_NO$),             "STR"):@FM
DataFields := "MAKEUP_BOX"         :@VM:SQL_Format(Rec(WO_MAT_MAKEUP_BOX$),          "BIT"):@FM
DataFields := "HOT_LOT"            :@VM:SQL_Format(Rec(WO_MAT_HOT_LOT$),             "BIT"):@FM
DataFields := "RX_DTM"             :@VM:SQL_Format(Rec(WO_MAT_RX_DTM$),              "DATETIME"):@FM
DataFields := "RX_BY"              :@VM:SQL_Format(Rec(WO_MAT_RX_BY$),               "STR"):@FM
DataFields := "REL_DTM"            :@VM:SQL_Format(Rec(WO_MAT_REL_DTM$),             "DATETIME"):@FM
DataFields := "REL_BY"             :@VM:SQL_Format(Rec(WO_MAT_REL_BY$),              "STR"):@FM
DataFields := "ORG_COMMIT_DT"      :@VM:SQL_Format(Rec(WO_MAT_ORG_COMMIT_DT$),       "DATE"):@FM
DataFields := "HOLD"               :@VM:SQL_Format(Rec(WO_MAT_HOLD$),                "BIT"):@FM
DataFields := "MU_WAFER_FLAG"      :@VM:SQL_Format(Rec(WO_MAT_MU_WAFER_FLAG$),       "BIT"):@FM
DataFields := "WMI_CURR_STATUS"    :@VM:SQL_Format(Rec(WO_MAT_WMI_CURR_STATUS$),     "STR"):@FM
DataFields := "WMO_CURR_STATUS"    :@VM:SQL_Format(Rec(WO_MAT_WMO_CURR_STATUS$),     "STR"):@FM
DataFields := "VOID"               :@VM:SQL_Format(Rec(WO_MAT_VOID$),                "BIT"):@FM
DataFields := "CANCELLED"          :@VM:SQL_Format(Rec(WO_MAT_CANCELLED$),           "BIT"):@FM
DataFields := "EPO_MAKEUP_BOX"     :@VM:SQL_Format(Rec(WO_MAT_EPO_MAKEUP_BOX$),      "BIT"):@FM
DataFields := "RET_REJECTS"        :@VM:SQL_Format(Rec(WO_MAT_RET_REJECTS$),         "BIT"):@FM
DataFields := "REPROCESSED_MAT"    :@VM:SQL_Format(Rec(WO_MAT_REPROCESSED_MAT$),     "BIT"):@FM
DataFields := "CASS_SHIP_QTY"      :@VM:SQL_Format(Rec(WO_MAT_CASS_SHIP_QTY$),       "INT"):@FM
DataFields := "SHIP_SHORT"         :@VM:SQL_Format(Rec(WO_MAT_SHIP_SHORT$),          "BIT"):@FM
DataFields := "EPOS_CLEAN_INSP_KEY":@VM:SQL_Format(Rec(WO_MAT_EPOS_CLEAN_INSP_KEY$), "STR"):@FM
DataFields := "EPI_PRO"            :@VM:SQL_Format(Rec(WO_MAT_EPI_PRO$),             "BIT"):@FM
DataFields := "EPI_CI_NO"          :@VM:SQL_Format(Rec(WO_MAT_EPI_CI_NO$),           "STR"):@FM
DataFields := "EPO_CI_NO"          :@VM:SQL_Format(Rec(WO_MAT_EPO_CI_NO$),           "STR"):@FM
DataFields := "EPO_SHIP_HOLD"      :@VM:SQL_Format(Rec(WO_MAT_EPO_SHIP_HOLD$),       "BIT"):@FM
DataFields := "SHIP_HOLD"          :@VM:SQL_Format(Rec(WO_MAT_SHIP_HOLD$),           "BIT"):@FM
DataFields := "SAP_BATCH_NO"       :@VM:SQL_Format(Rec(WO_MAT_SAP_BATCH_NO$),        "STR"):@FM
DataFields := "CUST_PART_REV_FUT"  :@VM:SQL_Format(Rec(WO_MAT_CUST_PART_REV_FUT$),   "STR"):@FM
DataFields := "SUB_VEND_CD"        :@VM:SQL_Format(Rec(WO_MAT_SUB_VEND_CD$),         "STR"):@FM
DataFields := "SAP_TX_DTM"         :@VM:SQL_Format(Rec(WO_MAT_SAP_TX_DTM$),          "DATETIME"):@FM
DataFields := "ORG_SAP_BATCH_NO"   :@VM:SQL_Format(Rec(WO_MAT_ORG_SAP_BATCH_NO$),    "STR"):@FM
DataFields := "WMO_LOAD_DTM"       :@VM:SQL_Format(Rec(WO_MAT_WMO_LOAD_DTM$),        "DATETIME"):@FM
DataFields := "REC_VER"            :@VM:SQL_Format(Rec(WO_MAT_REC_VER$),             "INT"):@FM

// Symbolics
CassIdSap        = {CASS_ID_SAP}
CaptiveMerchant  = {CAPTIVE_MERCHANT}
MuBox            = {MU_BOX}
DataFields      := "CUST_NAME"        :@VM:SQL_Format({CUST_NAME}[1,50],   "STR"):@FM
DataFields      := "INV_FAB_DAYS"     :@VM:SQL_Format({INV_FAB_DAYS},      "DEC", 1):@FM
DataFields      := "INV_FAB_HRS"      :@VM:SQL_Format({INV_FAB_HRS},       "DEC", 1):@FM
DataFields      := "REACTOR_TYPE"     :@VM:SQL_Format(ReactorType,         "STR"):@FM
DataFields      := "SHIP_PSN"         :@VM:SQL_Format({SHIP_PSN},          "INT"):@FM
DataFields      := "WAFER_SIZE"       :@VM:SQL_Format({WAFER_SIZE},        "STR"):@FM
DataFields      := "WO_STATUS"        :@VM:SQL_Format({WO_STATUS},         "BIT"):@FM
DataFields      := "CASS_ID_SAP"      :@VM:SQL_Format(CassIdSap,           "STR"):@FM
DataFields      := "SAP_YIELD"        :@VM:SQL_Format({SAP_YIELD},         "INT"):@FM
DataFields      := "SAP_VEND_CD"      :@VM:SQL_Format({SAP_VEND_CD},       "STR"):@FM
DataFields      := "EPI_PART_NO"      :@VM:SQL_Format({EPI_PART_NO},       "STR"):@FM
DataFields      := "PROD_ORD_NO"      :@VM:SQL_Format({PROD_ORD_NO},       "STR"):@FM
DataFields      := "SAP_SCRAP_QTY"    :@VM:SQL_Format({SAP_SCRAP_QTY},     "INT"):@FM
DataFields      := "SAP_PROD_TEST_QTY":@VM:SQL_Format({SAP_PROD_TEST_QTY}, "INT"):@FM
DataFields      := "SAP_MU_QTY"       :@VM:SQL_Format({SAP_MU_QTY},        "INT"):@FM
DataFields      := "MU_BOX"           :@VM:SQL_Format(MuBox,               "STR"):@FM
DataFields      := "SAP_ORD_TYPE"     :@VM:SQL_Format({SAP_ORD_TYPE},      "STR"):@FM
DataFields      := "SAP_MAT_TYPE"     :@VM:SQL_Format({SAP_MAT_TYPE},      "STR"):@FM
DataFields      := "WO_QTY"           :@VM:SQL_Format({WO_QTY},            "INT"):@FM
DataFields      := "FINAL_SIG_COMP"   :@VM:SQL_Format({FINAL_SIG_COMP},    "BIT"):@FM
DataFields      := "COMMENT"          :@VM:SQL_Format({COMMENT},           "STR"):@FM
DataFields      := "CUST_CAPTIVE"     :@VM:SQL_Format({CUST_CAPTIVE},      "BIT"):@FM
DataFields      := "CAPTIVE_MERCHANT" :@VM:SQL_Format(CaptiveMerchant,     "STR"):@FM
DataFields      := "CURR_STATUS"	  :@VM:SQL_Format({CURR_STATUS},	   "STR")

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

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

// WO_MAT_RDS_NO
If Ans EQ "" AND Rec(WO_MAT_RDS_NO$) NE "" then
	
	// List of data fields and their values
	MvFields  = "WO_STEP_NO"       :@FM:SQL_Format({WO_STEP_NO},                   "STR"):@RM
	MvFields := "WO_STEP_PS_NO"    :@FM:SQL_Format({WO_STEP_PS_NO},                "STR"):@RM
	MvFields := "WO_STEP_PRE_CLEAN":@FM:SQL_Format({WO_STEP_PRE_CLEAN},            "STR"):@RM
	MvFields := "RDS_NO"           :@FM:SQL_Format(Rec(WO_MAT_RDS_NO$),            "INT"):@RM
	MvFields := "RDS_RUN_STATUS"   :@FM:SQL_Format({RDS_RUN_STATUS},               "STR"):@RM
	MvFields := "RDS_WFRS_OUT_NOMU":@FM:SQL_Format({RDS_WFRS_OUT_NOMU},            "INT"):@RM
	MvFields := "RDS_FINAL_SIG"    :@FM:SQL_Format({RDS_FINAL_SIG},                "STR"):@RM
	MvFields := "RDS_FINAL_SIG_DTM":@FM:SQL_Format({RDS_FINAL_SIG_DTM},            "DATETIME")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_RDS_NO", Keys, MvFields);
	
end

// WO_MAT_INV_WH
If Ans EQ "" AND Rec(WO_MAT_INV_DTM$) NE "" then
	*    If Index(ReactorType, 'EPP', 1) then
	*        ActionCnt   = DCount(Rec(WO_MAT_INV_ACTION$), @VM)
	*        If ActionCnt EQ 7 then Debug
	*        If Rec(WO_MAT_INV_ACTION$)[-1, 'B' : @VM] EQ '1UNLOAD' then Debug
	*    end
	// List of data fields and their values
	MvFields  = "INV_DTM"       : @FM : SQL_Format(Rec(WO_MAT_INV_DTM$),      "DATETIME"):@RM
	MvFields := "INV_WH"        : @FM : SQL_Format(Rec(WO_MAT_INV_WH$),       "STR"):@RM
	MvFields := "INV_WH_DESC"   : @FM : SQL_Format({INV_WH_DESC},             "STR"):@RM
	MvFields := "INV_LOCATION"  : @FM : SQL_Format(Rec(WO_MAT_INV_LOCATION$), "STR"):@RM
	MvFields := "INV_LOC_DESC"  : @FM : SQL_Format({INV_LOC_DESC},            "STR"):@RM
	MvFields := "INV_ACTION"    : @FM : SQL_Format(Rec(WO_MAT_INV_ACTION$),   "STR"):@RM
	MvFields := "INV_USER"      : @FM : SQL_Format(Rec(WO_MAT_INV_USER$),     "STR"):@RM
	MvFields := "INV_TAG"       : @FM : SQL_Format(Rec(WO_MAT_INV_TAG$),      "STR"):@RM
	MvFields := "INV_TOOL_ID"   : @FM : SQL_Format(Rec(WO_MAT_INV_TOOL_ID$),  "STR"):@RM
	MvFields := "REP_STATUS"    : @FM : SQL_Format({REP_STATUS},             "STR")
	*    NumItems    = DCount(Rec(WO_MAT_INV_DTM$), @VM)
	*    LoadWfrCnt  = {LOAD_WFR_CNT}
	*    LoadWfrCnt  = Field(LoadWfrCnt, @VM, 1, NumItems)
	*    MvFields := "LOAD_WFR_CNT"  : @FM : SQL_Format(LoadWfrCnt,                "INT")
	
	RepeatFields  = "CURR_LOCATION"     :@VM:SQL_Format({CURR_LOCATION},            "STR"):@FM
	RepeatFields := "CURR_LOCATION_DESC":@VM:SQL_Format({CURR_LOCATION_DESC},       "STR"):@FM
	RepeatFields := "CASS_ID_SAP"       :@VM:SQL_Format(CassIdSap,                  "STR"):@FM
	RepeatFields := "MU_BOX"            :@VM:SQL_Format(MuBox,                      "STR"):@FM
	RepeatFields := "CURR_WFR_CNT"      :@VM:SQL_Format({CURR_WFR_CNT},             "INT"):@FM
	RepeatFields := "WIP_START_DTM"     :@VM:SQL_Format(Rec(WO_MAT_WIP_START_DTM$), "DATETIME"):@FM
	RepeatFields := "WIP_STOP_DTM"      :@VM:SQL_Format(Rec(WO_MAT_WIP_STOP_DTM$),  "DATETIME"):@FM
	RepeatFields := "LOAD_WFR_CNT"      :@VM:SQL_Format({LOAD_WFR_CNT},             "INT"):@FM
	RepeatFields := "WO_REACT_TYPE"     :@VM:SQL_Format({WO_REACT_TYPE},            "STR")
	*    RepeatFields := "REP_STATUS"        :@VM:SQL_Format({REP_STATUS},               "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_INV_WH", Keys, MvFields, RepeatFields);
	
end

// WO_MAT_SIG_PROFILE
If Ans EQ "" AND Rec(WO_MAT_SIG_DTM$) NE "" then
	
	// List of data fields and their values
	MvFields  = "SIG_DTM"       :@FM:SQL_Format(Rec(WO_MAT_SIG_DTM$),     "DATETIME"):@RM
	MvFields := "SIGNATURE"     :@FM:SQL_Format(Rec(WO_MAT_SIGNATURE$),   "STR"):@RM
	MvFields := "SIG_PROFILE"   :@FM:SQL_Format(Rec(WO_MAT_SIG_PROFILE$), "STR"):@RM
	MvFields := "SIG_VER"       :@FM:SQL_Format(Rec(WO_MAT_SIG_VER$),     "INT")
	
	RepeatFields  = "SHIP_STATUS"     :@VM:SQL_Format(OConv({SHIP_STATUS}, "[WO_MAT_CURR_STATUS_CONV]"), "STR"):@FM
	RepeatFields := "SIG_PROF_EXPORT" :@VM:SQL_Format({SIG_PROF_EXPORT},                                 "STR"):@FM
	RepeatFields := "CASS_ID_SAP"     :@VM:SQL_Format(CassIdSap,                                         "STR"):@FM
	RepeatFields := "CAPTIVE_MERCHANT":@VM:SQL_Format(CaptiveMerchant,                                   "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_SIG_PROFILE", Keys, MvFields, RepeatFields);
	
end

// WO_MAT_SIG_PROFILE_AUDIT
If Ans EQ "" AND Rec(WO_MAT_INV_DTM$) NE "" then
	MvFields  = "NEW_SIG_DTM"    :@FM:Sql_Format(Rec(WO_MAT_INV_DTM$),       "DATETIME"):@RM
	MvFields  := "DATE_ADDED"    :@FM:Sql_Format(Rec(WO_MAT_INV_DTM$),       "DATETIME"):@RM
	MvFields := "SIG_PROFILE"    :@FM:SQL_Format(Rec(WO_MAT_INV_ACTION$), "STR"):@RM
	MvFields := "SIGNATURE"     :@FM:SQL_Format(Rec(WO_MAT_INV_USER$),   "STR"):@RM
	MvFields := "INV_WH_DESC"   : @FM : SQL_Format({INV_WH_DESC},             "STR"):@RM
	MvFields := "INV_LOC_DESC"  : @FM : SQL_Format({INV_LOC_DESC},            "STR"):@RM
	MvFields := "INV_TOOL_ID"   : @FM : SQL_Format(Rec(WO_MAT_INV_TOOL_ID$),  "STR"):@RM
	MvFields := "INV_LOCATION"  : @FM : SQL_Format(Rec(WO_MAT_INV_LOCATION$), "STR")
	
	RepeatFields  = "CURR_LOCATION"     :@VM:SQL_Format({CURR_LOCATION},            "STR"):@FM
	RepeatFields := "CASS_ID_SAP"       :@VM:SQL_Format(CassIdSap,                  "STR"):@FM
	RepeatFields := "CURR_WFR_CNT"      :@VM:SQL_Format({CURR_WFR_CNT},             "INT"):@FM
	
	Ans = SQL_Write_MV(Connection, "WO_MAT_SIG_PROFILE_AUDIT", Keys, MvFields, RepeatFields);
end

// WO_MAT_SLOT_NO
* If Ans EQ "" AND Rec(WO_MAT_SLOT_NO$) NE "" then
*    
*    // List of data fields and their values
*    MvFields  = "SLOT_NO"          :@FM:SQL_Format(Rec(WO_MAT_SLOT_NO$),           "INT"):@RM
*    MvFields := "SLOT_WAFER_ID"    :@FM:SQL_Format({SLOT_WAFER_ID},                "STR"):@RM
*    MvFields := "SLOT_NCR"         :@FM:SQL_Format(Rec(WO_MAT_SLOT_NCR$),          "INT"):@RM
*    MvFields := "SLOT_MET_NO"      :@FM:SQL_Format(Rec(WO_MAT_SLOT_MET_NO$),       "STR"):@RM
*    MvFields := "SLOT_MOVED_TO"    :@FM:SQL_Format(Rec(WO_MAT_SLOT_MOVED_TO$),     "STR"):@RM
*    MvFields := "SLOT_REP_WAFER_ID":@FM:SQL_Format(Rec(WO_MAT_SLOT_REP_WAFER_ID$), "STR")
*    
*    // Write the data to the SQL database
*    Ans = SQL_Write_MV(Connection, "WO_MAT_SLOT_NO", Keys, MvFields);
*    
* end

// WO_MAT_HOLD_HISTORY
* If (Rec(WO_MAT_HOLD_START_DTM$) NE "" OR Rec(WO_MAT_HOLD_STOP_DTM$) NE "") then
If Ans EQ "" AND (Rec(WO_MAT_HOLD_START_DTM$) NE "" OR Rec(WO_MAT_HOLD_STOP_DTM$) NE "") then
	
	// List of data fields and their values
	MvFields  = "HOLD_START_DTM"   :@FM:SQL_Format(Rec(WO_MAT_HOLD_START_DTM$),    "DATETIME"):@RM
	MvFields := "HOLD_START_USER"  :@FM:SQL_Format(Rec(WO_MAT_HOLD_START_USER$),   "STR"):@RM
	MvFields := "HOLD_START_REASON":@FM:SQL_Format(Rec(WO_MAT_HOLD_START_REASON$), "STR"):@RM
	MvFields := "HOLD_STOP_DTM"    :@FM:SQL_Format(Rec(WO_MAT_HOLD_STOP_DTM$),     "DATETIME"):@RM
	MvFields := "HOLD_STOP_USER"   :@FM:SQL_Format(Rec(WO_MAT_HOLD_STOP_USER$),    "STR"):@RM
	MvFields := "HOLD_STOP_REASON" :@FM:SQL_Format(Rec(WO_MAT_HOLD_STOP_REASON$),  "STR"):@RM
	MvFields := "HOLD_ENTITY"      :@FM:SQL_Format(Rec(WO_MAT_HOLD_ENTITY$),       "STR"):@RM
	MvFields := "HOLD_ENTITY_ID"   :@FM:SQL_Format(Rec(WO_MAT_HOLD_ENTITY_ID$),    "STR"):@RM
	MvFields := "HOLD_EXTENDED"    :@FM:SQL_Format(Rec(WO_MAT_HOLD_EXTENDED$),     "BIT")
	
	RepeatFields = "CASS_ID_SAP"   :@VM:SQL_Format(CassIdSap,                      "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_HOLD_HISTORY", Keys, MvFields, RepeatFields);
	
end

// WO_MAT_SHIP_HOLD_HISTORY
If Ans EQ "" AND (Rec(WO_MAT_SHIP_HOLD_START_DTM$) NE "" OR Rec(WO_MAT_SHIP_HOLD_STOP_DTM$) NE "") then
	
	// List of data fields and their values
	MvFields  = "SHIP_HOLD_START_DTM"   :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_START_DTM$),    "DATETIME"):@RM
	MvFields := "SHIP_HOLD_START_USER"  :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_START_USER$),   "STR"):@RM
	MvFields := "SHIP_HOLD_START_REASON":@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_START_REASON$), "STR"):@RM
	MvFields := "SHIP_HOLD_STOP_DTM"    :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_STOP_DTM$),     "DATETIME"):@RM
	MvFields := "SHIP_HOLD_STOP_USER"   :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_STOP_USER$),    "STR"):@RM
	MvFields := "SHIP_HOLD_STOP_REASON" :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_STOP_REASON$),  "STR"):@RM
	MvFields := "SHIP_HOLD_EXTENDED"    :@FM:SQL_Format(Rec(WO_MAT_SHIP_HOLD_EXTENDED$),     "BIT")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_SHIP_HOLD_HISTORY", Keys, MvFields);
	
end

// WO_MAT_WMI_SLOT_NO
If Ans EQ "" AND Rec(WO_MAT_WMI_KEY$) NE "" then
	
	// List of data fields and their values
	MvFields  = "WMI_KEY"      :@FM:SQL_Format(Rec(WO_MAT_WMI_KEY$), "STR"):@RM
	MvFields := "WMI_SLOT_NO"  :@FM:SQL_Format({WMI_SLOT_NO},        "INT"):@RM
	MvFields := "WMI_RDS_NO"   :@FM:SQL_Format({WMI_RDS_NO},         "STR"):@RM
	MvFields := "WMI_POCKET_NO":@FM:SQL_Format({WMI_POCKET_NO},      "STR"):@RM
	MvFields := "WMI_SLOT_NCR" :@FM:SQL_Format({WMI_SLOT_NCR},       "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_WMI_SLOT_NO", Keys, MvFields);
	
end

// WO_MAT_WMO_SLOT_NO
If Ans EQ "" AND Rec(WO_MAT_WMO_KEY$) NE "" then
	
	// List of data fields and their values
	MvFields  = "WMO_KEY"      :@FM:SQL_Format(Rec(WO_MAT_WMO_KEY$),  "STR"):@RM
	MvFields := "EPO_SLOT"     :@FM:SQL_Format(Rec(WO_MAT_EPO_SLOT$), "INT"):@RM
	MvFields := "WMO_RDS_NO"   :@FM:SQL_Format({WMO_RDS_NO},          "INT"):@RM
	MvFields := "WMO_POCKET"   :@FM:SQL_Format({WMO_POCKET},          "STR"):@RM
	MvFields := "WMO_SLOT_NCR" :@FM:SQL_Format({WMO_SLOT_NCR},        "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_WMO_SLOT_NO", Keys, MvFields);
	
end

// WO_MAT_CLEAN_INSP
If Ans EQ "" AND Rec(WO_MAT_WMO_KEY$) NE "" then
	
	// List of data fields and their values
	MvFields  = "CLEAN_INSP_KEY":@FM:SQL_Format(Rec(WO_MAT_CLEAN_INSP_KEY$), "INT"):@RM
	MvFields := "CI_STEP_NO"    :@FM:SQL_Format({CI_STEP_NO},                "STR"):@RM
	MvFields := "CI_STAGE"      :@FM:SQL_Format({CI_STAGE},                  "STR"):@RM
	MvFields := "CI_CLEAN_TOOL" :@FM:SQL_Format({CI_CLEAN_TOOL},             "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_CLEAN_INSP", Keys, MvFields);
	
end

// WO_MAT_MET_PROFILE
If Ans EQ "" AND Rec(WO_MAT_MET_PROFILE$) NE "" then
	
	// List of data fields and their values
	MvFields  = "MET_PROFILE"  :@FM:SQL_Format(Rec(WO_MAT_MET_PROFILE$),  "STR"):@RM
	MvFields := "MET_RUN_STEP" :@FM:SQL_Format(Rec(WO_MAT_MET_RUN_STEP$), "STR"):@RM
	MvFields := "MET_MIN"      :@FM:SQL_Format(Rec(WO_MAT_MET_MIN$),      "STR"):@RM
	MvFields := "MET_MAX"      :@FM:SQL_Format(Rec(WO_MAT_MET_MAX$),      "STR"):@RM
	MvFields := "MET_RESULT"   :@FM:SQL_Format(Rec(WO_MAT_MET_RESULT$),   "STR"):@RM
	MvFields := "MET_SLOT"     :@FM:SQL_Format(Rec(WO_MAT_MET_SLOT$),     "STR"):@RM
	MvFields := "MET_SLOT_DESC":@FM:SQL_Format({MET_SLOT_DESC},           "STR"):@RM
	MvFields := "MET_SIG"      :@FM:SQL_Format(Rec(WO_MAT_MET_SIG$),      "STR"):@RM
	MvFields := "MET_SIG_DTM"  :@FM:SQL_Format(Rec(WO_MAT_MET_SIG_DTM$),  "DATETIME")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_MET_PROFILE", Keys, MvFields);
	
end

// WO_MAT_NCR_KEYS
If Ans EQ "" AND Rec(WO_MAT_NCR_KEYS$) NE "" then
	
	// List of data fields and their values
	MvFields  = "NCR_KEYS"         :@FM:SQL_Format(Rec(WO_MAT_NCR_KEYS$),          "STR"):@RM
	MvFields := "NCR_FINAL_SIG"    :@FM:SQL_Format(Rec(WO_MAT_NCR_FINAL_SIG$),     "STR"):@RM
	MvFields := "NCR_FINAL_SIG_DTM":@FM:SQL_Format(Rec(WO_MAT_NCR_FINAL_SIG_DTM$), "DATETIME"):@RM
	MvFields := "NCR_LOSS_BY"      :@FM:SQL_Format({NCR_LOSS_BY},                  "STR"):@RM
	MvFields := "NCR_LOSS_COMMENT" :@FM:SQL_Format({NCR_LOSS_COMMENT},             "STR"):@RM
	MvFields := "NCR_LOSS_DESC"    :@FM:SQL_Format({NCR_LOSS_DESC},                "STR"):@RM
	MvFields := "NCR_LOSS_STAGE"   :@FM:SQL_Format({NCR_LOSS_STAGE},               "STR"):@RM
	MvFields := "NCR_REJ_CNT"      :@FM:SQL_Format({NCR_REJ_CNT},                  "INT"):@RM
	MvFields := "NCR_STATUS"       :@FM:SQL_Format({NCR_STATUS},                   "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_NCR_KEYS", Keys, MvFields);
	
end

// WO_MAT_EPO_SLOT
If Ans EQ "" AND Rec(WO_MAT_EPO_SLOT$) NE "" then
	
	// List of data fields and their values
	MvFields  = "EPO_SLOT"         :@FM:SQL_Format(Rec(WO_MAT_EPO_SLOT$),          "STR"):@RM
	MvFields := "EPOS_WFR_IN"      :@FM:SQL_Format(Rec(WO_MAT_EPOS_WFR_IN$),       "STR"):@RM
	MvFields := "EPOS_RUN_ID"      :@FM:SQL_Format(Rec(WO_MAT_EPOS_RUN_ID$),       "STR"):@RM
	MvFields := "EPOS_NCR"         :@FM:SQL_Format(Rec(WO_MAT_EPOS_NCR$),          "INT"):@RM
	MvFields := "EPOS_MET_NO"      :@FM:SQL_Format(Rec(WO_MAT_EPOS_MET_NO$),       "INT"):@RM
	MvFields := "EPOS_MOVED_TO"    :@FM:SQL_Format(Rec(WO_MAT_EPOS_MOVED_TO$),     "STR"):@RM
	MvFields := "EPOS_REP_WAFER_ID":@FM:SQL_Format(Rec(WO_MAT_EPOS_REP_WAFER_ID$), "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_EPO_SLOT", Keys, MvFields);
	
end

// WO_MAT_REACTORS
Reactor = {REACTOR}
If Ans EQ "" AND Reactor NE "" then
	
	// List of data fields and their values
	MvFields     = "REACTOR"    :@FM:SQL_Format(Reactor,   "STR")
	RepeatFields = "CASS_ID_SAP":@VM:SQL_Format(CassIdSap, "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_REACTORS", Keys, MvFields, RepeatFields);
	
end

// WO_MAT_REP_CURR_WFR_CNTS
RepCurrWfrCnt = {REP_CURR_WFR_CNT}
If Ans EQ "" AND RepCurrWfrCnt NE "" then
	
	// List of data fields and their values
	MvFields  = "REP_CURR_WFR_CNT":@FM:SQL_Format(RepCurrWfrCnt, "INT")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_REP_CURR_WFR_CNTS", Keys, MvFields);
	
end

// WO_MAT_REP_STATUS
RepStatus = {REP_STATUS}
If Ans EQ "" AND RepStatus NE "" then
	
	// List of data fields and their values
	MvFields  = "REP_STATUS":@FM:SQL_Format(RepStatus, "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_REP_STATUS", Keys, MvFields);
	
end

// WO_MAT_MU_CASS_IDS_SAP
MuCassIdsSap = {MU_CASS_IDS_SAP}
If Ans EQ "" AND MuCassIdsSap NE "" then
	
	// List of data fields and their values
	MvFields  = "MU_CASS_IDS_SAP":@FM:SQL_Format(MuCassIdsSap, "STR")
	
	// Write the data to the SQL database
	Ans = SQL_Write_MV(Connection, "WO_MAT_MU_CASS_IDS_SAP", Keys, MvFields);
	
end

Return Ans


