REFORMAT and SREFORMAT

REFORMAT and SREFORMAT

Top  Previous  Next

 

The REFORMAT verb constructs a new file from data in the source file. It is of use, for example, when constructing intermediate files in complex reporting processes.

 

REFORMAT {DICT} file.name

{USING {DICT} file.name}

{field.name {field.qualifier} ...}

{selection.clause}

{sort.clause}

{display.clause}

{record.id...}

{FROM select.list.no}

{TO new.file.name | TO DATA}

 

 

REFORMAT behaves like LIST except that the data identified by the display clause is used to populate a new file instead of being displayed or printed. The first item in the data is used as the record id for the item in the new file. The remaining items form the fields within the record. REFORMAT does not automatically prefix the display clause with @ID.

 

The SREFORMAT command is identical to REFORMAT except that it sorts by record id after any other sorting has been applied.

 

The TO clause can be used to name the target file on the command line. If this clause is not present, a prompt is displayed for the file name. The file must already exist.

 

Use of TO DATA causes the query processor to create a dynamic array containing the output and placing this in the @DATA variable. Each "record" in this array is separated by an item mark character (char 255) and the fields within the item correspond to the display clause elements in the REFORMAT command.

 

When used with breakpoints, data from the detail and total lines is directed to the output file but the grand total is omitted.

 

 

Example

 

REFORMAT CUSTOMERS ZIP.CODE CUST.NO NAME TO CUST.BY.ZIP

 

This command constructs a new file, CUST.BY.ZIP, keyed by zip code and containing two data fields, the customer number and name. Note that if two or more customers share the same zip code, the record will be overwritten by the second and subsequent items.