>>PROCEDURE _Insert( tcTable, tcTag, tu1, tu2, tu3, tu4, tu5 ) >> >>********************************* >>***** searches tcTag (candidate tag) for values corresponing to tu? values >>***** positions pointer on record if found >>***** inserts record if not found >>***** >>***** tu1, tu2 etc. must be in order as they appear in tcTag >>***** Example: >>***** select Invoice >>***** Index on BINTOC(PK) + DTOS(date) Tag Invoice_order >>***** if _Insert( 'Invoice, 'Invoice_Order', <PK>, date() ) >>***** && record pointer on existing or new record >>***** else >>***** && error >>***** endif >>********************************* >> >>IF EMPTY(tcTable) >> tcTable = ALIAS() >>ENDIF >> >>IF EMPTY(tcTag) >> tcTag = DBGETPROP(tcTable,"TABLE","PRIMARYKEY") >>ENDIF >> >>LOCAL ln, lc, lu, lcType, laFields(1), lcKey, lnCnt, lnField, lcMemVar, lcSeek >> >>***** Build string to INDEXSEEK() >>lcSeek = '' >>FOR ln = 1 TO PCOUNT() - 2 >> lu = EVALUATE('tu'+TRANSFORM(ln)) >> lcType = VARTYPE(lu) >> DO CASE >> CASE lcType = 'N' >> lc = BINTOC(lu) >> CASE lcType = 'C' >> lc = lu >> CASE lcType = 'D' >> lc = DTOS(lu) >> CASE lcType = 'T' >> lc = TTOC(lu) >> ENDCASE >> lcSeek = lcSeek + lc >>ENDFOR >> >>***** determine if String currently in table >>IF !INDEXSEEK(lcSeek,.T.,tcTable,tcTag) >> ***** determine order of fields in Key() >> = AFIELDS(laFields,tcTable) >> lcKey = KEY(TAGNO(tcTag,tcTable,tcTable),tcTable) >> FOR ln = 1 TO ALEN(laFields,1) >> laFields(ln,2) = AT(laFields(ln,1),lcKey) >> ENDFOR >> = ASORT(laFields,2) >> >> ***** assign value to fields in Key() >> lnCnt = 0 >> FOR lnField = 1 TO ALEN(laFields,1) >> lcMemVar = laFields(lnField,1) >> PRIVATE (lcMemVar) && make sure no values leak thru from calling prog() >> IF !EMPTY( laFields(lnField,2) ) >> ** only assign values to fields in tcTag >> lnCnt = lnCnt + 1 >> STORE EVALUATE('tu'+TRANSFORM(lnCnt)) TO (lcMemVar) >> ENDIF >> ENDFOR >> INSERT INTO (tcTable) FROM MEMVAR >>ENDIF >>>