Syntax of RENAME

I try to rename a record, but it doesn’t work. The primary key consist of two fields. Both fields are sent with the RENAME-command, but there is only one record renamed. The Online-help is not very helpful, so wasn’t going wrong ? I’ve coded: ICPG.RENAME(“IC Carrier”.Beschreibung, ICPG.Gasse); You see, just the first field of the primary key will change, the second stays as it is. Is there a fault in the code line ? If yes, how should this line look like ?! Stefan Weinreich Billing Analyst

quote:


Both fields are sent with the RENAME-command, but there is only one record renamed.


You can only RENAME one record, there’s nothing like MODIFYALL (RENAMEALL ?) !

quote:


Use this function to change a primary key in a C/SIDE table. [Ok]:= Record.RENAME(Value1, [Value2],…) Ok Data type: boolean This tells you whether the system was able to rename the primary key or not. Typically, the system will return FALSE if the record does not exist or if you do not have permission to write to the table. Record Data type: record The record that contains the primary key that you want to change. Value1, Value2, … Data type: text The new values for the primary key. Comments For example, if you use the customers phone number as the customer number, you can use this function to change the customer number if the phone number changes.


e.g. if your record has the two primary-key fields with value A and B, then [code]Record.RENAME(C,B)[code] would set the primary-key values of that record to C and B (if this record doesn’t allready exist). If you want to rename more then one record, you need to do that within a loop. Regards, Jörg Joerg A. Stryk Apollo-Optik, IT/ERP

Hey Joerg, i didn’t show the complete code, but the line i sent was within a loop. I wondered because the only record which was renamed was the last one. But the loop runs definitively through the complete table (i’ve checked it out). Hence i thought i did something wrong in this code line. But if i understand the online-help and your posting correct the codeline is okay. Hence the fault must be somewhere else. I guess i have to check it once again… Maybe i “can’t see the forest because of all the trees”… :wink: Stefan Weinreich Billing Analyst

okay, i’ve found my fault. as i changed the primary key in one record of the table the system finished the loop. Hence only the last record was renamed. Using a second recordvariable for the same table (ICPG2 for table ICPG) and renaming the record of ICPG2 instead of ICPG did solve the problem. Stefan Weinreich Billing Analyst

You must copy initial (filtered) records into some buffer and after it you can make loop: TempBuf.DELETEALL; Table.SETRANGE(Field,MinValue,MaxValue); IF Table.FIND(’-’) THEN REPEAT TempBuf.INIT; TempBuf.PrimaryKeyField1 := Table.PrimaryKeyField1; TempBuf.PrimaryKeyField2 := Table.PrimaryKeyField2; TempBuf.INSERT; UNTIL Table.NEXT = 0 ; Table.RESET; TempBuf.FIND(’-’); REPEAT Table.GET(TempBuf.PrimaryKeyField1,TempBuf.PrimaryKeyField3); Table.RENAME(PriKeyNewValue1,PriKeyNewValue2); //Table.MODIFY; //??? UNTIL TempBuf.NEXT = 0; TempBuf.DELETEALL; Business Applications Programmer Sertified Navision Developer SIA “Sintegra” Latvia

interesting idea using temporary tables for this problem, Alexei. Your idea should be added to a navision-section “How to’s - suggestions and examples” ! Stefan Weinreich Billing Analyst

The behavior Stefan experienced can occur whenever you change any field within the current key while in a loop. I used to think it failed consistently and in a predictable fashion. However I just found a piece of my code that did just that kind of key member field change (shame on me), but worked fine for four years until I added another field to the key in question. Then it began failing. I solved the problem exactly the way Alexei recommended. I agree that this would be a good submission for a “Tips and Tricks” forum. Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

its good to see that i’m not the only one who faught with this problem… :slight_smile: But - is this behavior always the same, independent from the key i use ? Or does this only occur when i use the primary key ? btw: a “tips and tricks” section would be a great idea. What has to be done to establish such a forum here ? Stefan Weinreich Billing Analyst

A “tips and tricks” section? It IS there: - http://www.navision.net/forum/forum.asp?FORUM_ID=26&CAT_ID=3&Forum_Title=Attain%2FFinancials+-+Tips+%26+Tricks

Stefan, The problem arises whenever you change a field in the current key within a processing loop. It doesn’t matter if the current key is the primary key or not. Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

One small note. I would recommend avoid using algorythm with copying to temporary record as time-consuming. AFAIK, it is enough to use two record variables (not temporary!) of the same type (as Stefan has already mentioned). To paraphrase the code above: TableBuf.SETRANGE(Field,MinValue,MaxValue); IF TableBuf.FIND(’-’) THEN REPEAT Table.GET(TempBuf.PrimaryKeyField1,TempBuf.PrimaryKeyField3); Table.RENAME(PriKeyNewValue1,PriKeyNewValue2); UNTIL TempBuf.NEXT = 0; I believe, this would be enough. Best regards,

Presuming the volume of data to be modified is not too large, I would think copying the data to a temporary table would be very fast as it will be totally cached (no disk I/O). Dave Studebaker das@libertyforever.com Liberty Grove Software A Navision Services Partner

quote:


Originally posted by Petro: One small note. I would recommend avoid using algorythm with copying to temporary record as time-consuming. AFAIK, it is enough to use two record variables (not temporary!) of the same type (as Stefan has already mentioned). To paraphrase the code above: TableBuf.SETRANGE(Field,MinValue,MaxValue); IF TableBuf.FIND(’-’) THEN REPEAT Table.GET(TempBuf.PrimaryKeyField1,TempBuf.PrimaryKeyField3); Table.RENAME(PriKeyNewValue1,PriKeyNewValue2); UNTIL TempBuf.NEXT = 0; I believe, this would be enough. Best regards,


I agree with David (don’t I always) about the speed issue however, the above code will work as well. Having said that, you do not need to “GET” the record, a simple assignment would work: TableBuf.SETRANGE(Field,MinValue,MaxValue); IF TableBuf.FIND(’-’) THEN REPEAT Table := TableBuf; Table.RENAME(PriKeyNewValue1,PriKeyNewValue2); UNTIL TempBuf.NEXT = 0; Bill Benefiel Manager of Information Systems Overhead Door Company billb@ohdindy.com (317) 842-7444 ext 117

TableBuf.SETRANGE(Field,MinValue,MaxValue); >>IF TableBuf.FIND(’-’) THEN >>REPEAT >>Table := TableBuf; >>Table.RENAME(PriKeyNewValue1,PriKeyNewValue2); >>UNTIL TempBuf.NEXT = 0; PEOPLE!!! In my example buffer contains only primary key values, not all table. And it works very fast. In navision’s documentation i cannot find nothing about database “cursor”. I do not know how Navision works if fields (included in loop criteria) are changed within loop. Business Applications Programmer Sertified Navision Developer SIA “Sintegra” Latvia