Compile function Copy_RDS_Record_To_SQL(Connection, Key, Record)

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

$insert RDS_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(307)
MatParse Record into Rec
Rec(307) = Rec(307)[1, @FM]

// List of key names and their values
Keys = "SEQ":@VM:SQL_Format(Key, "INT")

// List of data fields and their values
DataFields  = ''
DataFields := "DATE_OUT"                :@VM:SQL_Format({DATE_OUT},                         "DATE"):@FM
DataFields := "WO"                      :@VM:SQL_Format({WO},                               "INT"):@FM
DataFields := "SAP_BATCH_NO"            :@VM:SQL_Format({SAP_BATCH_NO},                     "STR"):@FM
DataFields := "REACTOR"                 :@VM:SQL_Format({REACTOR},                          "INT"):@FM
DataFields := "REACTOR_TYPE"            :@VM:SQL_Format({REACTOR_TYPE},                     "STR"):@FM
DataFields := "WFRS_OUT"                :@VM:SQL_Format({WAFERS_IN},                        "INT"):@FM
DataFields := "WAFER_MM"                :@VM:SQL_Format({WAFER_MM},                         "STR"):@FM
DataFields := "CUST_NAME"               :@VM:SQL_Format({CUST_NAME}[1,50],                  "STR"):@FM
DataFields := "CUST_NO"                 :@VM:SQL_Format({CUST_NO},                          "INT"):@FM
DataFields := "PART_NUM"                :@VM:SQL_Format({PART_NUM},                         "STR"):@FM
DataFields := "PROD_SPEC_ID"            :@VM:SQL_Format({PROD_SPEC_ID},                     "INT"):@FM
DataFields := "SUB_PART_NUM"            :@VM:SQL_Format({SUB_PART_NUM},                     "STR"):@FM
DataFields := "SUB_PART_MFG"            :@VM:SQL_Format({SUB_PART_MFG},                     "STR"):@FM
DataFields := "LOT_NUM"                 :@VM:SQL_Format({LOT_NUM},                          "STR"):@FM
DataFields := "THICK_MIN"               :@VM:SQL_Format({THICK_MIN},                        "INT"):@FM
DataFields := "THICK_TARGET"            :@VM:SQL_Format({THICK_TARGET},                     "INT"):@FM
DataFields := "THICK_MAX"               :@VM:SQL_Format({THICK_MAX},                        "INT"):@FM
DataFields := "RES_MIN"                 :@VM:SQL_Format({RES_MIN},                          "INT"):@FM
DataFields := "RES_TARGET"              :@VM:SQL_Format({RES_TARGET},                       "INT"):@FM
DataFields := "RES_MAX"                 :@VM:SQL_Format({RES_MAX},                          "INT"):@FM
DataFields := "L80_THICK"               :@VM:SQL_Format({L80_THICK},                        "INT"):@FM
DataFields := "L70_THICK"               :@VM:SQL_Format({L70_THICK},                        "INT"):@FM
DataFields := "L60_THICK"               :@VM:SQL_Format({L60_THICK},                        "INT"):@FM
DataFields := "L50_THICK"               :@VM:SQL_Format({L50_THICK},                        "INT"):@FM
DataFields := "L40_THICK"               :@VM:SQL_Format({L40_THICK},                        "INT"):@FM
DataFields := "L30_THICK"               :@VM:SQL_Format({L30_THICK},                        "INT"):@FM
DataFields := "L20_THICK"               :@VM:SQL_Format({L20_THICK},                        "INT"):@FM
DataFields := "L10_THICK"               :@VM:SQL_Format({L10_THICK},                        "INT"):@FM
DataFields := "C_THICK"                 :@VM:SQL_Format({C_THICK},                          "INT"):@FM
DataFields := "R10_THICK"               :@VM:SQL_Format({R10_THICK},                        "INT"):@FM
DataFields := "R20_THICK"               :@VM:SQL_Format({R20_THICK},                        "INT"):@FM
DataFields := "R30_THICK"               :@VM:SQL_Format({R30_THICK},                        "INT"):@FM
DataFields := "R40_THICK"               :@VM:SQL_Format({R40_THICK},                        "INT"):@FM
DataFields := "R50_THICK"               :@VM:SQL_Format({R50_THICK},                        "INT"):@FM
DataFields := "R60_THICK"               :@VM:SQL_Format({R60_THICK},                        "INT"):@FM
DataFields := "R70_THICK"               :@VM:SQL_Format({R70_THICK},                        "INT"):@FM
DataFields := "R80_THICK"               :@VM:SQL_Format({R80_THICK},                        "INT"):@FM
DataFields := "THICK_AVG"               :@VM:SQL_Format({TTHICK_AVG}<0,1>,                  "INT"):@FM
DataFields := "THICK_STDEV"             :@VM:SQL_Format({TTHICK_STDEV},                     "INT"):@FM
DataFields := "L80_RES"                 :@VM:SQL_Format({L80_RES},                          "INT"):@FM
DataFields := "L70_RES"                 :@VM:SQL_Format({L70_RES},                          "INT"):@FM
DataFields := "L60_RES"                 :@VM:SQL_Format({L60_RES},                          "INT"):@FM
DataFields := "L50_RES"                 :@VM:SQL_Format({L50_RES},                          "INT"):@FM
DataFields := "L40_RES"                 :@VM:SQL_Format({L40_RES},                          "INT"):@FM
DataFields := "L30_RES"                 :@VM:SQL_Format({L30_RES},                          "INT"):@FM
DataFields := "L20_RES"                 :@VM:SQL_Format({L20_RES},                          "INT"):@FM
DataFields := "L10_RES"                 :@VM:SQL_Format({L10_RES},                          "INT"):@FM
DataFields := "C_RES"                   :@VM:SQL_Format({C_RES},                            "INT"):@FM
DataFields := "R10_RES"                 :@VM:SQL_Format({R10_RES},                          "INT"):@FM
DataFields := "R20_RES"                 :@VM:SQL_Format({R20_RES},                          "INT"):@FM
DataFields := "R30_RES"                 :@VM:SQL_Format({R30_RES},                          "INT"):@FM
DataFields := "R40_RES"                 :@VM:SQL_Format({R40_RES},                          "INT"):@FM
DataFields := "R50_RES"                 :@VM:SQL_Format({R50_RES},                          "INT"):@FM
DataFields := "R60_RES"                 :@VM:SQL_Format({R60_RES},                          "INT"):@FM
DataFields := "R70_RES"                 :@VM:SQL_Format({R70_RES},                          "INT"):@FM
DataFields := "R80_RES"                 :@VM:SQL_Format({R80_RES},                          "INT"):@FM
DataFields := "RES_AVG"                 :@VM:SQL_Format({TRES_AVG},                         "INT"):@FM
DataFields := "RES_STDEV"               :@VM:SQL_Format({TRES_STDEV},                       "INT"):@FM
DataFields := "THICK_TARGET_TOT"        :@VM:SQL_Format({THICK_TARGET_TOT},                 "INT"):@FM
DataFields := "TW_PROD"                 :@VM:SQL_Format({TW_PROD},                          "INT"):@FM
DataFields := "CUST_TOT_REJ"            :@VM:SQL_Format({CUST_TOT_REJ},                     "INT"):@FM
DataFields := "LSL_TOT_REJ"             :@VM:SQL_Format({LSL_TOT_REJ},                      "INT"):@FM
DataFields := "PROD_ORD_NO"             :@VM:SQL_Format({PROD_ORD_NO},                      "STR")
// Insert 
// Write the data to the SQL database
Ans = SQL_Write(Connection, "RDS", Keys, DataFields)

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

