For both WRITE commands,
you must correctly envision the desired commands in the finished DMC to
correctly specify the FORMAT statements in DSDELIM. The first WRITE command
must include double quotes to surround the title text, as well as encompass
the delimiter string. The third WRITE command must correctly include the
required single quotes to encircle the attribute names as part of the
#NAM specifier.
One of the tricks
to writing these types of format statements is to know that single quotes
can also be used to delimit text in a FORMAT statement. This is especially
useful when you need to output text containing double quotes.
Generated
Code
The following code
is generated by the DSDELIM tool for the DIVISIONS dataset.
set ds DIVISIONS find all
init 8 DIVISIONS.txt write on 8 format( - "Division Name|" $ - "Div./ID|" $ - "City|" $ - "State//Province|" $ - "Country|" $ - "Division Budget|" $ - "Profits|" $ - " ") write on 8 fmt(" ")
for each record do write on 8 - #NAM'DIVISION_NAME' - $text(#NAM'DIVISION_ID') - #NAM'CITY' - #NAM'STATE' - #NAM'COUNTRY' - $text(#NAM'DIVISION_BUDGET') - $text(#NAM'PROFITS') - format( 7(a "|") ) end_for release 8 write format("Created DIVISIONS.TXT")
|
|
An output channel
is initialized, followed by a WRITE command to create the heading line
for the output data. A record loop performs another WRITE command on the
selected records in the dataset. All non-text data is converted to text,
thus making the FORMAT portion of the WRITE command very simple. The #NAM
operator is used to ensure operation of the DMC file in the event that
an attribute name happens to be a keyword, in which case an error would
ensue.
Using
the DSDELIM Tool
To use the DSDELIM
tool, choose the dataset from which you need to extract data, and open
it in a System 1032 session. The following example uses the DIVISIONS
dataset located in the S1032_DEMO directory.
$ s1032 Computer Corporation of America System 1032 Version V9.81-1 Copyright 2002, Computer Corporation of America 1032> open ds divisions in s1032_demo read Current dataset is now DIVISIONS 1032> 1032> use DSDELIM Initializing channel 1 Created DMC file DIVISIONS.DELIMIT 1032> 1032> use DIVISIONS.DELIMIT 6 DIVISIONS records found Initializing channel 8 Created DIVISIONS.TXT 1032> exit $ $ type DIVISIONS.TXT Division Name|Div./ID|City|State//Province|Country|Division Budget|Profits| Eastern Entertainment| 1|New York City|New York|USA| 1000000.00| 200000.00| California Classic Films| 2|Hollywood|California|USA| 1200000.00| 225000.00| Autre Chose Cinema| 3|Montreal|Quebec|Canada| 1250000.00| 225000.00| Cine Quebec| 4|Montreal|Quebec|Canada| 1230000.00| 240000.00| Cinemexico| 5|Mexico City|Mexico|Mexico| 2750000.00| 300000.00| Vanguard Films| 6|Boston|Massachusetts|USA| 3000000.00| 275000.00| $
|
|
The DSDELIM tool
operates on DIVISIONS, the current dataset, creating the DIVISIONS.DELIMIT
command file. It locates the active records in the DIVISIONS dataset,
and applies the WRITE commands described in Generated
Code to output the headings, followed by the data from within
the dataset.
If the extraction
needs to be repeated later after dataset updates or upon another dataset
having the same structure as the DIVISIONS dataset, the DSDELIM program
need not be run again, because the DIVISIONS.DELIMIT program can be reused.
Note that DSDELIM
does not work upon a dataset containing arrayed attributes.
Other
Extraction Solutions
If you have this sort
of extraction problem, but are uncertain that using the DSDELIM tool is
the best solution for you, please have a look at previous articles on
this topic, which have resolved the problem a bit differently.