Compile function Copy_COC_Record_To_SQL(Connection, Key, Record)

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

$insert COC_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

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

// List of data fields and their values
DataFields  = "ENTRY_ID"         :@VM:SQL_Format(Rec(COC_ENTRY_ID$),          "STR"):@FM
DataFields := "ENTRY_DATE"       :@VM:SQL_Format(Rec(COC_ENTRY_DATE$),        "DATE"):@FM
DataFields := "PO"               :@VM:SQL_Format(Rec(COC_PO$),                "STR"):@FM
DataFields := "WO"               :@VM:SQL_Format(Rec(COC_WO$),                "STR"):@FM
DataFields := "CUST_NO_ORG"      :@VM:SQL_Format(Rec(COC_CUST_NO_ORG$),       "INT"):@FM
DataFields := "SHIPMENT"         :@VM:SQL_Format(Rec(COC_SHIPMENT$),          "INT"):@FM
DataFields := "SHIP_VIA"         :@VM:SQL_Format(Rec(COC_SHIP_VIA$),          "STR"):@FM
DataFields := "SHIP_VIA_ACCT_NO" :@VM:SQL_Format(Rec(COC_SHIP_VIA_ACCT_NO$),  "STR"):@FM
DataFields := "PICK_BY"          :@VM:SQL_Format(Rec(COC_PICK_BY$),           "STR"):@FM
DataFields := "PICK_DTM"         :@VM:SQL_Format(Rec(COC_PICK_DTM$),          "DATETIME"):@FM
* DataFields := "INVOICE_NO"       :@VM:SQL_Format(Rec(COC_INVOICE_NO$),        "STR"):@FM
DataFields := "SHIP_DT"          :@VM:SQL_Format(Rec(COC_SHIP_DT$),           "DATE"):@FM
DataFields := "VISION_DTM"       :@VM:SQL_Format(Rec(COC_VISION_DTM$),        "DATETIME"):@FM
DataFields := "VISION_ORD_REL_NO":@VM:SQL_Format(Rec(COC_VISION_ORD_REL_NO$), "INT"):@FM
DataFields := "REACTOR_TYPE"     :@VM:SQL_Format(Rec(COC_REACTOR_TYPE$),      "STR"):@FM
DataFields := "SAP_DEL_NO"       :@VM:SQL_Format(Rec(COC_SAP_DEL_NO$),        "STR"):@FM

// Symbolics
DataFields := "CUST_NO"          :@VM:SQL_Format({CUST_NO},                   "STR"):@FM
DataFields := "CUST_PART_NO"     :@VM:SQL_Format({CUST_PART_NO},              "STR"):@FM
DataFields := "PROD_ORD_NO"      :@VM:SQL_Format({PROD_ORD_NO},               "STR"):@FM
DataFields := "PROD_SPEC_ID"     :@VM:SQL_Format({PROD_SPEC_ID},              "STR"):@FM
DataFields := "COMMIT_DATE"      :@VM:SQL_Format({COMMIT_DATE},               "DATE")

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

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

