RENAMEing a bunch of records (solved!!!)

Start of editing <<<<<<<<<<<<<<<<<<<<< Thanks to all who replied! After posting this question, I did a search in the archive (yeah, should have done that before posting, shame on me…[:I]), and found out that this topic had come up before and was solved by using a second record variable, which is then renamed. I’m not going to delete my posting because someone else might have the same problem, but the problem can be considered solved. Thanks again to all of you! >>>>>>>>>>>>>>>>>>>>>>>> End of editing <<<<<<<<<<<<<<<<<<<<< Folks, I’m out of my wits on this one. Maybe someone can help me out. I have a table with primary key e.g. F1, F2, F3. All records where F2=‘X’ must be renamed to F2=‘Y’. My first attempt using MODIFYALL failed miserably, giving the error message that F2 was part of the primary key. A RENAME had to be used. So I tried RecVar.SETRANGE(F2, ‘X’); IF RecVar.FIND(’-’) THEN REPEAT RecVAR.RENAME(RecVar.F1, ‘Y’, RecVar.F3); UNTIL RecVar.NEXT = 0; Which worked, but renamed only the first record of many. The second run of this code piece renamed only the next (= then first) record and so on. I assumed the reason might be that filtering on a primary key field and then changing the content of this field in a loop might be confusing at least. So I switched to MARKing the records first, then removing the filter and looping over the marked records. Same problem. I don’t want to loop over the loop, setting filters again and again. There’s got to be a more elegant solution. Any ideas? Thanks,

Hi Heinz I would use a dataport to export the whole table, rename the value with an editor and then import the data with the same dataport. I go this way quite often. bye Andre

Hi Andre, Thanks for the tip - I thought of this myself, but it seems like too much work [;)] Anyways, I did a search after I posted my question, and this topic has been dealt with before [:p]. The trick is to use a second record variable inside the loop, upon which the RENAME is executed.

Hi you need new record variable and code like this: RecVar.SETRANGE(F2, ‘X’); IF RecVar.FIND(’-’) THEN REPEAT NewRecVAR := RecVAR; NewRecVAR.RENAME(RecVar.F1, ‘Y’, RecVar.F3); UNTIL RecVar.NEXT = 0;

Well… i used to create a temporary variable and do something like this: CLEAR (TempRec); TempRec.RESET; TempRec.DELETEALL; RecVar.SETRANGE(F2,‘x’); IF (RecVar.FIND(’-’)) THEN REPEAT TempRec.INIT; TempRec.TRANSFERFIELDS(RecVar); TempRec.INSERT; UNTIL (RecVar.NEXT = 0); RecVar.RESET; IF (TempRec.FIND(’-’)) THEN REPEAT RecVar.GET(TempRec.F1,TempRec.F2,TempRec.F3); RecVar.RENAME(TempRec.F1,‘Y’,TempRec.F3); TempRec.DELETE; UNTIL (NOT TempRec.FIND(’-’));

Hi Heinz Thread: RENAMEing a bunch of records (solved!!!) <= COOL! We should issue a law: §1: All solved problems should (must) be marked as solved! bye Andre

Well… usually that’s what the moderator it’s supposed to do in a similar way: closing the topic. Regards,

Yes, but the moderator has to “guess” if no more posts are to be expected and a topic may be closed (except maybe in obvious cases). The original poster of a problem should know definitely when a satisfying answer is available [;)]