To parse the data returned from a report, you first need to understand the report's format. If you included the {TABDELIMIT} command in the report script, the data comes back in the following format:
<token><tab><token><tab><token><tab>..........<token><newline> <token><tab><token><tab><token><tab>..........<token><newline> ..... <token><tab><token><tab><token><tab>..........<token><null>
For example, consider the following report script:
{SSFORMAT}{DECIMAL 0} <COL(Year) <ROW(Market) Budget Sales Cola <CHILD Qtr1 <ICHILD Market !
This report script would normally output data that looks like the following:
Budget Sales Cola Jan Feb Mar East 5200 5000 5300 West 5600 5350 5700 Central 4250 4050 4400 South 3800 3450 3800 Market 18850 17850 19200
When you include the {TABDELIMIT} command, the report script outputs the data as follows:
<tab>Budget<tab>Sales<tab>Cola<newline> <tab>Jan<tab>Feb<tab>Mar<newline> East<tab>5200<tab>5000<tab>5300<newline> West<tab>5600<tab>5350<tab>5700<newline> Central<tab>4250<tab>4050<tab>4400<newline> South<tab>3800<tab>3450<tab>3800<newline> Market <tab>18850<tab>17850<tab>19200<null>
To parse data in this format, scan the returned string for a tab, a newline, or a null, each of which define the end of a token. The token can be one of four types:
A member name (must begin with an alphanumeric character)
A data value (must always begin with a number or a negative sign)
A special value, such as #Missing (must begin with a # character)
An empty cell (none of the above)
If the report is stored in an internal data structure, such as a grid or array, and the report shrinks in the number of rows or the number of columns (for example, after a zoom out operation), you might need to adjust the bounds of the new report.
The possible conflict between numeric values and numeric member names can usually be resolved by scanning any tokens that begin with a number and validating that they conform to the parameters (for example, decimal precision) of a number value. Any token that does not conform should be treated as a member name.
A more reliable method is to use the positioning of the token in the report to determine whether it is a member name or a data value. The first x rows of the report can be only member names (where x is the number of column dimensions + 1 row for the page header), and the first y columns can only be member names (where y is the number of row dimensions). If the coordinates of the token are greater than both x and y, then the token is either a special value (begins with a # character), or it is a number value.
It is possible to force double quotation marks around all member names (and so avoid the identification issue) by using the <QUOTEMBRNAMES command. When you use this command, you can recognize member names by the leading double quotation marks.
It is often useful to parse the returned report output tokens into Page, Column, Row and Data areas, so they can be easily re-used in subsequent reports (see Using Report Output as a Script, below).