How to add values while extracting
<pre><code>for (int l = 0; l &lt; extractedData.size(); l++) {
                TSAMMGFSScfInvoiceData data = extractedData.get(l);
                if (DateUtil.formatDate(data.getMATDT()).equals(tomorrowDate)) {
                    BigDecimal S = null;
                    String obligatitionNumber = isNull(data.getOBLIGNUM());
                    String buyerName = isNull(data.getBUYERNAME());
                    String invoiceNumber = isNull(data.getINVNUMBER());
                    String sellerName = isNull(data.getSELLERNAME());
                    String importFileName = isNull(data.getIMPNAME());
                    String dataField_1 = isNull(data.getDATAFIELD1());
                    String dataField_2 = isNull(data.getDATAFIELD2());
                    String dataField_3 = isNull(data.getDATAFIELD3());
                    String dataField_4 = isNull(data.getDATAFIELD4());

                    reportData.append(TYPE_INVOICE).append(PIPE);
                    reportData.append(obligatitionNumber).append(PIPE);
                    reportData.append(buyerName).append(PIPE);
                    reportData.append(CURRENCY_USD).append(PIPE);

                    if (data.getINVAMT() == null) {

                        reportData.append("").append(PIPE);
                    } else {
                        reportData.append(data.getINVAMT().toString()).append(PIPE);
                    }

                    reportData.append(invoiceNumber).append(PIPE);
                    reportData.append(DateUtil.formatDate(data.getCM_MATDT(), DATE_FORMAT_MMDDYYYY_SHORT))
                            .append(PIPE);
                    reportData.append(sellerName).append(PIPE);
                    reportData.append(importFileName).append(PIPE);
                    reportData.append(dataField_1).append(PIPE);
                    reportData.append(dataField_2).append(PIPE);
                    reportData.append(dataField_3).append(PIPE);
                    reportData.append(dataField_4.replace("/", "")).append(PIPE);
                    reportData.append(presentDate).append(PIPE);
                    reportData.append(DateUtil.formatDate(currentDate, DATE_FORMAT_MMDDYYYYHHMM)).append(PIPE);
                    reportData
                            .append(DateUtil.formatDate(data.getLASTACTIVITYDTTM_CM(), DATE_FORMAT_MMDDYYYY_SHORT))
                            .append(invoiceNumber).append(PIPE);
                    reportData.append("\r\n");
                    b++;

                }
            }
</code></pre>

<p>I am extracting data from database. There is one column INVAMT(in the middle of the code) of BigDecimal type. I want to add all the values of INVAMT which I get once it is in if loop. How would I do that? 
Secondly is there a way to declare or get that value outside if loop or for loop?                        </p>