Extract

PURPOSE:  The EXTRACT command retrieves fields of selected records which may be displayed on the terminal, written to a system file or output to one or more data sets.

Syntax

EXTRACT [/USE/ DOMAIN name]

[WHEN clause]

[{IF; UNLESS} clause]

"[{IF; UNLESS} clause; [APPEND] TO ds_name; [IN DBL name]"

[MULTIPLE]]

[VIA clause]

[SHOWING clause]

[SET clause]

[STOP; END clause]

[UNQ/UALIFIED/ [APPEND] TO ds_name [IN DBL name]]

EXTRACT

with no VIA or SHOWING clause has the same effect as the SHOW DATA clause; i.e., it displays all fields, separated by one space, for the selected records.  The field separator, a space, can be changed by setting another value to @SEPARATOR.

/USE/ DOMAIN name

specifies the domain of a Data Index (DI) to be used for retrieving the records.

WHEN clause

limits indexed retrieval to records having the specified key field values.  Described in detail in Chapter 7.

{IF; UNLESS} clause

is a conditional clause.  If a single conditional clause is used without a TO ds_name clause, all records that satisfy the conditionals are processed by the SET clause, the PM, and the SHOWING clause.  Described in detail in Chapter 7.

[APPEND] TO ds_name
[IN DBL name]

creates an output DS.  A single TO ds_name clause can be used without a conditional clause.  All records are written to the output DS after the SET clause is applied.  If APPEND TO is used, the selected data will be appended to the destination DS.  If TO is used without APPEND, the selected data will replace the existing contents of the destination DS.  The destination DS must already exist in the current Data Base Library (DBL) and have the same Schema Definition  (SD) as the current DS or the specified DBL if one is specified.

{IF; UNLESS} clause
[APPEND] TO ds_name
[{IN DBL} name]

selects records for output DS’s.  This clause may be repeated up to ten times to create different output DS’s for different conditions.  All destination DS’s must already exist, and have the same Schema Definitions identical as the current DS.

If a conditional clause is used with TO ds_name, then any additional conditional clauses must also specify output DS’s.  In this case each conditional clause selects records for the respective output DS, and records that satisfy any conditional clauses are altered in the output DS’s by the SET clause or Process Module (PM) specified in the VIA clause.

MULTIPLE

is used, when more than one 'conditional TO' clause is used.  This option allows a copy of the current record to be written on more than one of the output DS’s.  If more than one conditional clause is used without MULTIPLE, a copy of the current record is written on the output DS associated with the first conditional clause that the record satisfies , and only on that output DS.  MULTIPLE causes all conditional clauses to test the record, and a copy of the record to be written to each DS whose conditional clause is satisfied.

VIA clause

is used to specify the name of a PM to be executed after each record is read.  When EXTRACT executes a Process Module, records are not displayed at the terminal unless a SHOWING clause is used. Described in detail in Chapter 7.

SHOWING clause

When a conditional clause is used, only the records that meet the specified condition will be acted upon by the SHOWING clause. Described in detail in Chapter 7.

SET clause

changes values in the current record to be displayed at the terminal, saved on a System File, or sent to output DS’s, but does not affect the current DS.  Described in detail in Chapter 7.

STOP; END clause

described in detail in Chapter 7.

UNQ/UALIFIED/ [APPEND] TO ds_name [IN DBL name]

is used to output a copy of the records not satisfying any of the conditional clauses to the specified data set.

EXAMPLE

The EXTRACT command is often used for interactive inquiry.  If a DI is declared, the WHEN clause is much faster than a conditional clause.

*USE DS BOOKS_DBM2 DI BOOKS_DBM2
*EXTRACT USE DOMAIN TITLE_CODE WHEN TITLE_CODE = TR1717 &
SHOW TYPE_CODE, 2B, PRICE
travel  2.99

When EXTRACT is used with no SHOWING or VIA clause and no output DS’s, it displays all fields, separated by one space (or the value in @SEPARATOR) at the terminal.

*USE DS STORE_DBM2
*EXTRACT IF STORE_CODE BEGINS WITH "7"
7238 Sophisticated 1492 S. Maria Plymouth   MA   01776   USA
7106 Een Boekwinkel Antwerspeg 13 Gouda   XX   00000   Netherlands

The next EXTRACT command copies all records that satisfy the conditional clause to one DS, and all records that fail the conditional clause to another DS.  The master DS is not affected.

*EXTRACT IF TITLE_CODE BEGINS WITH "CP" OR "TR" TO HOTSALE &
UNQUALIFIED TO SLOMOVE

The next example includes a SHOWING clause that calls for the displaying of text strings and values in two fields.

*EXTRACT IF QTY LE 35 SHOWING "TITLE_CODE:",TITLE_CODE,3B, &
"QUANTITY:", QTY
TITLE_CODE:  CP3896  QUANTITY: 15
TITLE_CODE:  FL1247  QUANTITY: 10
TITLE_CODE:  TR5139  QUANTITY: 5

NOTES:  To output all field values separated by commas for importing to other applications do the following:

*SET ',' TO @SEPARATOR
*EXTRACT SHOW DATA TO EXPORT.DAT

SEE ALSO:  @SEPARATOR