Compile function Copy_WO_LOG_Record_To_SQL(Connection, Key, Record)

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

$insert WO_LOG_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "ENTRY_ID"            :@VM:SQL_Format(Rec(WO_LOG_ENTRY_ID$),              "STR"):@FM
DataFields := "ENTRY_DATE"          :@VM:SQL_Format(Rec(WO_LOG_ENTRY_DATE$),            "DATE"):@FM
DataFields := "CUST_NO"             :@VM:SQL_Format(Rec(WO_LOG_CUST_NO$),               "INT"):@FM
DataFields := "QTY"                 :@VM:SQL_Format(Rec(WO_LOG_QTY$),                   "INT"):@FM
DataFields := "PROD_SPEC_ID"        :@VM:SQL_Format(Rec(WO_LOG_PROD_SPEC_ID$),          "INT"):@FM
DataFields := "NOTES"               :@VM:SQL_Format(Rec(WO_LOG_NOTES$),                 "STR", 1):@FM
DataFields := "CUST_SHIP_DATE"      :@VM:SQL_Format(Rec(WO_LOG_CUST_SHIP_DATE$),        "DATE"):@FM
DataFields := "STATUS"              :@VM:SQL_Format(Rec(WO_LOG_STATUS$),                "STR"):@FM
DataFields := "ORG_SCHEDULED"       :@VM:SQL_Format(Rec(WO_LOG_ORG_SCHEDULED$),         "BIT"):@FM
DataFields := "RECEIVED_DATE"       :@VM:SQL_Format(Rec(WO_LOG_RECEIVED_DATE$),         "DATE"):@FM
DataFields := "CLOSE_DATE"          :@VM:SQL_Format(Rec(WO_LOG_CLOSE_DATE$),            "DATE"):@FM
DataFields := "RECEIVED_TIME"       :@VM:SQL_Format(Rec(WO_LOG_RECEIVED_TIME$),         "TIME"):@FM
DataFields := "COMMIT_DATE"         :@VM:SQL_Format(Rec(WO_LOG_COMMIT_DATE$),           "DATE"):@FM
DataFields := "CYCLE_TIME"          :@VM:SQL_Format(Rec(WO_LOG_CYCLE_TIME$),            "STR"):@FM
DataFields := "UNIT_PRICE"          :@VM:SQL_Format(Rec(WO_LOG_UNIT_PRICE$),            "STR"):@FM
DataFields := "ORDER_NO"            :@VM:SQL_Format(Rec(WO_LOG_ORDER_NO$),              "STR"):@FM
DataFields := "RX_DTM"              :@VM:SQL_Format(Rec(WO_LOG_RX_DTM$),                "DATETIME"):@FM
DataFields := "OUT_CASS_LOAD_QTY"   :@VM:SQL_Format(Rec(WO_LOG_OUT_CASS_LOAD_QTY$),     "INT"):@FM
DataFields := "PART_NO"             :@VM:SQL_Format(Rec(WO_LOG_PART_NO$),               "STR"):@FM
DataFields := "PROD_ORD_NO"         :@VM:SQL_Format(Rec(WO_LOG_PROD_ORD_NO$),           "STR"):@FM
DataFields := "WO_START_DTM"        :@VM:SQL_Format(Rec(WO_LOG_WO_START_DTM$),          "DATETIME"):@FM
DataFields := "WO_STOP_DTM"         :@VM:SQL_Format(Rec(WO_LOG_WO_STOP_DTM$),           "DATETIME"):@FM
DataFields := "WO_HOLD"             :@VM:SQL_Format(Rec(WO_LOG_WO_HOLD$),               "BIT"):@FM
DataFields := "EPI_PART_NO"         :@VM:SQL_Format(Rec(WO_LOG_EPI_PART_NO$),           "STR"):@FM
DataFields := "ORD_SUB_PART_NO"     :@VM:SQL_Format(Rec(WO_LOG_ORD_SUB_PART_NO$),       "STR"):@FM
DataFields := "ORD_SUB_PART_REV"    :@VM:SQL_Format(Rec(WO_LOG_ORD_SUB_PART_REV$),      "STR"):@FM
DataFields := "CUST_PO_NO"          :@VM:SQL_Format(Rec(WO_LOG_CUST_PO_NO$),            "STR"):@FM
DataFields := "SAP_ORD_QTY"         :@VM:SQL_Format(Rec(WO_LOG_SAP_ORD_QTY$),           "INT"):@FM
DataFields := "CUST_PART_NO"        :@VM:SQL_Format(Rec(WO_LOG_CUST_PART_NO$),          "STR"):@FM
DataFields := "CUST_PART_INBOUND"   :@VM:SQL_Format(Rec(WO_LOG_CUST_PART_INBOUND$),     "STR"):@FM
DataFields := "CUST_SUB_PART_NO"    :@VM:SQL_Format(Rec(WO_LOG_CUST_SUB_PART_NO$),      "STR"):@FM
DataFields := "CUST_SUB_MFR"        :@VM:SQL_Format(Rec(WO_LOG_CUST_SUB_MFR$),          "STR"):@FM
DataFields := "PROD_ORD_NO_TMP"     :@VM:SQL_Format(Rec(WO_LOG_PROD_ORD_NO_TMP$),       "STR"):@FM
DataFields := "ORIGIN"              :@VM:SQL_Format(Rec(WO_LOG_ORIGIN$),                "STR"):@FM
DataFields := "INCO_CODE"           :@VM:SQL_Format(Rec(WO_LOG_INCO_CODE$),             "STR"):@FM
DataFields := "HOT_FLAG"            :@VM:SQL_Format(Rec(WO_LOG_HOT_FLAG$),              "BIT"):@FM
DataFields := "CURR_STATUS_STATIC"  :@VM:SQL_Format(Rec(WO_LOG_CURR_STATUS_STATIC$),    "STR"):@FM
DataFields := "REL_QTY"             :@VM:SQL_Format(Rec(WO_LOG_REL_QTY_STATIC$),		"INT"):@FM
DataFields := "UNREL_QTY"           :@VM:SQL_Format(Rec(WO_LOG_UNREL_QTY_STATIC$),		"INT"):@FM

