Modifying an Existing SQR Program for HTML

In this section, an existing sample program, ex12a.sqr, was modified to use HTML procedures. The modified program is named program ex28b.sqr. First, examine the output from ex12a.sqr when this program is run without modifications by using the -PRINTER:HT command-line flag. Three HTML files are generated: ex12a.htm, ex12a_frm.htm, and ex12a_toc.htm.

Program ex28b.sqr 
#include 'html.inc'
begin-setup
  declare-layout default
    max-lines=10000
  end-declare
end-setup
begin-program
 do main
end-program
begin-procedure main
do html_on
print $current-date (1,1) edit 'DD-MON-YYYY'
do html_p('')
do html_table('BORDER')
do html_tr('')
do html_th('WIDTH=250')
print 'Name'   (3,1)
do html_th('WIDTH=120')
print 'City'   (,32)
do html_th('WIDTH=60')
print 'State'  (,49)
do html_th('WIDTH=90')
print 'Total'  (,61)
begin-select
  do html_tr('')
  do html_td('')
name  (,1,30)
  do html_td('')
city  (,+1,16)
  do html_td('')
state (,+1,5)
  do html_td('ALIGN=RIGHT')
tot   (,+1,11) edit 99999999.99
  next-listing no-advance need=1
  let #grand_total = #grand_total + &tot
from customers
end-select  
  do html_tr('')
  do html_tr('')
  do html_td('COLSPAN=3 ALIGN=RIGHT')
print 'Grand Total' (+1,40)
  do html_td('ALIGN=RIGHT')
print #grand_total (,55,11) edit 99999999.99
do html_table_end
end-procedure ! main

In this code example, a DECLARE-LAYOUT command with a large page length setting that is specified in the MAX-LINES argument is issued to prevent page breaks.

The html_on procedure activates the HTML procedures.

The html_table, html_tr, html_td, and html_th procedures position the information in a tabular format. Note the arguments that are passed to the HTML procedures:

  • BORDER produces the sculpted border.

  • WIDTH defines the width of the columns.

  • ALIGN right-aligns the text in the Total column.

  • COLSPAN causes the Grand Total label to be spanned beneath three columns of data.

Instead of using a HEADING section, use the html_tr and html_th procedures to display column headings.

See Displaying Records in Tables.