Defining CSV Files

Defining CSV files using workdef provides the capability to have your applications write data directly to a CSV file, eliminating the need for the end user to extract data from the print (.prt) file using lashow. Once you have defined CSV files using workdef, use the CSV routines to read from and write to the files. For more information, see Application Program Interfaces.

When you set the CSV file options using the following procedure, you are actually defining a work file options record (WRKFLOPTS). The program uses these options whenever it executes, unless the user overrides the options using jobdef. In that case, a job step work file options record (JOBSTEPWRK) is defined, and the program uses those options for only that one execution of the program.

You can also define a CSV file without setting any options. In this case, workdef uses values from your Locale record as the default. Whenever the program executes, it uses the values in the Locale record of the user who started the program.

To set the attributes of the CSV file

  1. Press Define (F6) and choose Define File Attributes. The CSV Workfile Attribute Definition form displays.

    Many of the fields in the CSV Workfile Attribute Definition form are especially useful when reading an existing CSV file. Because of the varying nature of CSV files, it is important to have flexibility in specifying the file attributes as needed.

  2. Type parameters in the CSV Workfile Attribute Definition form as follows:
    In this field Type or Select (F4)
    External Name The external name (for work file storage) of this CSV file. For more information on using this field, see Defining External Names for CSV Files.
    Usage Output, Input, or Input/Output, to specify whether the file is write-only, read-only, or both.
    File Header

    Off (no file header) or On (file header) to specify whether a file header containing field names should be written to the CSV file or, if the file is being read, if the header exists.

    If the header exists, the system assumes it is in a mixed-case format without spaces or dashes (for example, Company Nbr, not COMPANY-NBR). When writing a CSV file with a header, this format is also used.

    Xlt Header Names Off or On to specify whether to translate header names. If you are writing to a file and you choose On, it translates the header names as specified in the user's Locale record.
    Field Separator

    The symbol separating fields in the file. Valid entries are comma (,), Tab, Space, and None (fixed-length field format). For more information on fixed-length fields, see Defining a CSV File in Fixed-Length Field Format.

    If you select Custom Char, type the desired character in the Custom FldSep Char field.

    Custom FldSep Char The symbol separating fields in the file.
    Date Format

    The date format to use in any date fields that might be included in the file. Valid entries are:

    ccyymmdd - Date in century, year, month, day order.

    mmddccyy - Date in month, day, century, year order.

    ddmmccyy - Date in day, month, century, year order.

    yymmdd - Date in year, month, day order.

    mmddyy - Date in month, day, year order.

    ddmmyy - Date in day, month, year order.

    Date Separator The symbol separating month, day, and year formats. If you type a space, dates are compressed (a space is not used as a separator) and date fields are not enclosed with quote characters.
    Time Separator The symbol separating hours and minutes in any time formats that might be included in the file.
    Decimal Separator The symbol separating the parts of a number that has decimal places.
    Thousands Sep The symbol separating the thousands place from the hundreds, and so on.
    Quote Character The symbol to use for delimiting strings.
    Line Terminator The code that denotes the end of each line in the file. Valid entries are cr, nl, and hex 0D0A.
    File Terminator The code that denotes the end of the file. Valid entries are None and hex 1A.