Compile function Copy_WM_OUT_Record_To_SQL(Connection, Key, Record)

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

$insert WM_OUT_EQUATES

Declare function SQL_Write, SQL_Write_MV, SQL_Format
Ans = ""

// Parse record into a dimensioned array for speed
Dim Rec(67)
MatParse Record into Rec
					    
// List of key names and their values
Keys  = "WO_NO"       :@VM:SQL_Format(Field(Key, "*", 1), "INT"):@FM
Keys := "PROC_STEP_NO":@VM:SQL_Format(Field(Key, "*", 2), "INT"):@FM
Keys := "OUT_CASS_NO" :@VM:SQL_Format(Field(Key, "*", 3), "INT")

// List of data fields and their values
DataFields  = "POST_CODE"        :@VM:SQL_Format(Rec(WM_OUT_POST_CODE$),         "STR"):@FM
DataFields := "POST_BOAT_ID"     :@VM:SQL_Format(Rec(WM_OUT_POST_BOAT_ID$),      "STR"):@FM
DataFields := "POST_SRD_NO"      :@VM:SQL_Format(Rec(WM_OUT_POST_SRD_NO$),       "INT"):@FM
DataFields := "POST_EPI_SIG"     :@VM:SQL_Format(Rec(WM_OUT_POST_EPI_SIG$),      "STR"):@FM
DataFields := "POST_EPI_SIG_DTM" :@VM:SQL_Format(Rec(WM_OUT_POST_EPI_SIG_DTM$),  "DATETIME"):@FM
DataFields := "POST_PITS"        :@VM:SQL_Format(Rec(WM_OUT_POST_PITS$),         "STR"):@FM
DataFields := "POST_MOUNDS"      :@VM:SQL_Format(Rec(WM_OUT_POST_MOUNDS$),       "STR"):@FM
DataFields := "POST_STACK_FAULTS":@VM:SQL_Format(Rec(WM_OUT_POST_STACK_FAULTS$), "INT"):@FM
DataFields := "POST_SPOTS"       :@VM:SQL_Format(Rec(WM_OUT_POST_SPOTS$),        "INT"):@FM
DataFields := "POST_FOV"         :@VM:SQL_Format(Rec(WM_OUT_POST_FOV$),          "INT"):@FM
DataFields := "POST_BL_DEFECTS"  :@VM:SQL_Format(Rec(WM_OUT_POST_BL_DEFECTS$),   "INT"):@FM
DataFields := "POST_SPIKES"      :@VM:SQL_Format(Rec(WM_OUT_POST_SPIKES$),       "INT"):@FM
DataFields := "POST_SCRATCHES"   :@VM:SQL_Format(Rec(WM_OUT_POST_SCRATCHES$),    "INT"):@FM
DataFields := "POST_SCRATCH_LEN" :@VM:SQL_Format(Rec(WM_OUT_POST_SCRATCH_LEN$),  "INT"):@FM
DataFields := "LPD_FIRSTWAFER"   :@VM:SQL_Format(Rec(WM_OUT_LPD_FIRSTWAFER$),    "INT"):@FM
DataFields := "LPD_POSTCLEAN"    :@VM:SQL_Format(Rec(WM_OUT_LPD_POSTCLEAN$),     "INT"):@FM
DataFields := "SHIFT"            :@VM:SQL_Format(Rec(WM_OUT_SHIFT$),             "STR"):@FM
DataFields := "SUP_VER_SIG"      :@VM:SQL_Format(Rec(WM_OUT_SUP_VER_SIG$),       "STR"):@FM
DataFields := "SUP_VER_SIG_DTM"  :@VM:SQL_Format(Rec(WM_OUT_SUP_VER_SIG_DTM$),   "DATETIME"):@FM
DataFields := "SHIP_NO"          :@VM:SQL_Format(Rec(WM_OUT_SHIP_NO$),           "STR"):@FM
DataFields := "POST_CLEAN"       :@VM:SQL_Format(Rec(WM_OUT_POST_CLEAN$),        "STR"):@FM
DataFields := "MAKEUP_BOX"       :@VM:SQL_Format(Rec(WM_OUT_MAKEUP_BOX$),        "BIT"):@FM
DataFields := "ADE_READ"         :@VM:SQL_Format(Rec(WM_OUT_ADE_READ$),          "STR"):@FM
DataFields := "PROMISE_SHIP_DT"  :@VM:SQL_Format(Rec(WM_OUT_PROMISE_SHIP_DT$),   "DATE"):@FM
DataFields := "IN_CLEANROOM"     :@VM:SQL_Format(Rec(WM_OUT_IN_CLEANROOM$),      "BIT"):@FM
DataFields := "VOID"             :@VM:SQL_Format(Rec(WM_OUT_VOID$),              "BIT"):@FM
DataFields := "IN_PTO"           :@VM:SQL_Format(Rec(WM_OUT_IN_PTO$),            "BIT"):@FM
DataFields := "CI_NO"            :@VM:SQL_Format(Rec(WM_OUT_CI_NO$),             "INT")

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

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

