Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
The most elegant and readable way (and efficient)
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01076714
Message ID:
01076922
Views:
20
Here is what I wrote yesterday but haven't time to test. Now I'm going to work on this form. As you see, it's the same as Sergey proposed and the easiest solution here:
LOCAL lcOldPK, lcNewPk, lnI

LOCAL ARRAY laOldRecord[1], laNewRecord[1]

lcOldPk = ALLTRIM(this.Parent.cboCarriers.value) 
lcNewPk = ALLTRIM(this.Parent.cboCarrierToMerge.Value) 

LOCATE FOR cCarriers_pk = m.lcOldPk
SCATTER FIELDS EXCEPT CCARRIERS_PK, CCARRIER_NAME, IACTIVE_FLAG, TENTERED_DATE, CENTERED_USER, TLAST_UPDATED_DATE, ;
					  CLAST_UPDATED_USER, CUSER_DEF1, CUSER_DEF2, CUSER_DEF3, CUSER_DEF4 TO laOldRecord

replace iActive_flag WITH 0

LOCATE FOR cCarriers_pk = m.lcNewPk
SCATTER FIELDS EXCEPT CCARRIERS_PK, CCARRIER_NAME, IACTIVE_FLAG, TENTERED_DATE, CENTERED_USER, TLAST_UPDATED_DATE, CLAST_UPDATED_USER, CUSER_DEF1, CUSER_DEF2, CUSER_DEF3, CUSER_DEF4 TO laNewRecord

for lnI =1 to ALEN(laOldRecord)
    IF NOT EMPTY(laOldRecord[m.lnI]) AND EMPTY(laNewRecord[m.lnI])
       laNewRecord[m.lni] = laOldRecord[m.lnI]
    endif   
NEXT

GATHER FROM laNewRecord FIELDS EXCEPT  ;
					CCARRIERS_PK, CCARRIER_NAME, IACTIVE_FLAG, TENTERED_DATE, CENTERED_USER, TLAST_UPDATED_DATE, ;
					CLAST_UPDATED_USER, CUSER_DEF1, CUSER_DEF2, CUSER_DEF3, CUSER_DEF4



>>>>>Do you want also French fries with it? < gd&r >.
>>>>
>>>>I knew it <g> I was hoping to take a little break, serve the table and come back and have already written solution <g> Now I had to hurry up to finish it before Shabbath <g>
>>>
>>>How you decide which records you have to merge?
>>>I mean, did they have some uniqueness?
>>
>>Yes, they both have PK. I'm merging two insurance carriers. There are lots of cases there the same carrier was entered several times with slight difference in spelling. In my form I have two comboboxes. One to select carrier which is going to be merged and another the one, that is going to be come a new merged record.
>>
>>Here is what I'm writing now in the presavehook of my biz object (thinking at the same time)
>>
>>
>>LOCAL lcOldPK, lcNewPk
>>
>>lcOldPk = ALLTRIM(this.Parent.cboCarriers.value)
>>lcNewPk = ALLTRIM(this.Parent.cboCarrierToMerge.Value)
>>
>>LOCATE FOR cCarriers_pk = m.lcOldPk
>>SCATTER FIELDS EXCEPT CCARRIERS_PK, CCARRIER_NAME, IACTIVE_FLAG, TENTERED_DATE, CENTERED_USER, TLAST_UPDATED_DATE, CLAST_UPDATED_USER, CUSER_DEF1, CUSER_DEF2, CUSER_DEF3, CUSER_DEF4 memvar
>>
>>replace iActive_flag WITH 0
>>
>>Now I need to find a way to compare. May be memvar is not a good idea and better to use array instead. I then would construct a replace command as a string and then &lcReplace. I have ~10 minutes left...
>
>eak,
>I couldn think better solution that Sergey :o) (Suprise :o))))
>First I think about SELECT SUM(Field1) but then it comes to my mind that you dind't mension that field must be empty in one record and full in other.
>So this could be:
>
>LOCAL lcOldPK, lcNewPk, loOldRecord, loNewRecord, lnFor, lcField, leFieldValue
>
>lcOldPk = ALLTRIM(this.Parent.cboCarriers.value)
>lcNewPk = ALLTRIM(this.Parent.cboCarrierToMerge.Value)
>
>LOCATE FOR cCarriers_pk = m.lcOldPk
>SCATTER FIELDS EXCEPT CCARRIERS_PK, CCARRIER_NAME, IACTIVE_FLAG, TENTERED_DATE, CENTERED_USER, TLAST_UPDATED_DATE,;
>                      CLAST_UPDATED_USER, CUSER_DEF1, CUSER_DEF2, CUSER_DEF3, CUSER_DEF4;
>NAME loOldRecord
>LOCATE FOR cCarriers_pk = m.lcNewPk
>FOR lnFor = 1 TO FCOUNT()
>    lcField      = FIELD(lnFor)
>    leFieldValue = EVALUATE(lcField)
>    IF PEMSTATUS(loOldRecord,lcField,5)
>       IF NOT EMPTY(leFieldValue) && or IF EMPTY() - I can't remember logic :o)
>          lcField  = [loOldRecord.]+lcField
>          &lcField = leFieldValue
>       ENDIF
>    ENDIF
>NEXT
>GATHER NAME loOldRecord
>
>Somethig like that (not tested)
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform