Examples

Example setup
The examples use a temp-table holding a collection of MP3 files. The temp-table consist of 4 fields: the artist, the album, the tracknumber and the title of the track. See the code example for the definition.
Playing code
If you cut-and-paste this code into your editor you can replay the examples given and experiment with it.

      define temp-table song RCODE-INFORMATION
        field Artist     as character label 'Artist'    format 'x(12)'
        field Album      as character label 'Album'     format 'x(12)'
        field Track#     as integer   label 'Track#'    format '>>9'
        field TrackName  as character label 'TrackName' format 'x(40)' .

      define variable cOptions as character no-undo.

      input from song.d.
      repeat transaction:
        create song.
        import song.
      end.
      input close.

      run tt-file.p ( input temp-table song:handle,
                      input 'temp.txt',
                      input cOptions ).

      os-command no-wait start temp.txt.

You may need to change paths to temp.txt, song.d or tt-file.p. For each example the option string used is given.
Playing data

The data in the temp-table is as follows:

"Pink Floyd" "The Wall" 1 "In the flesh"
"Pink Floyd" "The Wall" 2 "Thin ice"
"Pink Floyd" "The Wall" 3 "Another brick in the wall"
"Pink Floyd" "The Wall" 4 "The Happiest Days Of Our Lives"
"Pink Floyd" "Meddle" 1 "One of these days"
"Pink Floyd" "Meddle" 2 "A pillow of winds"
"Pink Floyd" "Meddle" 3 "Fearless"
"Pink Floyd" "Meddle" 4 "San Tropez"
"Pink Floyd" "Meddle" 5 "Seamus"
"Pink Floyd" "Meddle" 6 "Echoes"

Save this data in a separate .d file named song.d. It is imported in the example program.
Example Overview
Below you will find the following examples:

* Display the contents 'as is'
* Use a default grid
* Use a grid for groups of 3 records.
* Make groups of records for each album
* Change the appearance of the gridlines.
* Suppress a field
* Suppress the header
* Over the top
* XML Output
* XML Output using attributes

Example 1: Display the contents 'as is'
- The TT expositor is called with only the filetype option. Note that the result would be the same if we did not specify anything at all as an option. This is left as an exercise for the reader ;-)

cOptions = 'FileType:txt'.

The following two lines are functionally equivalent to the former:

cOptions = ''.
cOptions = 'txt'.

output:

Artist Album Track# TrackName
Pink Floyd The Wall 1 In the flesh
Pink Floyd The Wall 2 Thin ice
Pink Floyd The Wall 3 Another brick in the wall
Pink Floyd The Wall 4 The Happiest Days Of Our Lives
Pink Floyd Meddle 1 One of these days
Pink Floyd Meddle 2 A pillow of winds
Pink Floyd Meddle 3 Fearless
Pink Floyd Meddle 4 San Tropez
Pink Floyd Meddle 5 Seamus
Pink Floyd Meddle 6 Echoes

Example 2: Use a default grid
- Display a 'grid' for text file output. Both a vertical and a horizontal grid is displayed (optional). You can specify that you want a horizontal grid, a vertical grid or both using the 'Grid' option. Use 'Grid:hor', for horizontal, 'Grid:ver' for vertical and 'Grid:yes' for both.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'.

output:

  Artist       | Album        | Track# | TrackName
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 1      | In the flesh
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 2      | Thin ice
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 3      | Another brick in the wall
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 4      | The Happiest Days Of Our Lives
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 1      | One of these days
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 2      | A pillow of winds
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 3      | Fearless
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 4      | San Tropez
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 5      | Seamus
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 6      | Echoes
  -------------+--------------+--------+-----------------------------------------

Example 3: Use a grid for groups of 3 records.
- The vertical grid can be told to appear after each lines using the GridInterval option: 'GridInterval:3'. The default value is 1. Specifying 0 as the interval disables the vertical grid.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'GridInterval:3'.

output:

  Artist       | Album        | Track# | TrackName
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 1      | In the flesh
  Pink Floyd   | The Wall     | 2      | Thin ice
  Pink Floyd   | The Wall     | 3      | Another brick in the wall
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 4      | The Happiest Days Of Our Lives
  Pink Floyd   | Meddle       | 1      | One of these days
  Pink Floyd   | Meddle       | 2      | A pillow of winds
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 3      | Fearless
  Pink Floyd   | Meddle       | 4      | San Tropez
  Pink Floyd   | Meddle       | 5      | Seamus
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | Meddle       | 6      | Echoes

Example 4: Make groups of records for each album
- We are going to suppress the artist and the album as long as they don't change. We also want a gridline to appear when the album changes.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'FirstOfList:Artist,Album'
+ chr(1) + 'GridField:Album'.

output:

  Artist       | Album        | Track# | TrackName
  -------------+--------------+--------+-----------------------------------------
  Pink Floyd   | The Wall     | 1      | In the flesh
               |              | 2      | Thin ice
               |              | 3      | Another brick in the wall
               |              | 4      | The Happiest Days Of Our Lives
  -------------+--------------+--------+-----------------------------------------
               | Meddle       | 1      | One of these days
               |              | 2      | A pillow of winds
               |              | 3      | Fearless
               |              | 4      | San Tropez
               |              | 5      | Seamus
               |              | 6      | Echoes
  -------------+--------------+--------+-----------------------------------------

