Variable with type record

mthe80mthe80 Member Posts: 27
Dear all,

I am sorry for not trying to look first about what will I ask to you guys.
Cause I rather run out of time.

I am rather confuse about this variable type.
Does this kind of variable has the same function as DATASET in VB.Net or C#? If I not mistaken, the dataset is think like a cache in our computer so when I do some changes, the changes only in my computer not to the database unless, I make it to insert to the database.

If I use that as a record of a table, does it will took all of the record?
When this kind of variable will take the record? Does it will take the record after I say Record.Setrange?

If I declare this kind of record without define it as a temporary, does the changes I made will also changes the record in the real table?
:-k
TIA

Michael Darmawan Teja

Comments

  • DenSterDenSter Member Posts: 8,307
    I you don't make it temporary then changes are written into the table as soon as you use a command to write the values, like MODIFY, INSERT, DELETE or RENAME. If you don't use any of these commands, then no change will every be written to the database.

    You can make a record variable temporary, but then it has no link to the database. So if you have a customer with number 123, and you do Customer.GET('123') with a temporary customer record variable, you will get an error message, even though the customer exists in the database.
  • krikikriki Member, Moderator Posts: 9,118
    mthe80 wrote:
    Dear all,

    I am sorry for not trying to look first about what will I ask to you guys.
    Cause I rather run out of time.
    Well in general it is faster to search for it in the weekends. You're lucky someone is online.

    A record is a 'storage' for 1 DB-record. When you get (FIND or GET) a record, it is stored in that variable. If you change it, it isn't changed in the DB until you do a MODIFY. If you have to change just 1 field in a record, you still have to get the record (GET,FIND), change the field (TheRecord."Field" := Value ; TheRecord.VALIDATE("Field",Value) ; and write record back (MODIFY). Until you do a MODIFY, the DB will not contain your new value.

    SETRANGE,SETFILTER,SETCURRENTKEY does nothing to the values in the record. Only until you do FIND (or NEXT), the first (or a next) record will be put in the variable.

    Temporary is like it says temporary. All changes you do on it will not be written in the DB. It exists only in the object where you declared it as a global (or a function in which you declared it as a local). When you enter in an object, a temptable will be empty (even if in the DB, there are records).
    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!


  • mthe80mthe80 Member Posts: 27
    Continuing about the insert, modify, delete and rename think.

    When I must use COMMIT?
    From what I read, it say COMMIT is used when your write a trx (into a table?) and then you write terx again.
    But IF the write trx only do it once in code, then the system will commit by it self.

    So whenever i use
    Repeat
    (insert,modify,delete)
    --> must COMMIT??
    Until

    or I don't have to use the COMMIT?
  • bbrownbbrown Member Posts: 3,268
    Navision uses implicit transactions. A transaction is strarted by the first command that changes the database (insert,modify,delete,..) and ends (and commit database changes) when the calling objects completes without error.

    An error will rollback the database to the point of last commit.

    The COMMIT statement can be used to alter this behavior. This statement will commit any open transaction. Most of your Navision coding will not require the use of an explicit COMMIT statement.
    There are no bugs - only undocumented features.
  • DenSterDenSter Member Posts: 8,307
    mthe80 wrote:
    So whenever i use
    Repeat
    (insert,modify,delete)
    --> must COMMIT??
    Until

    or I don't have to use the COMMIT?
    This depends on what you consider a transaction. If you want to commit each time you go through the loop, then you put the COMMIT inside the loop. If the loop encounters an error at some point, it will only rollback to the last COMMIT. If you consider the whole thing as one transaction, for instance when you loop through the sales lines for one shipment posting, then you can put a COMMIT statement right after the loop. You only have to do that though if something comes after the loop. If the loop is the last thing in your code, then just completing the code will commit the transaction to the database.
Sign In or Register to comment.