// WM_OUT_THICK_MIN_ALL
RdsLsId        = {RDS_LS_ID}
ThickMinAll    = {THICK_MIN_ALL}
ThickTargetAll = {THICK_TARGET_ALL}
ThickMaxAll    = {THICK_MAX_ALL}
ThickUnitsAll  = {THICK_UNITS_ALL}
If Ans EQ "" AND (RdsLsId NE "" OR ThickMinAll NE "" OR ThickTargetAll NE "" OR ThickMaxAll NE "" OR ThickUnitsAll NE "") then
    
    // List of data fields and their values
    MvFields  = "RDS_LS_ID"       :@FM:SQL_Format(RdsLsId,        "STR"):@RM
    MvFields := "THICK_MIN_ALL"   :@FM:SQL_Format(ThickMinAll,    "DEC", 2):@RM
    MvFields := "THICK_TARGET_ALL":@FM:SQL_Format(ThickTargetAll, "DEC", 2):@RM
    MvFields := "THICK_MAX_ALL"   :@FM:SQL_Format(ThickMaxAll,    "DEC", 2):@RM
    MvFields := "THICK_UNITS_ALL" :@FM:SQL_Format(ThickUnitsAll,  "DEC", 2)
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_THICK_MIN_ALL", Keys, MvFields);
    
end

// WM_OUT_MET_TEST
MetTest     = {MET_TEST}
MetTestDesc = {MET_TEST_DESC}
MetSlot     = {MET_SLOT}
MetSlotDesc = {MET_SLOT_DESC}
MetMin      = {MET_MIN}
MetMax      = {MET_MAX}
MetResult   = {MET_RESULT}
MetSig      = {MET_SIG}
MetSigDtm   = {MET_SIG_DTM}
If Ans EQ "" AND (MetTest NE "" OR MetTestDesc NE "" OR MetSlot NE "" OR MetSlotDesc NE "" OR MetMin NE "" OR MetMax NE "" OR MetResult NE "" OR MetSig NE "" OR MetSigDtm NE "") then
    
    // List of data fields and their values
    MvFields  = "MET_TEST"     :@FM:SQL_Format(MetTest,     "STR"):@RM
    MvFields := "MET_TEST_DESC":@FM:SQL_Format(MetTestDesc, "STR"):@RM
    MvFields := "MET_SLOT"     :@FM:SQL_Format(MetSlot,     "STR"):@RM
    MvFields := "MET_SLOT_DESC":@FM:SQL_Format(MetSlotDesc, "STR"):@RM
    MvFields := "MET_MIN"      :@FM:SQL_Format(MetMin,      "STR"):@RM
    MvFields := "MET_MAX"      :@FM:SQL_Format(MetMax,      "STR"):@RM
    MvFields := "MET_RESULT"   :@FM:SQL_Format(MetResult,   "STR"):@RM
    MvFields := "MET_SIG"      :@FM:SQL_Format(MetSig,      "STR"):@RM
    MvFields := "MET_SIG_DTM"  :@FM:SQL_Format(MetSigDtm,   "DATETIME")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_MET_TEST", Keys, MvFields);
    
