Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Wondering about best technique
Message
 
To
28/05/2001 12:08:52
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00511635
Message ID:
00512162
Views:
15
Jer,

>>I need be able to get all theh operations in comma delimited form, but he harder part is if there is a chanage to the data in the comma delimited cursor, it need to go back and update the information in origonal table for ( in this case ) those 3 operations ( there will be many other fields in the comma delimited cursor )

No problem.

Three steps:
1) Make a cursor of individual operation codes (Op_Code) for each part by parsing out the op_codes.
2) Find out which op_codes were removed by querying the Op_Codes cursor against the Part_Dim table.
Use the result set as the basis for deleteing records from Part_Dim.
3) Find out which op_codes were added by querying the Op_Codes cursor agains the Part_Dim table.
Append the result set from this query to the Part_Dim table.

HTH

Thom C.
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform