Friday, 22 March 2019

Loop the temp table and update the temp table based on conditions

Loop the temp table and update the temp table based on conditions : 


 SalesCreateReleaseOrderLineTmp  lineTmp = sender.datasource().cursor();   // get the record
SalesCreateReleaseOrderLineTmp  localTmpTable; // local table for looping
 localTmpTable.setTmpData(lineTmp);  // assigning our tempt table to local table

       
ttsbegin;
while select forupdate  from localTmpTable
            where localTmpTable.FBHAdditive == NoYes::Yes
            && localTmpTable.FBHMainAgreementLine == agreementLineQuantityCommitment.LineNumber

{
 localTmpTable.SalesQty = Global::roundDownDec(unitConvertionValueAdditiveSalesUnit,2); 
 localTmpTable.doUpdate(); // updating temp table field data
}

ttscommit;
lineTmp.setTmpData(localTmpTable); // assigning it to original table


for data source also we need to get the data source first the get the temp table and run the loop.

delete button  event handler for selected records in form form , which is having data source as temp table and need to delete records based on conditions from temp table code is below.

[FormControlEventHandler(formControlStr(SalesAgreementGenerateReleaseOrder, DeleteLineGridCmdButton), FormControlEventType::Clicked)]
    public static void DeleteLineGridCmdButton_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        FormRun                        formrun  = sender.formRun();
        FormDataSource                 lines_ds = formrun.dataSource(formDataSourceStr(SalesAgreementGenerateReleaseOrder,SalesCreateReleaseOrderLineTmp));
        SalesCreateReleaseOrderLineTmp lines = lines_ds.cursor();
       
        ttsbegin;
        MultiSelectionHelper           selectionHelper = MultiSelectionHelper::construct();
        SalesCreateReleaseOrderLineTmp tmpLines,tmpLinesMsg;
        selectionHelper.parmDatasource(lines_ds);
       
        SalesCreateReleaseOrderLineTmp  localTmpTable;
        localTmpTable.setTmpData(lines);
       
        //for error message if user selects additive lines
        tmpLinesMsg = selectionHelper.getFirst();
        While(tmpLinesMsg)
        {
            if (tmpLinesMsg.FBHAdditive)
            {
                throw Error("@FBH:FBH270269");
            }
            tmpLinesMsg =selectionHelper.getNext();
        }

        // for deleting selected lines
        tmpLines = selectionHelper.getFirst();
        While(tmpLines)
        {
            ttsbegin;
            while select forupdate localTmpTable
                where localTmpTable.RecId == tmpLines.RecId
            {
                SalesCreateReleaseOrderLineTmp  localTmpTableAdditives;
                AgreementLineQuantityCommitment agreementLineQuantityCommitment;
                localTmpTableAdditives.setTmpData(lines);

                while select forupdate  localTmpTableAdditives
                    where localTmpTableAdditives.FBHAdditive == NoYes::Yes
                join agreementLineQuantityCommitment
                    where localTmpTableAdditives.FBHMainAgreementLine == agreementLineQuantityCommitment.LineNumber
                    && agreementLineQuantityCommitment.RecId == localTmpTable.AgreementLineQuantityCommitment
                {
                    localTmpTableAdditives.doDelete(); // deleting all additive lines for corresponded link with main agreement line
                }

                localTmpTable.doDelete();// deleting main agreement line
            }
            ttscommit;
            tmpLines =selectionHelper.getNext();

        }
        lines.setTmpData(localTmpTable);
        lines_ds.research(true);
        ttscommit;
        lines_ds.executeQuery();
    }

No comments:

Post a Comment