end

// WM_OUT_SLOT
If Ans EQ "" AND Rec(WM_OUT_SLOT_NO$) NE "" then
    
    // List of data fields and their values
    MvFields  = "SLOT_NO"        :@FM:SQL_Format(Rec(WM_OUT_SLOT_NO$),     "INT"):@RM
    MvFields := "RDS"            :@FM:SQL_Format(Rec(WM_OUT_RDS$),         "STR"):@RM
    MvFields := "RDS_REACT_NO"   :@FM:SQL_Format({RDS_REACT_NO},           "STR"):@RM
    MvFields := "RDS_CURR_STATUS":@FM:SQL_Format({RDS_CURR_STATUS},        "STR"):@RM
    MvFields := "POCKET"         :@FM:SQL_Format(Rec(WM_OUT_POCKET$),      "STR"):@RM
    MvFields := "ZONE"           :@FM:SQL_Format(Rec(WM_OUT_ZONE$),        "STR"):@RM
    MvFields := "IN_CASS_NO"     :@FM:SQL_Format(Rec(WM_OUT_IN_CASS_NO$),  "STR"):@RM
    MvFields := "IN_SLOT_NO"     :@FM:SQL_Format(Rec(WM_OUT_IN_SLOT_NO$),  "INT"):@RM
    MvFields := "SLOT_NCR"       :@FM:SQL_Format(Rec(WM_OUT_SLOT_NCR$),    "INT"):@RM
    MvFields := "MU_WO_NO"       :@FM:SQL_Format(Rec(WM_OUT_MU_WO_NO$),    "STR"):@RM
    MvFields := "MU_WO_STEP"     :@FM:SQL_Format(Rec(WM_OUT_MU_WO_STEP$),  "INT"):@RM
    MvFields := "MU_CASS_NO"     :@FM:SQL_Format(Rec(WM_OUT_MU_CASS_NO$),  "INT"):@RM
    MvFields := "MU_SLOT_NO"     :@FM:SQL_Format(Rec(WM_OUT_MU_SLOT_NO$),  "INT"):@RM
    MvFields := "UMW_CASS_ID"    :@FM:SQL_Format(Rec(WM_OUT_UMW_CASS_ID$), "STR"):@RM
    MvFields := "UMW_SLOT_NO"    :@FM:SQL_Format(Rec(WM_OUT_UMW_SLOT_NO$), "INT"):@RM
    MvFields := "MU_BY"          :@FM:SQL_Format(Rec(WM_OUT_MU_BY$),       "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_SLOT", Keys, MvFields);
    
end

// WM_OUT_NCR_KEYS
NcrNos         = {NCR_NOS}
NcrStatus      = {NCR_STATUS}
NcrRejCnt      = {NCR_REJ_CNT}
NcrLossBy      = {NCR_LOSS_BY}
NcrLossStage   = {NCR_LOSS_STAGE}
NcrLossDesc    = {NCR_LOSS_DESC}
NcrLossComment = {NCR_LOSS_COMMENT}
If Ans EQ "" AND (NcrNos NE "" OR NcrStatus NE "" OR NcrRejCnt NE "" OR NcrLossBy NE "" OR NcrLossStage NE "" OR NcrLossDesc NE "" OR NcrLossComment NE "") then
    
    // List of data fields and their values
    MvFields  = "NCR_NOS"         :@FM:SQL_Format(NcrNos,         "STR"):@RM
    MvFields := "NCR_STATUS"      :@FM:SQL_Format(NcrStatus,      "STR"):@RM
    MvFields := "NCR_REJ_CNT"     :@FM:SQL_Format(NcrRejCnt,      "INT"):@RM
    MvFields := "NCR_LOSS_BY"     :@FM:SQL_Format(NcrLossBy,      "STR"):@RM
    MvFields := "NCR_LOSS_STAGE"  :@FM:SQL_Format(NcrLossStage,   "STR"):@RM
    MvFields := "NCR_LOSS_DESC"   :@FM:SQL_Format(NcrLossDesc,    "STR"):@RM
    MvFields := "NCR_LOSS_COMMENT":@FM:SQL_Format(NcrLossComment, "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_NCR_KEYS", Keys, MvFields);
    