Example 5: Change the appearance of the gridlines.
- We are going to use different characters for the gridlines. We want to use '.' for horizontal lines and ':' for both vertical lines and crossings of hor and ver lines.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'FirstOfList:Artist,Album'
+ chr(1) + 'GridField:Album'
+ chr(1) + 'GridCharHor:.'
+ chr(1) + 'GridCharVer::'
+ chr(1) + 'GridCharCross::'.

output:

  Artist       : Album        : Track# : TrackName
  .............:..............:........:.........................................
  Pink Floyd   : The Wall     : 1      : In the flesh
               :              : 2      : Thin ice
               :              : 3      : Another brick in the wall
               :              : 4      : The Happiest Days Of Our Lives
  .............:..............:........:.........................................
               : Meddle       : 1      : One of these days
               :              : 2      : A pillow of winds
               :              : 3      : Fearless
               :              : 4      : San Tropez
               :              : 5      : Seamus
               :              : 6      : Echoes
  .............:..............:........:.........................................

Example 6: Suppress a field
- We are not interested in the track number, so we want to suppress this field.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'FirstOfList:Artist,Album'
+ chr(1) + 'GridField:Album'
+ chr(1) + 'GridCharHor:.'
+ chr(1) + 'GridCharVer::'
+ chr(1) + 'GridCharCross::'
+ chr(1) + 'SkipList:Track#'.

output:

  Artist       : Album        : TrackName
  .............:..............:.........................................
  Pink Floyd   : The Wall     : In the flesh
               :              : Thin ice
               :              : Another brick in the wall
               :              : The Happiest Days Of Our Lives
  .............:..............:.........................................
               : Meddle       : One of these days
               :              : A pillow of winds
               :              : Fearless
               :              : San Tropez
               :              : Seamus
               :              : Echoes
  .............:..............:.........................................

Example 7: Suppress the header
- We are not interested in the header either so we want to suppress this field. Secondly, this strange grid settings are annoying us so we also get rid of them.

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'FirstOfList:Artist,Album'
+ chr(1) + 'GridField:Album'
+ chr(1) + 'SkipList:Track#'
+ chr(1) + 'Labels:no'.

output:

  Pink Floyd   | The Wall     | In the flesh
               |              | Thin ice
               |              | Another brick in the wall
               |              | The Happiest Days Of Our Lives
  -------------+--------------+-----------------------------------------
               | Meddle       | One of these days
               |              | A pillow of winds
               |              | Fearless
               |              | San Tropez
               |              | Seamus
               |              | Echoes
  -------------+--------------+-----------------------------------------

Example 8: Over the top
- If you are really enthusiastic about al these new features, one warning: don't overdo it, or you may find yourself producing output which is somewhat over the top, if you catch my drift ...

cOptions = 'FileType:txt' + chr(1) + 'Grid:yes'
+ chr(1) + 'FirstOfList:Artist,Album'
+ chr(1) + 'GridField:Album'
+ chr(1) + 'GridCharHor:-='
+ chr(1) + 'GridCharVer:| '
+ chr(1) + 'GridCharCross:+='.

output:

  Artist        |   Album         |   Track#  |   TrackName
  -=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  Pink Floyd    |   The Wall      |   1       |   In the flesh
                |                 |   2       |   Thin ice
                |                 |   3       |   Another brick in the wall
                |                 |   4       |   The Happiest Days Of Our Lives
  -=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
                |   Meddle        |   1       |   One of these days
                |                 |   2       |   A pillow of winds
                |                 |   3       |   Fearless
                |                 |   4       |   San Tropez
                |                 |   5       |   Seamus
                |                 |   6       |   Echoes
  -=-=-=-=-=-=-=+=-=-=-=-=-=-=-=-=+=-=-=-=-=-=+=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Example 9: XML Output
- If you want to produce an XML file containing your data, you can use the XML filetype.

cOptions = 'FileType:xml' + chr(1).

output:

<?xml version="1.0" ?>
-
-
Pink Floyd
The Wall
1
In the flesh

-
Pink Floyd
The Wall
2
Thin ice

-
Pink Floyd
The Wall
3
Another brick in the wall

(snip)

Example 10: XML Output using attributes
- You can specify which fields identify a record using the AttributeList.

cOptions = 'FileType:xml' + chr(1) + 'AttributeList:Artist,Album,Track#'.

output:

    < ?xml version="1.0" ?>
    - < RecordSet>
      - < song Album="The Wall" Track="1" Artist="Pink Floyd">
          In the flesh
        < /song>
      - < song Album="The Wall" Track="2" Artist="Pink Floyd">
          Thin ice
        < /song>
      - < song Album="The Wall" Track="3" Artist="Pink Floyd">
        < TrackName>Another brick in the wall
      < /song>
    (snip)
    < /RecordSet>