Jan 9, 2012

How to update a table ?


For example selects the table myTable for update. Any records with the name equal to 'my name' are updated. The AmountMST field has 100 added to its current value, and the AccountNum field is changed to account number 1050.
tsBegin;
select forUpdate myTable
         where myTable.Name=='My name';
 
myTable.AmountMST += 100;
myTable.AccountNum = 1050;
 
MyTable.update();
 
ttsCommit;

how to design a form through the code


static void createForm(Args _args)
{
    Args args;
    Form form;
    FormRun formRun;
    FormBuildDesign formBuildDesign;
    FormBuildDataSource formBuildDataSource;
    FormBuildDataSource formBuildDataSource2;
    FormBuildGridControl formBuildGridControl;
    FormDataSource formDataSource;
    DictTable dictTable;
    DictTable dictTable2;
    int idx;
    ;
    // Create the form header.
    form = new Form();

    // Add data sources to the form.
    dictTable = new DictTable(tablenum(CustTable));
    formBuildDataSource = form.addDataSource(dictTable.name());
    formBuildDataSource.table(dictTable.id());
    dictTable2 = new DictTable(78);
    formBuildDataSource2 = form.addDataSource(dictTable2.name());
    formBuildDataSource2.table(dictTable2.id());

    // Create the form design.
    formBuildDesign = form.addDesign("Design");

    // Add a grid control.
    formBuildGridControl =
 formBuildDesign.addControl(FormControlType::Grid, "Table Grid");
    formBuildGridControl.dataSource(dictTable.name());

    // Add a data field to the grid control.
    formBuildGridControl.addDataField(formBuildDataSource.id(),
    dictTable.fieldName2Id("AccountNum"));

    args = new Args();
    args.object(form);

    // Create the run-time form.
    formRun = new FormRun(Args);
    formRun.run();
    formRun.detach();

    // Return an object for the first data source,
    // and then display a query form.
    formdatasource = formRun.dataSource(1);
    formdatasource.prompt();
}

Jan 4, 2012

How to write a find() in a table


 
static  MyTable find(PrimarykeyEDT  _PrimaryKey)
{
MyTable  MyTable  ;
;
select firstonly   MyTable  ;

return (  MyTable);
}

=============  (OR) =============


public static  MyTable  find(EDTDocumentId _DocumentId, boolean _forupdate = false)
{
     MyTable   MyTable  = null;
    ;

     MyTable .selectForUpdate(_forupdate);

    if(_DocumentId)
    {
        select firstonly MyTable
        where  MyTable DocumentId == _DocumentId;
    }

    return  MyTable ;
}

      Example of find()
=================


static COL_ShipmentTerms find(COL_ShipmentTermId     ShipmentTermId,
                       boolean          _forUpdate = false,
                       ConcurrencyModel _concurrencyModel = ConcurrencyModel::Auto)
{
    COL_ShipmentTerms  shipmentTerms;
    ;

    if (ShipmentTermId)
    {
        if (_forUpdate)
        {
            shipmentTerms.selectForUpdate (_forUpdate);
            if (_concurrencyModel != ConcurrencyModel::Auto)
                shipmentTerms.concurrencyModel(_concurrencyModel);
        }
        shipmentTerms.selectLocked    (_forUpdate);

        select firstonly shipmentTerms
            index hint ShipmentTermIdx
            where shipmentTerms.ShipmentTermId == ShipmentTermId;
    }

    return shipmentTerms;
}