end

// WM_OUT_INV_WH
InvDtm      = {INV_DTM}
InvWH       = {INV_WH}
InvWHDesc   = {INV_WH_DESC}
InvLocation = {INV_LOCATION}
InvLocDesc  = {INV_LOC_DESC}
InvAction   = {INV_ACTION}
InvUser     = {INV_USER}
InvTag      = {INV_TAG}
If Ans EQ "" AND (InvDtm NE "" OR InvWH NE "" OR InvWHDesc NE "" OR InvLocation NE "" OR InvLocDesc NE "" OR InvAction NE "" OR InvUser NE "" OR InvTag NE "") then
    
    // List of data fields and their values
    MvFields  = "INV_DTM"     :@FM:SQL_Format(InvDtm,      "DATETIME"):@RM
    MvFields := "INV_WH"      :@FM:SQL_Format(InvWH,       "STR"):@RM
    MvFields := "INV_WH_DESC" :@FM:SQL_Format(InvWHDesc,   "STR"):@RM
    MvFields := "INV_LOCATION":@FM:SQL_Format(InvLocation, "STR"):@RM
    MvFields := "INV_LOC_DESC":@FM:SQL_Format(InvLocDesc,  "STR"):@RM
    MvFields := "INV_ACTION"  :@FM:SQL_Format(InvAction,   "STR"):@RM
    MvFields := "INV_USER"    :@FM:SQL_Format(InvUser,     "STR"):@RM
    MvFields := "INV_TAG"     :@FM:SQL_Format(InvTag,      "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_INV_WH", Keys, MvFields);
    
end

// WM_OUT_HOLD_HISTORY
HoldStartDtm    = {HOLD_START_DTM}
HoldStartUser   = {HOLD_START_USER}
HoldStartReason = {HOLD_START_REASON}
HoldStopDtm     = {HOLD_STOP_DTM}
HoldStopUser    = {HOLD_STOP_USER}
HoldStopReason  = {HOLD_STOP_REASON}
If Ans EQ "" AND (HoldStartDtm NE "" OR HoldStartUser NE "" OR HoldStartReason NE "" OR HoldStopDtm NE "" OR HoldStopUser NE "" OR HoldStopReason NE "") then
    
    // List of data fields and their values
    MvFields  = "HOLD_START_DTM"   :@FM:SQL_Format(HoldStartDtm,    "DATETIME"):@RM
    MvFields := "HOLD_START_USER"  :@FM:SQL_Format(HoldStartUser,   "STR"):@RM
    MvFields := "HOLD_START_REASON":@FM:SQL_Format(HoldStartReason, "STR"):@RM
    MvFields := "HOLD_STOP_DTM"    :@FM:SQL_Format(HoldStopDtm,     "DATETIME"):@RM
    MvFields := "HOLD_STOP_USER"   :@FM:SQL_Format(HoldStopUser,    "STR"):@RM
    MvFields := "HOLD_STOP_REASON" :@FM:SQL_Format(HoldStopReason,  "STR")
    
    // Write the data to the SQL database
    Ans = SQL_Write_MV(Connection, "WM_OUT_HOLD_HISTORY", Keys, MvFields);
    
end

// WM_OUT Comments
If Ans EQ "" AND Rec(64) NE "" then
    MvFields  = "EPP_COMMENT_DATE":@FM:SQL_Format(Rec(64), "DATETIME"):@RM
    MvFields := "EPP_COMMENT_USER":@FM:SQL_Format(Rec(65), "STR"):@RM
    MvFields := "EPP_COMMENT_NOTE":@FM:SQL_Format(Rec(66), "STR")
    Ans       = SQL_Write_MV(Connection, "WM_OUT_COMMENT", Keys, MvFields);
end

Return Ans