// Symbolics
DataFields := "START_DT"                :@VM:SQL_Format({START_DT},                 "DATE"):@FM
DataFields := "START_FISCAL_MONTH"      :@VM:SQL_Format({START_FISCAL_MONTH},       "STR"):@FM
DataFields := "START_FISCAL_QUARTER"    :@VM:SQL_Format({START_FISCAL_QUARTER},     "STR"):@FM
DataFields := "START_FISCAL_WEEK"       :@VM:SQL_Format({START_FISCAL_WEEK},        "INT"):@FM
DataFields := "START_FISCAL_YEAR"       :@VM:SQL_Format({START_FISCAL_YEAR},        "STR"):@FM
DataFields := "CYCLE_TIME_WIP"          :@VM:SQL_Format({CYCLE_TIME_WIP},           "DEC", 1):@FM
DataFields := "CYCLE_TIME_DELTA"        :@VM:SQL_Format({CYCLE_TIME_DELTA},         "DEC", 1):@FM
DataFields := "CYCLE_TIME_QA_SHIP"      :@VM:SQL_Format({CYCLE_TIME_QA_SHIP},       "DEC", 1):@FM
DataFields := "CYCLE_TIME_REL_FIRST_VER":@VM:SQL_Format({CYCLE_TIME_REL_FIRST_VER}, "DEC", 1):@FM
DataFields := "SAP_TOT_WFR_QTY"         :@VM:SQL_Format({SAP_TOT_WFR_QTY},          "STR")

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

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

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

// WO_LOG_ORDER_ITEMS
If Ans EQ "" AND Rec(WO_LOG_ORDER_ITEM$) NE "" then
    
    // List of data fields and their values
    MvFields  = "ORDER_ITEM"            :@FM:SQL_Format(Rec(WO_LOG_ORDER_ITEM$),  "STR"):@RM
    MvFields := "ORDER_ITEM_CUST_PN"    :@FM:SQL_Format({ORDER_ITEM_CUST_PN},     "STR"):@RM
    MvFields := "ORDER_ITEM_SUB_PART_NO":@FM:SQL_Format({ORDER_ITEM_SUB_PART_NO}, "STR"):@RM
    MvFields := "ORDER_ITEM_PROMISE_DT" :@FM:SQL_Format({ORDER_ITEM_PROMISE_DT},  "DATE"):@RM
    MvFields := "ORDER_ITEM_QTY"        :@FM:SQL_Format({ORDER_ITEM_QTY},         "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_ORDER_ITEMS", Keys, MvFields);
    
end

