CDS064

Define File

Last Revised: 01/30/17

CDS064 is used to define data files and folders.  It is typically only needed for string files, as CDS034 should be used to define all data files, both permanent and temporary, that have been described in the Dynamo Tools Data Dictionary.  See CDS002 to erase and re-define an existing data file.

When passed certain characteristics about the file to be defined, the routine will:

  1. Optionally determine the number of records to be in the file based on the number of records in some other file (not needed anymore now that most files are dynamic).
  2. Optionally determine an unused name for the file.
  3. Define the file.
  4. Open the file.

Note that files defined in a tmp directory (including /tmp/, ./tmp/, and tmp/) will be erased upon return to the menu.  This is done so that temporary work files do not need to be erased by the application program.  You can disable the option to delete files defined in tmp upon return to the menu by adding a "p" to the front of the TYPE$ field.  If you have other "temporary" files that you do not want automatically erased, then define them in the TEMP/ directory.  We also typically run the cleartmp routine using cron that deletes files in tmp/ each night that are more than one day old.

Calling Format:

CALL "CDS064", ERR=NNNN, Y$, CHAN, DISCNO, KEYSIZE, RECS, RECSIZE, TYPE$, FILNAM$, DISPMSG$, AUXFIL$

CDS064
NNNN the line label/number to branch to if unable to define file.
Possible Errors
Error#Description
2 or 15Insufficient disc space
12File name specified already exists, or unable to define folders
17Invalid KEYSIZE, TYPE$, or key structure
18User does not have write permissions in directory where file is to be defined
Y$ the standard terminal control variable
CHAN the channel number to which the file should be opened.  If passed with a value of zero, then CDS064 will call CDS088 to obtain an available channel and return that channel number to the calling program.
DISCNO Disc Number - obsolete, was used on Basic Four computers where disc drives were referred to by number and fileset.
KEYSIZE Number of characters in key for files of type SKY, DIR, and SRT.
RECS Number of records in file.  Normally passed as zero to create file without limit.
RECSIZE Characters per record.  Applies to files of type MKY, SKY, DIR, and IND.
TYPE$ The type of file to be defined.  There are three components to TYPE$.  Note that all files defined by CDS064 are in the 'highly recoverable' format.
TYPE$ Prefix (in any sequence)
pUse a TYPE$ Prefix of lower case "p" to disable erasing of the temporary file upon return to the menu.  Note that this option is implied for files defined in a tmp folder with an extension that begins with the characters PDF, htm, txt, xls, or xml.  See example and note above regarding temporary files.
LUse a TYPE$ Prefix of upper case "L" to define a large file, i.e., a file that can expand in size to over 2Gb.
TypeObsolete single character typeFile Type
MKYMMulti-Keyed Mkeyed file (followed by key definition parameters S187.KEYDEF$ or FIN().
MKX Multi-Keyed Xkeyed file (followed by key definition parameters S187.KEYDEF$ or FIN() not XFIN().
MKJ Multi-Keyed Jkeyed file (followed by key definition parameters S187.KEYDEF$ or FIN() not XFIN().
MKV Multi-Keyed Vkeyed file (followed by key definition parameters S187.KEYDEF$ or FIN() not XFIN().
SKYKSingle Keyed Mkeyed file (maximum file size 2Gb)
SKX Single Keyed Xkeyed file (bbj only)
SKJ Single Keyed Jkeyed file (bbj only)
SKV Single Keyed Vkeyed file (bbj only)
DIRDDirect file
SRTSSort file
INDIIndexed file
SERPSerial (print) file
PGMGProgram file
STRTString file
DRYRDirectory
FTS Full Text Search (bbj only). Note that a Data Dictionary Entry is required to define a Full Text Search File. The primary key must be the first data element in the record.
TYPE$ Suffix
The Suffix is required for all Multi-Keyed files, and contains the key definition information.  For existing files, the key definition from S187.KEYDEF$ can be used.  To define a new file, use CDS034 instead of CDS064 which will create the key definition from the Dynamo Tools Data Dictionary.  The key definition field is based on the FIN() format for MKY files as well as bbj specific file types MKX, MKJ, and MKV.
FILNAM$ The name of the file to be defined.  FILNAM$ can optionally include a data server prefix, a drive letter followed by a colon, folder, base file name, and extension.  FILNAM$ will be returned to the calling program with the actual file name defined.  Leading and trailing blanks are removed from FILNAM$.  Note that any of the following characters in FILNAM$: blank, <, >, |, *, ? and non-printable characters are replaced with a hyphen.
Data Server Prefix
To define a file on another server, include the data server prefix in the format /<servername, service & options>
Drive Letter
For Windows file systems, the drive letter followed by a colon can be used.
Folder (Directory)
If one or more folders are included in FILNAM$, then the folders will be automatically defined if they do not exist. This permits passing a complete file path to CDS064 without needing to define the parent directories.
If no Folder is provided, and the file type is PG5, or the file type is PGM and running pro5 or Vpro5, and the folder XX/pg5/ exists, where XX is the first two characters of the Base File Name, then the program will be defined in the XX/pg5/ folder.
If no Folder is provided, and the file type is PG6, or the file type is PGM and running bbj, and the folder XX/pg6/ exists, where XX is the first two characters of the Base File Name, then the program will be defined in the XX/pg6/ folder.

If no Folder is provided, and the file type is PGM, and folder XX/PGM/ exists, where XX is the first two characters of the Base File Name, then the program will be defined in the XX/PGM/ folder.

If no Folder is provided, and the file type is not PGx or EPx, and folder XX/dat/ exists, where XX is the first two characters of the Base File Name, then the data file will be defined in the XX/dat/ folder.
If no Folder is provided, and the first two characters of the Base File Name exist as a folder, such as DS/, and then the file will be defined in the DS/ folder.
If no Folder is provided, or the Folder is "./tmp/" or "tmp/" then the file will be defined in the folder below SMSDIR, such as /u/CDI/tmp/, /usr/CDI/tmp/, etc. and not below the current directory.
Base File Name
If no Base File Name is provided, then one is derived using the active company code and application or program name, such as DS-SO480.
If the Base File Name begins with XX then XX will be replaced by the current company code.
If the Base File Name  does not contain a comma, period, nor slash, then if defining a program and folder XX/PGM/ exists, the program will be defined in the XX/PGM folder, otherwise if the XX/ folder exists, the file will be defined in the XX/ folder. 
If the Base File Name ends with a period, or contains a comma before the extension, then CDS064 will derive a unique file name and append a -NNN suffix to the Base File Name.  If there are many files in the same folder with the same Base File Name, then the number of digits in the suffix will be increased as necessary to create a unique file.  The suffix is randomly assigned to eliminate the need to sequentially check many file names before determining an unused file name.
Extension
A file name Extension is used if FILNAM$ contains a period or a comma, followed by an Extension, i.e., SO230.pdf, or SO230,pdf.  See FILNAM$ examples below.
DISPMSG$ This parameter is obsolete and is not used.  On older systems where it took the system from several seconds to several minutes to define and initialize a large data file, this field was used to override the standard display message while the file was being defined.
AUXFIL$ This parameter is not needed much anymore with the advent of dynamic files.  AUXFIL$ is used when you want the define the file FILNAM$ based on the number of records that are in use in file AUXFIL$.  When AUXFIL$ is used, the number of records defined in the new file will be the number of records in use in the AUXFIL$ file, plus a percentage specified in RECS.  For example, to define a file with 10% more records than are in use in AUXFIL$, pass RECS as 10.
Examples
  1. Define a single-keyed MKEYED file with a keysize of 14, with 180 records, and 64 bytes per record, using the file name DSFD32, and open the file to device 7.
    CALL "CDS064",Y$,7,0,14,180,64,"SKY","DSFD32"
  2. Create the same file as above but instead of 180 records, define the file with the same number of records that are in file DSFD10.
    CALL "CDS064",Y$,7,0,14,0,64,"SKY","DSFD32","","DSFD10"
  3. The previous example would define file DSFD32 to have the number of active records in file DSFD10 (assuming DSFD10 is a keyed file). This means that if file DSFD10 is defined to have 1000 records, but only 650 are currently in use, then file DSFD32 will be defined as only 650 records. To create a file with 10% more than the number of defined records pass the RECS parameter the percentage.
    CALL "CDS064",Y$,7,0,14,10,64,"SKY","DSFD32","","DSFD10"
  4. Define a Sort file, which will be used to sort a customer file, DSUD10 which requires a key size of 12. The number of records should be the same as the number of active records in the customer file.  Let CDS064 determine the channel number and file name.

    CALL "CDS064",Y$,WRK,0,12,0,0,"SRT",WRKFIL$,"","DSUD10"

  5. Define a string file named TEST in the WORK directory.

    CALL "CDS064",Y$,CHAN,0,0,0,0,"STR","WORK/TEST"

  6. Define a string file named TEST in the tmp directory.  File will be erased upon return to menu.

    CALL "CDS064",Y$,CHAN,0,0,0,0,"STR","tmp/TEST"

  7. Define a string file named TEST in the tmp directory.  File will not be erased upon return to menu.

    CALL "CDS064",Y$,CHAN,0,0,0,0,"pSTR","tmp/TEST"

  8. Define a large Single Keyed file.

    CALL "CDS064",Y$,CHAN,0,4,0,128,"LSKY","DS/DSQA01"

Examples of FILNAM$
Passed to CDS064 Example of returned Value
"" ./tmp/DS-SO480
/u/CDI/tmp/DS-SO480
/<server,port=1100>/u/CDI/tmp/DS-SO480
",txt" ./tmp/DS-SO480-123.txt
",html" ./tmp/DS/SO480-123.htm
"DSSO40" DS/DSSO40
"DSU010" with TYPE$="PGM" DS/PGM/DSU010
"DS/DSSO40" DS/DSSO40
"TEMP/,txt" TEMP/DS-SO480-123.txt
"TEST." ./tmp/TEST-123
"PRT/" PRT/DS-SO480
"PRT/." PRT/DS-SO480-123
"PRT/.txt" PRT/DS-SO480.txt
"DY/SO480" DY/SO480