RENAME BY USING INSERT/DELETE

Hi All,

I'm using the following codes to change one of Comment Line Key but I realized some records are deleted (insert was failed) :(.
my intention is that I want to rename number comment line by using insert-delete method. Is there any better way?


CommentLine.RESET;
CommentLine.SETRANGE("No.",'XXX');
IF CommentLine.FINDSET THEN BEGIN
REPEAT
CommentLine2.INIT;
CommentLine2.TRANSFERFIELDS(CommentLine);
CommentLine2."No." := 'ZZZ';
CommentLine2.INSERT;

CommentLine.DELETE;
UNTIL CommentLine.NEXT = 0;
END;

Answers

  • TallyHoTallyHo Member Posts: 417
    edited 2019-04-19
    If no. is part of primary key
    Commentline.RENAME(newvalkeyfield1,newvalkeyfield2)

    (Findset(true, true))
  • AngeloAngelo Member Posts: 180
    Hi TallyHo,

    Use RENAME is slower and hit error 'Not allowed to rename' for some tables. Is there better way to use INSERT-DELETE method?
  • TallyHoTallyHo Member Posts: 417
    edited 2019-04-19
    You can try to use a temp table.
    Insert your New records from temp table. Repeat the procedure Per 100 records if you have lots of data in the table. Deleteall and Commit per 100 records if possible. Or do IT per item/customer or whatever you can use as point of return. Fill tour temp table again wil the next bulk of records. Empty tour temp table each time.
  • AngeloAngelo Member Posts: 180
    Is this what you mean?


    CommentLine.RESET;
    CommentLine.SETRANGE("No.",'XXX');
    IF CommentLine.FINDSET THEN BEGIN
    REPEAT
    TempCommentLine.DELETEALL;
    TempCommentLine.INIT;
    TempCommentLine.TRANSFERFIELDS(CommentLine);
    TempCommentLine."No." := 'ZZZ';
    TempCommentLine.INSERT;

    IF TempCommentLine.FINDFIRST THEN BEGIN
    CommentLine2.INIT;
    CommentLine2 := TempCommentLine;
    CommentLine2.INSERT;

    CommentLine.DELETE;
    END

    UNTIL CommentLine.NEXT = 0;
    END;
  • TallyHoTallyHo Member Posts: 417
    CommentLine.RESET;
    CommentLine.SETRANGE("No.",'XXX');
    IF CommentLine.FINDSET THEN BEGIN
    REPEAT
    TempCommentLine.INIT;
    TempCommentLine.TRANSFERFIELDS(CommentLine);
    TempCommentLine."No." := 'ZZZ';
    TempCommentLine.INSERT
    UNTIL CommentLine.next <= 0;

    Commentline.deleteall;

    TempCommentLine.findset;
    Repeat
    CommentLine.TRANSFERFIELDS(tempCommentLine);
    CommentLine.insert;
    UNTIL TempCommentLine.next <= 0;

    Faster or not at all. Just give it a try.
Sign In or Register to comment.