SUBROUTINE TABLE_S3
* Create a simple table using the RWS_TABLE routines and
* populate it with data from a Reality file. Draw borders
* round the cells. Format the columns using CSS classes.

* Include the RealWeb definitions.
INCLUDE #RW.INCLUDE.DEFS FROM /SYSFILES/REALWEB,BP

EQU LF TO CHAR(10)
EQU TAB TO CHAR(9)
EQU AM TO CHAR(254)
EQU VM TO CHAR(253)

* Get the URL of the Reality item server.
STYLESHEET = ""
CALL RW_GET_PARAM("__isurl", STYLESHEET)
* Specify the location of the stylesheet.
STYLESHEET = STYLESHEET : "/REALWEB-ITEMS/table.css"

* Start the HTML page.
CALL RW_START_HTML_PAGE("RWS_Table with Reality Data Example 2", "", STYLESHEET, "", "")

* Initialise the HTML string buffer.
HTML = ""

* Create a caption for the table.
TEXT = "Hotel Guests"
CALL RWS_TABLE_CAPTION(TEXT, "")
HTML = HTML : TEXT

* Assemble some data to go in the table.
PERFORM "SORT-SPREAD GUESTS < '200' " : ...
"ROOM NAME ADDRESS CITY STATE ZIP ID-SUPP" ...
CAPTURING aData
* The headings are in the second attribute.
DEL aData<1>
aHeadings = aData<1>
* SORT-SPREAD returns tab-separated data; we need a dynamic array.
aHeadings = CHANGE(aHeadings, TAB, AM)
* The data is in the third attribute onwards.
DEL aData<1>
* SORT-SPREAD returns tab-separated data; we need a dynamic array.
aData = CHANGE(aData, TAB, VM)

* For each heading...
FOR I = 1 TO DCOUNT(aHeadings , AM)
* Tag the text as a heading cell.
S = aHeadings<I>
CALL RWS_TABLE_HEADER(S, "")
aHeadings<I> = S
NEXT I
* Tag the attribute as a table row.
CALL RWS_TABLE_ROW(aHeadings, "")
HTML = HTML : aHeadings

* For each data attribute...
FOR I = 1 TO DCOUNT(aData, AM)
* For each value in the attribute...
FOR J = 1 TO DCOUNT(aData<I>, VM)
* Give alternate columns a different style.
IF MOD(INT(J),2) THEN
aClass = "gray"
END ELSE
aClass = "white"
END
* Tag the text as a table cell.
S = aData<I,J>
CALL RWS_TABLE_DATA(S, aClass)
aData<I,J> = S
NEXT J
* Tag the headings as a table row.
S = aData<I>
CALL RWS_TABLE_ROW(S, "")
aData<I> = S
NEXT I
HTML = HTML : aData

* Give the table a 3 pixel border.
aClass = ""
aClass<2> = "3"

* Create the table.
CALL RWS_TABLE(HTML, aClass)

* Output the HTML.
HTML = CONVERT(HTML, AM:VM, LF:TAB)
CALL RW_PUT(HTML)

* Complete the page.
CALL RW_END_PAGE
RETURN