CREATE CURSOR Op_Codes ; (Part_ID I, ; Op_Code I) *** scan through the display cursor SELECT Op_Disp SCAN *** the part id stays the same m.lnPartId = Op_Disp.Part_Id *** get the set of operation codes m.lcCodeSet = ALLTRIM(Op_Disp.Op_Codes) *** find out how many codes there are m.lnCodeCount = OCCURS(",", m.lcCodeSet) *** loop through all the codes, except the last one FOR m.i = 1 TO m.lnCodeCount *** process the first code in the list m.lcCode = LEFT(m.lcCodeSet, AT(",", m.lcCodeSet) -1) *** strip off the comma m.lcCode = CHRTRAN(m.lcCode, ",", "") *** translate the code into an integer m.lnCode = VAL(m.lcCode) *** NOTE: this command is the same as the preceeding three... i broke them out for clarity *** this will be faster * m.lnCode = VAL(CHRTRAN(LEFT(m.lcCodeSet, AT(",", m.lcCodeSet) -1), ",", "") *** add the part_id and operation code to the op_codes cursor INSERT INTO Op_Codes ; VALUES ; (m.lnPartId, ; m.lnCode) *** strip off the first code m.lcCodeSet = SUBSTR(m.lcCodeSet, AT(",", m.lcCodeSet) + 1) NEXT IF VAL(m.lcCodeSet) > 0 *** don't process blanks INSERT INTO Op_Codes ; VALUES ; (m.lnPartId, ; VAL(m.lcCodeSet)) ENDIF ENDSCAN *** SQL query to find out which op codes were removed SELECT PD.Part_Id, PD.Op_Id ; FROM Part_Dim PD ; WHERE NOT EXISTS ; (SELECT * ; FROM Op_Codes OC ; WHERE OC.Part_Id = PD.Part_ID ; AND OC.Op_Code = PD.Op_ID) ; INTO CURSOR Del_OpCodes IF _TALLY > 0 *** remove the deleted codes from Part_Dim INDEX ON STR(Part_Id) + STR(Op_Id) TAG Del_Key SELECT Part_Dim *** NOTE: INDEXSEEK does not need to reposition the record pointer in the Del_OpCodes cursor... *** We just need to know if the part_id/Op_Id exist in Del_OpCodes DELETE FOR ; INDEXSEEK(STR(Part_Id) + STR(Op_Id), .F., "Del_OpCodes", "Del_Key") PACK ENDIF USE IN Del_OpCodes *** SQL query to find out which op codes were added SELECT OC.Part_Id, OC.Op_Id ; FROM Op_Codes OC ; WHERE NOT EXISTS ; (SELECT * ; FROM Part_Dim PD ; WHERE OC.Part_Id = PD.Part_ID ; AND OC.Op_Code = PD.Op_ID) ; INTO CURSOR Add2PartDim IF _TALLY > 0 SELECT Part_Dim APPEND FROM DBF("Add2PartDim") ENDIF USE IN Add2PartDim USE IN Op_Codes