// WO_LOG_CASS_NO
If Ans EQ "" AND Rec(WO_LOG_WO_MAT_KEY$) NE "" then
    
    // List of data fields and their values
    MvFields  = "WO_MAT_CASS_NO"          :@FM:SQL_Format({WO_MAT_CASS_NO},           "STR"):@RM
    MvFields := "WO_MAT_LOT_NO"           :@FM:SQL_Format({WO_MAT_LOT_NO},            "STR"):@RM
    MvFields := "WO_MAT_WAFER_QTY"        :@FM:SQL_Format({WO_MAT_WAFER_QTY},         "INT"):@RM
    MvFields := "WO_MAT_CUST_PART_NO"     :@FM:SQL_Format({WO_MAT_CUST_PART_NO},      "STR"):@RM
    MvFields := "WO_MAT_SUB_PART_NO"      :@FM:SQL_Format({WO_MAT_SUB_PART_NO},       "STR"):@RM
    MvFields := "WO_MAT_VEND_CD"          :@FM:SQL_Format({WO_MAT_VEND_CD},           "STR"):@RM
    MvFields := "WO_MAT_EPI_PART_NO"      :@FM:SQL_Format({WO_MAT_EPI_PART_NO},       "STR"):@RM
    MvFields := "WO_MAT_RX_DTM"           :@FM:SQL_Format({WO_MAT_RX_DTM},            "DATETIME"):@RM
    MvFields := "WO_MAT_REL_DTM"          :@FM:SQL_Format({WO_MAT_REL_DTM},           "DATETIME"):@RM
    MvFields := "WO_MAT_CURR_STATUS"      :@FM:SQL_Format({WO_MAT_CURR_STATUS},       "STR"):@RM
    MvFields := "WO_MAT_SAP_TX_DTM"       :@FM:SQL_Format({WO_MAT_SAP_TX_DTM},        "DATETIME"):@RM
    MvFields := "SAP_BATCH_NO"            :@FM:SQL_Format({SAP_BATCH_NO},             "STR"):@RM
    MvFields := "WO_MAT_SAP_YIELD"        :@FM:SQL_Format({WO_MAT_SAP_YIELD},         "INT"):@RM
    MvFields := "WO_MAT_SAP_CONFIRM_SCRAP":@FM:SQL_Format({WO_MAT_SAP_CONFIRM_SCRAP}, "INT"):@RM
    MvFields := "WO_MAT_SAP_GR_QTY"       :@FM:SQL_Format({WO_MAT_SAP_GR_QTY},        "INT"):@RM
    MvFields := "WO_MAT_SAP_RAW_SCRAP_QTY":@FM:SQL_Format({WO_MAT_SAP_RAW_SCRAP_QTY}, "INT"):@RM
    MvFields := "WO_MAT_SAP_PROD_TEST_QTY":@FM:SQL_Format({WO_MAT_SAP_PROD_TEST_QTY}, "INT"):@RM
    MvFields := "WO_MAT_SAP_MU_QTY"       :@FM:SQL_Format({WO_MAT_SAP_MU_QTY},        "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_CASS_NO", Keys, MvFields);
    
end

