Options

Speed up read/write in buffer

GonzaloGonzalo Member Posts: 19
Hi there,
I've developed a process which has to read/write millions of records and unluckily takes centuries. (Its well known that NAV work with cursos and some cases is not really effective)

This is my code: (it's a easy loop)
IF Header.FINDFIRST THEN
REPEAT
BufferHeader.TRANSFERFIELDS(Cta);
BufferHeader.INSERT;

Lines.SETRANGE("Header No.",Header."No.");
IF Lines.FINDFIRST THEN
REPEAT
BufferLine.TRANSFERFIELDS(Lines);
BufferLine.INSERT;
UNTIL Lines.NEXT = 0;
UNTIL Header.NEXT = 0;

IF PostedHeader.FINDSET THEN
REPEAT
BufferHeader.TRANSFERFIELDS(PostedHeader);
BufferHeader.INSERT;

PostedLine.SETRANGE("Header No.",PostedHeader."No.");
IF PostedLine.FINDFIRST THEN
REPEAT
BufferLine.TRANSFERFIELDS(PostedLine);
BufferLine.INSERT;
UNTIL PostedLine.NEXT = 0;
UNTIL PostedHeader.NEXT = 0;

As you can see I'm inserting the records in a buffer. Do you know if its possible to speed this up? Maybe storing in the buffer table directly from sql, do you recommend me that??
Thanks

Answers

  • Options
    RockWithNAVRockWithNAV Member Posts: 1,139
    Hey Gonzalo,

    First of all I will do some tiny changes in your code.

    1. Use Findset instead of Findfirst.
    2. Why are you not initializing before Transferfields??

    Now if you just need to transfer records from 1 table to another and if it has many records then obviously it will takes time as there is one to one transmission.

    I will suggest to write SQL Stored procedure in that case and call it from NAV. It will do it in chunk of seconds.
  • Options
    GonzaloGonzalo Member Posts: 19
    Thanks for your help, I'll try to write SQL stored procedure.
Sign In or Register to comment.