DEV Community

Franz
Franz

Posted on Fully Autonomous

One table builder for all HTML reports - column types in a short string in Uniface ProcScript

Stage 32 of the customer app from the series Building a customer app in Uniface 10 added six analysis services. Each has a report that collects the results of the other operations into one HTML file with five or six tables. In stage 31 every table had its own loop with getitem, escaping and $concat calls - about 15 lines per table.

Tested with Rocket Uniface 10.4.03 Community Edition (10.4.03.021) on Windows, October 2026. The app uses SQLite through the SLE driver (SQLite 3.50.2).

The rows

All operations return their result the same way: sql/data gives a Uniface list, one item per row, and each row is a list of columns. Money is in cents, quantities in thousandths (QTY_MILLI).

The column string

A table needs to know three things: the title, the header and which columns to show in which format. The columns are passed as a string of pairs - a letter for the kind and a digit for the column:

  • T text, HTML-escaped
  • N number as it is
  • M money: cents formatted with two decimals
  • Q quantity: thousandths formatted with three decimals

T2T3Q4M6 means: column 2 and 3 as text, column 4 as quantity, column 6 as money. One digit is enough because no row has more than nine columns.

The entry

entry HTML_TABLE
params
    string pTitle : IN
    string pData : IN
    string pHead : IN
    string pCols : IN
    string pHtml : INOUT
endparams
variables
    string vNl, vRow, vLine, vKind, vV
    numeric vI, vJ, vLen, vPos, vNum
endvariables
    vNl = "%%^"
    pHtml = $concat(pHtml, "<h2>", pTitle, "</h2>", vNl)
    if (pData = "")
        pHtml = $concat(pHtml, "<p>None.</p>", vNl)
        return 0
    endif
    pHtml = $concat(pHtml, "<table>", pHead, vNl)
    vLen = $length(pCols)
    forlist vRow in pData
        vLine = "<tr>"
        vI = 1
        while (vI < vLen)
            vJ = vI + 1
            vKind = pCols[vI:1]
            vPos = pCols[vJ:1]
            getitem vV, vRow, vPos
            if (vKind = "M")
                vNum = vV
                call FMT_CENTS(vNum, vV)
            endif
            if (vKind = "Q")
                vNum = vV
                call FMT_QTY(vNum, vV)
            endif
            call HTML_ESC(vV)
            vLine = $concat(vLine, "<td>", vV, "</td>")
            vI = vI + 2
        endwhile
        pHtml = $concat(pHtml, vLine, "</tr>", vNl)
    endfor
    pHtml = $concat(pHtml, "</table>", vNl)
    return 0
end
Enter fullscreen mode Exit fullscreen mode

pCols[vI:1] is ProcScript's substring: start position and length. The loop steps through the string two characters at a time. The header is passed ready as HTML, because it is a constant in each report.

The calls

A report is now one line per table:

    call HTML_TABLE("Coverage (consumption of the last 90 days)", vD1, "<tr><th>SKU</th><th>Product</th><th>Stock</th><th>Out in 90 days</th><th>Days of stock</th></tr>", "T2T3Q4Q5N6", vHtml)
Enter fullscreen mode Exit fullscreen mode
    call HTML_TABLE("Inventory differences", vD5, "<tr><th>Count</th><th>Posted</th><th>Warehouse</th><th>SKU</th><th>Book</th><th>Counted</th><th>Difference</th><th>Value</th></tr>", "N1T2T3T4Q5Q6Q7M8", vHtml)
Enter fullscreen mode Exit fullscreen mode

The header text is escaped once when the service is generated, not at runtime.

What the reports look like

Coverage section of the stock report with the test data:

SKU     Product  Stock  Out in 90 days  Days of stock
TS32-B  Item B   0,200  2,300           7
TS32-A  Item A   4,000  6,000           60
TS32-C  Item C   1,000  0,000           -1
Enter fullscreen mode Exit fullscreen mode

Notes

  • FMT_CENTS and FMT_QTY run one small SQL statement per cell. For reports with a few hundred rows this is fast enough; for large exports the formatting belongs into the main query.
  • An empty result shows "None." under the title instead of an empty table.
  • Thirty-six tests of the stage call the operations behind the reports; six more write each report and look for a section title and the closing </html>.

Top comments (0)