How to: Update Data

Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2, Microsoft Dynamics AX 2012 Feature Pack, Microsoft Dynamics AX 2012

You can use the while select statement to modify data. For more information, see while select Statements.

All select statements use a table variable. This variable must be declared before a select statement can be executed. For more information, see Tables as Data Types.

In the following example, a customer record is updated when the condition specified by the where clause is met.

The ttsBegin and ttsCommit keywords are used to help ensure the integrity of the data transaction. For more information, see Transaction Integrity.

Warning

Microsoft Dynamics AX does not allow you to pass unbounded string parameters in where clauses. You create a bounded string by declaring a character limit after you specify the data type. In the example below, you declare the customer account number parameter as str 30 AccountNum.

    static void UpdateCustomerCreditMax(str 30 AccountNum, real newMaximum)
    {
        CustTable custTable;
    
    
        ttsBegin;
     
        while select forUpdate custTable        
                where custTable.AccountNum == AccountNum
                  
        {
            custTable.CreditMax = newMaximum;
            custTable.update();
            
        }
      
        
        ttsCommit;
    }

See also

Optimizing Record Inserts

Select Statement Syntax

Database for Microsoft Dynamics AX

Announcements: New book: "Inside Microsoft Dynamics AX 2012 R3" now available. Get your copy at the MS Press Store.