// Shipping Details
If Ans EQ "" AND Rec(COC_ORDER_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "ORDER_NO"  :@FM:SQL_Format(Rec(COC_ORDER_NO$),   "INT"):@RM
    MvFields := "ORDER_LINE":@FM:SQL_Format(Rec(COC_ORDER_LINE$), "INT"):@RM
    MvFields := "RDS_NO"    :@FM:SQL_Format(Rec(COC_RDS_NO$),     "STR"):@RM
    MvFields := "PART_NUM"  :@FM:SQL_Format(Rec(COC_PART_NUM$),   "STR"):@RM
    MvFields := "LOT_NUM"   :@FM:SQL_Format(Rec(COC_LOT_NUM$),    "STR"):@RM
    MvFields := "REACTOR"   :@FM:SQL_Format(Rec(COC_REACTOR$),    "INT"):@RM
    MvFields := "REJECTS"   :@FM:SQL_Format(Rec(COC_REJECTS$),    "INT"):@RM
    MvFields := "WAFER_QTY" :@FM:SQL_Format(Rec(COC_WAFER_QTY$),  "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_SHIPPING_DETAILS", Keys, MvFields);
    
end

// Tracking Details
If Ans EQ "" AND Rec(COC_TRACKING_NOS$) NE "" then
    
    // List of data fields and their values
    MvFields  = "TRACKING_NOS"    :@FM:SQL_Format(Rec(COC_TRACKING_NOS$),     "STR"):@RM
    MvFields := "TRACK_NO_BOX_CNT":@FM:SQL_Format(Rec(COC_TRACK_NO_BOX_CNT$), "INT"):@RM
    MvFields := "TRACK_NO_SHIP_WT":@FM:SQL_Format(Rec(COC_TRACK_NO_SHIP_WT$), "INT"):@RM
    MvFields := "TRACK_NO_LEN"    :@FM:SQL_Format(Rec(COC_TRACK_NO_LEN$),     "INT"):@RM
    MvFields := "TRACK_NO_WIDTH"  :@FM:SQL_Format(Rec(COC_TRACK_NO_WIDTH$),   "INT"):@RM
    MvFields := "TRACK_NO_HEIGHT" :@FM:SQL_Format(Rec(COC_TRACK_NO_HEIGHT$),  "INT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_TRACKING_DETAILS", Keys, MvFields);
    
end

// Vision Log
If Ans EQ "" AND Rec(COC_SEND_USER$) NE "" then
    
    // List of data fields and their values
    MvFields  = "SEND_DTM"   :@FM:SQL_Format(Rec(COC_SEND_DTM$),    "DATETIME"):@RM
    MvFields := "SEND_USER"  :@FM:SQL_Format(Rec(COC_SEND_USER$),   "STR"):@RM
    MvFields := "SEND_REASON":@FM:SQL_Format(Rec(COC_SEND_REASON$), "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_VISION_LOGS", Keys, MvFields);
    
end

// RDS Details
If Ans EQ "" AND (Rec(COC_WO_STEP$) NE "" OR Rec(COC_CASS_NO$) NE "") then
    
    // List of data fields and their values
    MvFields  = "WO_STEP"      :@FM:SQL_Format(Rec(COC_WO_STEP$),       "INT"):@RM
    MvFields := "CASS_NO"      :@FM:SQL_Format(Rec(COC_CASS_NO$),       "INT"):@RM
    MvFields := "RDS_NO"       :@FM:SQL_Format(Rec(COC_RDS_NO$),        "STR"):@RM
    MvFields := "CASS_RETURNED":@FM:SQL_Format(Rec(COC_CASS_RETURNED$), "BIT")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_RDS_DETAILS", Keys, MvFields);
    
end

// Order Items
If Ans EQ "" AND Rec(COC_ORDER_ITEM$) NE "" then
    
    // List of data fields and their values
    MvFields  = "ORDER_ITEM"     :@FM:SQL_Format(Rec(COC_ORDER_ITEM$),      "INT"):@RM
    MvFields := "ITEM_WFR_QTY"   :@FM:SQL_Format(Rec(COC_ITEM_WFR_QTY$),    "INT"):@RM
    MvFields := "ITEM_MISC_QTY"  :@FM:SQL_Format(Rec(COC_ITEM_MISC_QTY$),   "INT"):@RM
    MvFields := "ITEM_UNIT_PRICE":@FM:SQL_Format(Rec(COC_ITEM_UNIT_PRICE$), "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_ORDER_ITEMS", Keys, MvFields);
    
end

// Test Rej Wfrs
If Ans EQ "" AND Rec(COC_TEST_REJ_WFR_QTY$) NE "" then
    
    // List of data fields and their values
    MvFields  = "TEST_REJ_WFR_QTY"       :@FM:SQL_Format(Rec(COC_TEST_REJ_WFR_QTY$),        "INT"):@RM
    MvFields := "TEST_REJ_WFR_UNIT_PRICE":@FM:SQL_Format(Rec(COC_TEST_REJ_WFR_UNIT_PRICE$), "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "COC_TEST_REJ_WFRS", Keys, MvFields);
    
end

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

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

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

// COC_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, "COC_CASS_ID_SAP", Keys, MvFields);
    
end

Return Ans
