Convert

PURPOSE:  The CONVERT command restructures the records in the current Data Set (DS) to a form specified by another Schema Definition (SD) and writes the restructured DS to an output DS.  CONVERT allows the altering of the field types, names, or sizes, storage form, and data.  May only be used with a single record type data set.  This command applies to DB-MACH2 RDBMS applications.

SYNTAX

CONVERT [APPEND] TO ds_name [IN DBL dbl_name]
[/USE/ DOMAIN name]
[WHEN clause]
[{IF; UNLESS} clause]
[SET clause]
[SHOWING clause]
[{STOP; END} clause]

APPEND TO ds_name

writes the new records on the end of an existing DS.

TO ds_name

writes the new records in a DS.  If the output DS contains records, they will be removed at the beginning of the command.

IN DBL dbl_name

is used to convert to a DS in another Data Base Library (DBL).

/USE/DOMAIN name

specifies the domain of a declared Data Index (DI).  If a DI is used, the output records are in the order of the domain specified.

WHEN clause

limits conversion to records having the specified key field values when a DI is in use.  Described in detail in Chapter 7.

{IF; UNLESS} clause

described in detail in Chapter 7.

SET clause

The SET clause must be used if the new field name is different from the old field name, or if the field value is calculated.  Any fields not included in a SET clause are converted if the field name in the target DS is the same as either the field name or an alias in the source DS.  Aliases in the target DS are not considered.  Field names in the output DS can be identified with the optional suffix :C. Described in detail in Chapter 7.

SHOWING clause

Described in detail in Chapter 7.  Records are displayed (or saved) after the SET clause is applied.

{STOP; END} clause

Described in detail in Chapter 7.

EXAMPLE

*LIST SD TDATA

00010 STORE_CODE,CHAR,3
00020 ORD_NUM,CHAR,20
00030 O_DATE, DATE, ALIAS ORD_DATE
00040 AMT,INT,6
00050 PAY_TERMS,CHAR,12
00060 TITLE_CODE,CHAR,6

*LIST SD SALES_DBM2

00010 STORE_CODE, CHAR,4
00020 ORD_NUM,CHAR,20
00030 ORD_DATE, DATE
00040 QTY,INT,6
00050 PAY_TERMS, CHAR,12
00060 TITLE_CODE, CHAR,6

*USE DS TDATA

*CONVERT TO SALES_DBM2 SET 2 * AMT:M TO QTY:C

The field STORE_CODE is automatically converted from 3 to 4 characters, since the field names are identical.  The SET clause doubles AMT values in the PRICE field in the second DS.  The field O_DATE is converted to ORD_DATE, since ORD_DATE is an alias in the source DS.

NOTES:  CONVERT does not affect the current DS.  You can use system functions in the SET clause to do data conversion.   For example, to convert use:

to convert CHAR to INT use "set @INVAL fieldname to fieldname:c"

CONVERT rounds numeric fields, as appropriate.  In the case of incompatible data types, CONVERT displays error messages and continues the command, leaving the incompatible fields blank.  When field lengths do not match, ACCENT R truncates values if necessary.  If the truncated portion contains data, a warning message is displayed; if the truncated portion contains only spaces, no message is displayed.

When changing data types, the following conversions are attempted.  Binary storage form can be converted to ASCII and vice versa.  If a field contains data that cannot be converted to the new data type, a warning message is displayed.

CAN BE CONVERTED INTO FIELD TYPE

FIELD TYPE

Alphabetic

Char

Int

Numeric

Virtual

Date

Full-date

Real

Bit

Signed-bit

Date Time

Alphabetic

X

X

Char

X

X

X

X

X

X

X

X

X

X

Int

X

X

X

X

X

X

X

X

X

Numeric

X

X

X

X

X

X

X

Virtual

X

X

X

X

X

X

X

Date

X

X

X

X

X

Fulldate

X

X

X

X

X

X

Real

X

X

X

X

X

X

X

Signed Bit

X

X

X

X

X

X

X

X

X

Bit

X

X

X

X

X

X

X

X

X

Date Time

X

X

X

Data Type Conversions Attempted by CONVERT