// WO_LOG_ADD_CHG
If Ans EQ "" AND Rec(WO_LOG_ADD_CHG_AMT$) NE "" then
    
    // List of data fields and their values
    MvFields  = "ADD_CHG_DESC"    :@FM:SQL_Format(Rec(WO_LOG_ADD_CHG_DESC$),     "STR"):@RM
    MvFields := "ADD_CHG_AMT"     :@FM:SQL_Format(Rec(WO_LOG_ADD_CHG_AMT$),      "DEC", 2):@RM
    MvFields := "ADD_CHG_ORD_ITEM":@FM:SQL_Format(Rec(WO_LOG_ADD_CHG_ORD_ITEM$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_ADD_CHG", Keys, MvFields);
    
end

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

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

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

// WO_LOG_PART_STEP_NO
If Ans EQ "" AND Rec(WO_LOG_PROD_VER_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "PROD_VER_STEP_NO"         :@FM:SQL_Format({PROD_VER_STEP_NO},          "INT"):@RM
    MvFields := "PROD_VER_STEP_PSN"        :@FM:SQL_Format({PROD_VER_STEP_PSN},         "STR"):@RM
    MvFields := "PROD_VER_STEP_DOPANT"     :@FM:SQL_Format({PROD_VER_STEP_DOPANT},      "STR"):@RM
    MvFields := "PROD_VER_STEP_THICK_TARG" :@FM:SQL_Format({PROD_VER_STEP_THICK_TARG},  "DEC", 2):@RM
    MvFields := "PROD_VER_STEP_THICK_UNITS":@FM:SQL_Format({PROD_VER_STEP_THICK_UNITS}, "STR"):@RM
    MvFields := "PROD_VER_STEP_RES_TARG"   :@FM:SQL_Format({PROD_VER_STEP_RES_TARG},    "DEC", 3):@RM
    MvFields := "PROD_VER_STEP_RES_UNITS"  :@FM:SQL_Format({PROD_VER_STEP_RES_UNITS},   "STR"):@RM
    MvFields := "PROD_VER_STEP_DESC"       :@FM:SQL_Format({PROD_VER_STEP_DESC},        "DATETIME"):@RM
    MvFields := "WO_STEP_CURR_STATUS"      :@FM:SQL_Format({WO_STEP_CURR_STATUS},       "DATETIME"):@RM
    MvFields := "WO_STEP_SCHEDULED"        :@FM:SQL_Format({WO_STEP_SCHEDULED},         "BIT"):@RM
    MvFields := "WO_STEP_SCHED_DTM"        :@FM:SQL_Format({WO_STEP_SCHED_DTM},         "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_PART_STEP_NO", Keys, MvFields);
    
end

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

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

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

// WO_LOG_SHIP_NO
ShipNo = {SHIP_NO}
If Ans EQ "" AND ShipNo NE "" then
    
    // List of data fields and their values
    MvFields  = "SHIP_NO"      :@FM:SQL_Format(ShipNo,          "STR"):@RM
    MvFields := "SHIP_DT"      :@FM:SQL_Format({SHIP_DT},       "DATE"):@RM
    MvFields := "SHIP_LOT_NOS" :@FM:SQL_Format({SHIP_LOT_NOS},  "STR"):@RM
    MvFields := "SHIP_INV_NO"  :@FM:SQL_Format({SHIP_INV_NO},   "STR"):@RM
    MvFields := "SHIP_WFR_QTY" :@FM:SQL_Format({SHIP_WFR_QTY},  "INT"):@RM
    MvFields := "SHIP_REJ_QTY" :@FM:SQL_Format({SHIP_REJ_QTY},  "INT"):@RM
    MvFields := "SHIP_PROD_QTY":@FM:SQL_Format({SHIP_PROD_QTY}, "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_SHIP_NO", Keys, MvFields);
    
end

// WO_LOG_PSN_SUB_PART_NO
PsnSubPartNo = {PSN_SUB_PART_NO}
PsnSubPartMfg = {PSN_SUB_PART_MFG}
If Ans EQ "" AND (PsnSubPartNo NE "" OR PsnSubPartMfg NE "") then
    
    // List of data fields and their values
    MvFields  = "PSN_SUB_PART_NO" :@FM:SQL_Format(PsnSubPartNo,  "STR"):@RM
    MvFields := "PSN_SUB_PART_MFG":@FM:SQL_Format(PsnSubPartMfg, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_PSN_SUB_PART_NO", Keys, MvFields);
    
end

// WO_LOG_PROC_STEP
If Ans EQ "" AND Rec(WO_LOG_QUOTE_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "QUOTE_STEP"       :@FM:SQL_Format({QUOTE_STEP},        "INT"):@RM
    MvFields := "QUOTE_STEP_PSN"   :@FM:SQL_Format({QUOTE_STEP_PSN},    "STR"):@RM
    MvFields := "QUOTE_STEP_DOPANT":@FM:SQL_Format({QUOTE_STEP_DOPANT}, "STR"):@RM
    MvFields := "THICK_TARGET_L1"  :@FM:SQL_Format({THICK_TARGET_L1},   "DEC", 2):@RM
    MvFields := "THICK_UNITS_L1"   :@FM:SQL_Format({THICK_UNITS_L1},    "STR"):@RM
    MvFields := "RES_TARGET_L1"    :@FM:SQL_Format({RES_TARGET_L1},     "DEC", 2):@RM
    MvFields := "RES_UNITS_L1"     :@FM:SQL_Format({RES_UNITS_L1},      "STR"):@RM
    MvFields := "WO_STEP_DESC"     :@FM:SQL_Format({WO_STEP_DESC},      "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_PROC_STEP", Keys, MvFields);
    
end

// WO_LOG_WO_STEP
If Ans EQ "" AND Rec(WO_LOG_WO_STEP_KEY$) NE "" then
    
    // List of data fields and their values
    MvFields  = "WO_STEP"            :@FM:SQL_Format({WO_STEP},             "INT"):@RM
    MvFields := "WO_STEP_PSN"        :@FM:SQL_Format({WO_STEP_PSN},         "STR"):@RM
    MvFields := "WO_STEP_CURR_STATUS":@FM:SQL_Format({WO_STEP_CURR_STATUS}, "STR"):@RM
    MvFields := "WO_STEP_SCHEDULED"  :@FM:SQL_Format({WO_STEP_SCHEDULED},   "BIT"):@RM
    MvFields := "WO_STEP_SCHED_DTM"  :@FM:SQL_Format({WO_STEP_SCHED_DTM},   "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WO_LOG_WO_STEP", Keys, MvFields);
    
end

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

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

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

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

Return Ans

