SUBROUTINE TABLE_S5
* Create a table organised into horizontal and vertical sections.
* This demonstrates the use of most of the table functions.

* 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/blue.css"

* Start the HTML page.
CALL RW_START_HTML_PAGE("Complex RWS_Table Example", "", STYLESHEET, "", "")

* Create a caption to appear below the table.
TABLE = "Cereal preference, by Gender"
aClass = ""
aClass<2> = "bottom"
CALL RWS_TABLE_CAPTION(TABLE, aClass)

* Create groups of columns.
CALL RWA_TABLE_COLGROUP(TABLE, 1, "", "")
CALL RWA_TABLE_COLGROUP(TABLE, 1, "", "")
CALL RWA_TABLE_COLGROUP(TABLE, 2, "", "")

* Build up the data to go in the table, by adding the cells to a
* row one at a time. When complete, add the row to the section.
* When the section is complete, add it to the table.

* Start with a head section containing two rows.
* The top left-hand corner of the table will contain an empty cell
* spanning two columns and two rows.
CELL = ""
aClass = ""
aClass<4> = 2 ;* Span two columns.
aClass<5> = 2 ;* Span two rows.
CALL RWS_TABLE_HEADER(CELL, aClass) ;* Create the cell.
ROW = CELL ;* Add it to the row.

* The next cell will span two columns of the top row.
CELL = "Cereal"
aClass = ""
aClass<4> = 2 ;* Span two columns.
CALL RWS_TABLE_HEADER(CELL, aClass) ;* Create the cell.
ROW = ROW : CELL ;* Add it to the row.

CALL RWS_TABLE_ROW(ROW, "") ;* Create the table row.
SECT = ROW ;* Add it to the head section.

* The second row will contain two header cells.
CELL = "Choco flakes"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = CELL
CELL = "Bran rings"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = ROW : CELL ;* Add them to the row.

CALL RWS_TABLE_ROW(ROW, "") ;* Create the table row.
SECT = SECT : ROW ;* Add it to the head section.

CALL RWS_TABLE_HEAD(SECT, "") ;* Create the head section.
TABLE = TABLE : SECT ;* Add it to the table.

* The body of the table will be divided into to two sections, each
* containing two rows.
* The first cell will span two rows.
CELL = "Boys"
aClass = ""
aClass<5> = 2 ;* Span two rows.
CALL RWS_TABLE_HEADER(CELL, aClass)
ROW = CELL : LF
* The rest of the row will contain a header and two data cells.
CELL = "Under 11"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = ROW : CELL : LF
CELL = "92%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL : LF
CELL = "8%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL

CALL RWS_TABLE_ROW(ROW, AM:"CENTER") ;* Create the table row.
SECT = ROW ;* Add it to the body section.

* The second row will also contain a header and two data cells.
CELL = "11 and over"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = CELL : LF
CELL = "87%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL : LF
CELL = "13%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL : LF

CALL RWS_TABLE_ROW(ROW, AM:"CENTER") ;* Create the table row.
SECT = SECT : ROW : LF ;* Add it to the body section.

CALL RWS_TABLE_BODY(SECT, "") ;* Create the body section.
TABLE = TABLE : SECT : LF ;* Add it to the table.

* The second body section will have the same structure as the first.
CELL = "Girls"
aClass = ""
aClass<5> = 2 ;* Span two rows.
CALL RWS_TABLE_HEADER(CELL, aClass)
ROW = CELL : LF
CELL = "Under 11"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = ROW : CELL : LF
CELL = "74%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL : LF
CELL = "26%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL

CALL RWS_TABLE_ROW(ROW, AM:"CENTER") ;* Create the table row.
SECT = ROW : LF ;* Add it to the body section.

CELL = "11 and over"
CALL RWS_TABLE_HEADER(CELL, "")
ROW = CELL : LF
CELL = "37%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL : LF
CELL = "63%"
CALL RWS_TABLE_DATA(CELL, "")
ROW = ROW : CELL

CALL RWS_TABLE_ROW(ROW, AM:"CENTER") ;* Create the table row.
SECT = SECT : ROW : LF ;* Add it to the body section.

CALL RWS_TABLE_BODY(SECT, "") ;* Create the body section.
TABLE = TABLE : SECT : LF ;* Add it to the table.

* The foot section will contain a single row containing one cell
* centred across all four columns.
CELL = "Excludes children under 5."
aClass = ""
aClass<2> = "CENTER" ;* Centre the text.
aClass<4> = 4 ;* Span four columns.
CALL RWS_TABLE_DATA(CELL, aClass)
CALL RWS_TABLE_ROW(CELL, "") ;* Create the table row.
CALL RWS_TABLE_FOOT(CELL, "") ;* Create the foot section.
TABLE = TABLE : CELL : LF ;* Add it to the table.

* Give the table a border.
aClass = ""
aClass<2> = "border"
* Draw rules between the sections.
aClass<3> = "GROUPS"
* Set the cell spacing and padding.
* Give the table a background colour.
aClass<4> = "cellspacing=0 cellpadding=5 bgcolor=lightsteelblue"

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

* Output the TABLE.
CALL RW_PUT(TABLE)

* Complete the page.
CALL RW_END_PAGE
RETURN
Result
HTML