//HOLD_INFO
If Ans EQ "" AND Rec(194) NE "" then
    // List of data fields and their values
    MvFields  = "HOLD_DESC"    :@FM:SQL_Format(Rec(194), "STR"):@RM
    MvFields := "HOLD_OPERATOR":@FM:SQL_Format(Rec(196), "STR"):@RM
    MvFields := "HOLD_DATE_ORG":@FM:SQL_Format(Rec(197), "DATE"):@RM
    MvFields := "HOLD_TIME_ORG":@FM:SQL_Format(Rec(198), "TIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "RDS_HOLD_INFO", Keys, MvFields);
end

//SURFSCAN_KEYS
If Ans EQ "" AND Rec(255) NE "" then
    MvFields  = "SURFSCAN_KEY":@FM:SQL_Format(Rec(255), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_SURFSCAN_KEYS", Keys, MvFields);
end

//NCR_KEYS
If Ans EQ "" AND Rec(257) NE "" then
    MvFields  = "NCR_KEYS":@FM:SQL_Format(Rec(257), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_NCR_KEYS", Keys, MvFields);
end

//RDS_LAYER_KEYS
If Ans EQ "" AND Rec(150) NE "" then
    MvFields  = "RDS_LAYER_KEYS":@FM:SQL_Format(Rec(150), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_RDS_LAYER_KEYS", Keys, MvFields);
end

//UNLOAD_MOD_ID
If Ans EQ "" AND Rec(151) NE "" then
    MvFields  = "UNLOAD_MOD_ID":@FM:SQL_Format(Rec(151), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_UNLOAD_MOD_ID", Keys, MvFields);
end

// TW_INFO
If Ans EQ "" AND (Rec(30) NE "" OR Rec(28) NE "" OR Rec(77) NE "" or Rec(106) NE "" or Rec(164) NE "" or Rec(106) NE "240") then
    MvFields  = "TW_PMINUS_TRANS":@FM:SQL_Format(Rec(28), "DEC", "2"):@RM
    MvFields := "TW_PROD_RHO":@FM:SQL_Format(Rec(30), "INT"):@RM
    MvFields := "TW_PPLUS_TRANS":@FM:SQL_Format(Rec(77), "DEC", "2"):@RM
    MvFields := "TW_PROD_STRESS":@FM:SQL_Format(Rec(79), "STR"):@RM
    MvFields := "TW_PROD_ORIG":@FM:SQL_Format(Rec(81), "INT"):@RM
    MvFields := "TW_PPLUS_CODE":@FM:SQL_Format(Rec(106), "INT"):@RM
    MvFields := "TW_PMINUS_CODE":@FM:SQL_Format(Rec(107), "INT"):@RM
    MvFields := "TW_NPLUS_CODE":@FM:SQL_Format(Rec(108), "INT"):@RM
    MvFields := "TW_NMINUS_CODE":@FM:SQL_Format(Rec(109), "INT"):@RM
    MvFields := "TW_PPLUS_CNT":@FM:SQL_Format(Rec(110), "INT"):@RM
    MvFields := "TW_PMINUS_CNT":@FM:SQL_Format(Rec(111), "INT"):@RM
    MvFields := "TW_NPLUS_CNT":@FM:SQL_Format(Rec(112), "INT"):@RM
    MvFields := "TW_NMINUS_CNT":@FM:SQL_Format(Rec(113), "INT"):@RM
    MvFields := "TW_NMINUS_RHO":@FM:SQL_Format(Rec(138), "INT"):@RM
    MvFields := "TW_NPLUS_RHO":@FM:SQL_Format(Rec(139), "INT"):@RM
    MvFields := "TW_PMINUS_RHO":@FM:SQL_Format(Rec(140), "INT"):@RM
    MvFields := "TW_PPLUS_RHO":@FM:SQL_Format(Rec(141), "INT"):@RM
    MvFields := "TW_PROD_TRANS":@FM:SQL_Format(Rec(142), "DEC", "2"):@RM
    MvFields := "TW_NMINUS_TRANS":@FM:SQL_Format(Rec(143), "DEC", "2"):@RM
    MvFields := "TW_NPLUS_TRANS":@FM:SQL_Format(Rec(152), "DEC", "2"):@RM
    MvFields := "TW_PROD_CODE":@FM:SQL_Format(Rec(164), "INT"):@RM
    MvFields := "TW_PROD_CNT":@FM:SQL_Format(Rec(165), "INT"):@RM
    MvFields := "TW_PPLUS_TOOL":@FM:SQL_Format(Rec(166), "STR"):@RM
    MvFields := "TW_PMINUS_TOOL":@FM:SQL_Format(Rec(167), "STR"):@RM
    MvFields := "TW_NPLUS_TOOL":@FM:SQL_Format(Rec(168), "STR"):@RM
    MvFields := "TW_NMINUS_TOOL":@FM:SQL_Format(Rec(169), "STR"):@RM
    MvFields := "TW_PROD_TOOL":@FM:SQL_Format(Rec(170), "STR"):@RM
    MvFields := "TW_PPLUS_THICK":@FM:SQL_Format(Rec(171), "DEC", "2"):@RM
    MvFields := "TW_PMINUS_THICK":@FM:SQL_Format(Rec(172), "DEC", "2"):@RM
    MvFields := "TW_NPLUS_THICK":@FM:SQL_Format(Rec(173), "DEC", "2"):@RM
    MvFields := "TW_NMINUS_THICK":@FM:SQL_Format(Rec(174), "DEC", "2"):@RM
    MvFields := "TW_PROD_THICK":@FM:SQL_Format(Rec(175), "DEC", "2"):@RM
    MvFields := "TW_PPLUS_RES":@FM:SQL_Format(Rec(176), "DEC", "3"):@RM
    MvFields := "TW_PMINUS_RES":@FM:SQL_Format(Rec(177), "DEC", "3"):@RM
    MvFields := "TW_NPLUS_RES":@FM:SQL_Format(Rec(178), "DEC", "3"):@RM
    MvFields := "TW_NMINUS_RES":@FM:SQL_Format(Rec(179), "DEC", "3"):@RM
    MvFields := "TW_PROD_RES":@FM:SQL_Format(Rec(180), "DEC", "3"):@RM
    MvFields := "TW_PPLUS_CON":@FM:SQL_Format(Rec(181), "STR"):@RM
    MvFields := "TW_PMINUS_CON":@FM:SQL_Format(Rec(182), "STR"):@RM
    MvFields := "TW_NPLUS_CON":@FM:SQL_Format(Rec(183), "STR"):@RM
    MvFields := "TW_NMINUS_CON":@FM:SQL_Format(Rec(184), "STR"):@RM
    MvFields := "TW_PROD_CON":@FM:SQL_Format(Rec(185), "STR"):@RM
    MvFields := "TW_PPLUS_STRESS":@FM:SQL_Format(Rec(186), "STR"):@RM
    MvFields := "TW_PMINUS_STRES":@FM:SQL_Format(Rec(187), "STR"):@RM
    MvFields := "TW_NPLUS_STRESS":@FM:SQL_Format(Rec(188), "STR"):@RM
    MvFields := "TW_NMINUS_STRESS":@FM:SQL_Format(Rec(189), "STR"):@RM
    MvFields := "TW_RECLAIM_ORG":@FM:SQL_Format(Rec(240), "INT"):@RM
    MvFields := "TW_RECLAIM_CODE":@FM:SQL_Format(Rec(241), "INT"):@RM
    MvFields := "TW_RECLAIM_CNT":@FM:SQL_Format(Rec(242), "INT"):@RM
    MvFields := "TW_RECLAIM_CON":@FM:SQL_Format(Rec(243), "STR"):@RM
    MvFields := "TW_RECLAIM_RES":@FM:SQL_Format(Rec(244), "DEC", "3"):@RM
    MvFields := "TW_RECLAIM_RHO":@FM:SQL_Format(Rec(245), "INT"):@RM
    MvFields := "TW_RECLAIM_STRESS":@FM:SQL_Format(Rec(246), "STR"):@RM
    MvFields := "TW_RECLAIM_THICK":@FM:SQL_Format(Rec(247), "DEC", "2"):@RM
    MvFields := "TW_RECLAIM_TOOL":@FM:SQL_Format(Rec(248), "STR"):@RM
    MvFields := "TW_RECLAIM_TRANS":@FM:SQL_Format(Rec(249), "DEC", "2")
    Ans = SQL_Write_MV(Connection, "RDS_TW_INFO", Keys, MvFields);
end

//UNHOLD
If Ans EQ "" AND Rec(72) NE "" then
    MvFields  = "UNHOLD_OPERATOR":@FM:SQL_Format(Rec(72), "STR"):@RM
    MvFields := "UNHOLD_DATE":@FM:SQL_Format(Rec(73), "DATE"):@RM
    MvFields := "UNHOLD_TIME":@FM:SQL_Format(Rec(74), "TIME"):@RM
    MvFields := "UNHOLD_DESC":@FM:SQL_Format(Rec(199), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_UNHOLD", Keys, MvFields);
end

//POCKET
If Ans EQ "" AND Rec(267) NE "" then
    MvFields  = "POCKET":@FM:SQL_Format(Rec(267), "STR"):@RM
    MvFields := "POCKET_CHAR":@FM:SQL_Format(Rec(268), "STR"):@RM
    MvFields := "ZONE":@FM:SQL_Format(Rec(269), "STR"):@RM
    MvFields := "IN_CASS_NO":@FM:SQL_Format(Rec(270), "INT"):@RM
    MvFields := "IN_SLOT_NO":@FM:SQL_Format(Rec(271), "INT"):@RM
    MvFields := "OUT_CASS_NO":@FM:SQL_Format(Rec(272), "INT"):@RM
    MvFields := "OUT_SLOT_NO":@FM:SQL_Format(Rec(273), "INT"):@RM
    MvFields := "WAFER_CHAR":@FM:SQL_Format(Rec(275), "STR"):@RM
    MvFields := "OUT_NCR":@FM:SQL_Format(Rec(276), "STR")
    Ans = SQL_Write_MV(Connection, "RDS_POCKET", Keys, MvFields);
end

// PRE_EPI_SIG_INFO
If Ans EQ "" AND (Rec(126) OR Rec(132)) NE "" then
    MvFields  = "PRE_CODE":@FM:SQL_Format(Rec(126), "STR"):@RM
    MvFields := "PRE_BOAT_ID":@FM:SQL_Format(Rec(127), "STR"):@RM
    MvFields := "PRE_SRD_NUM":@FM:SQL_Format(Rec(128), "INT"):@RM
    MvFields := "PRE_EPI_SIG":@FM:SQL_Format(Rec(132), "STR"):@RM
    MvFields := "PRE_EPI_DATE":@FM:SQL_Format(Rec(133), "DATE"):@RM
    MvFields := "PRE_EPI_TIME":@FM:SQL_Format(Rec(134), "TIME")
    Ans = SQL_Write_MV(Connection, "RDS_PRE_EPI_SIG_INFO", Keys, MvFields);
end

// Modification
If Ans EQ "" AND Rec(82) NE "" then
    MvFields  = "MOD_ID":@FM:SQL_Format(Rec(82), "STR"):@RM
    MvFields := "MOD_DATE":@FM:SQL_Format(Rec(83), "DATE")
    Ans = SQL_Write_MV(Connection, "RDS_MOD_INFO", Keys, MvFields);
end

// RDS Comments
If Ans EQ "" AND Rec(305) NE "" then
    MvFields  = "COMMENT_DATE":@FM:SQL_Format(Rec(305), "DATETIME"):@RM
    MvFields := "COMMENT_USER":@FM:SQL_Format(Rec(306), "STR"):@RM
    MvFields := "COMMENT_NOTE":@FM:SQL_Format(Rec(307), "STR")
    Ans       = SQL_Write_MV(Connection, "RDS_COMMENT", Keys, MvFields);
end

/*
    // SKELETON CODE
        // List of data fields and their values
        MvFields  = "":@FM:SQL_Format(Rec(), "INT"):@RM
        MvFields := "":@FM:SQL_Format(Rec(), "STR"):@RM
        MvFields := "":@FM:SQL_Format(Rec(), "STR")
        
        // Write the data to the SQL database
        Ans = SQL_Write_MV(Connection, "", Keys, MvFields);
    end
    */

Return Ans




