CDS034

Define / Convert File

Last Revised: 12/27/16

This called routine will define or convert a file based on information contained in the Data Dictionary and define or replace the .tpl template file.  The Data Dictionary is maintained using the Data Dictionary Maintenance on the FMS menu.

CDS034 provides the following functions:

Defines permanent data files in the XX/ directory (or other directory specified) if the data file does not exist.

Defines or replaces the template file in the XX/tpl/ directory (or in tpl directory below data file) for permanent data files if the data file does not exist.

Defines temporary data files in the $SMSDIR/tmp directory using a unique file name and placing the template in global memory for use by applications.

Takes no action and exits quietly if the data dictionary field structure (including mask and title fields) is the same as the .tpl template file, and the data dictionary key structure matches that of the existing data file.

Analyzes the differences between the data dictionary and current file, returns these differences to calling program, and converts the file (when necessary) to match the data dictionary.

When file conversion takes place, CDS034 optionally archives the original file with the standard .YYMMDD suffix when S034.MODE$ is passed as "Y".

Can convert files of one type to another, i.e., DIR to SKY or MKY, SKY to MKY.

Optionally performs analysis but does not perform any conversion.

Field conversion includes: adding fields, deleting fields, changing the number of elements in an array, changing the field type, i.e., U(3) to B, or N(7) to C(7), etc.

When file conversion is required, the converted data file will reside in the same directory as the original, even if in an alternate directory such as in XX/DAT/ instead of just in XX/.

Warning: In most cases you should not simply CALL "CDS034" from console mode.  It is much better to use the File Utility 'Compare to Data Dictionary' option, since it will give you a chance to review the changes to be made before deciding to convert.  The File Utility archives both the original file and template file so that you can restore the archived copies when necessary.
Warning: CDS034 assumes that the data in the original file matches the template.  If there is ever any uncertainty, then run the File Utility option 'Verify Data to Template' before converting the file.

Calling Format:

Call "CDS034", ERR=XXXX, FILNAM$, { S034$ }

CDS034
ERR=XXXX

Error 11 returned if unable to locate the data dictionary entry for FILNAM$

Error 99 returned for most other issues including invalid file name, operator abort due to field mapping problem, etc.

FILNAM$ There are three options for the file name.
Process Single FileSingle File Name (must be more than two characters long)
OptionExample
Data Dictionary Name (excluding company code)CM01
Base File NameDSCM01
Base File Name with XX as company codeXXCM01
Relative Path NameDS/data/DSCM01
Fully Qualified/u/CDI/DS/data/DSCM01
Fully Qualified with Data Server/<server>/usr2/QP/DATA/QPITEMS

CDS034 requires the data dictionary to determine the file structure. The company code for the data dictionary is derived from the first two characters of the base file name, or the current company code.

Process all files for a company codeTwo character company code, with optional path to company directoryProcess all records in the data dictionary, ignoring all data dictionary entries for programs and temporary work files (file name ends with a period).  Examples: "XX", "DS", "TEST/DS".
Process all data dictionary files for a company codeCompany Code followed by "DD", with optional path to company directoryRevise the structure of the data dictionary files to match the master copies from company CD, then update the contents of the data dictionary reflecting any changes to the data dictionary files.  The Data Dictionary files all begin with DD, so applications should not names files that begin with DD, since other dictionary files may be added in the future.  Examples: "XXDD", "DSDD", "TEST/DS/DSDD".
S034$ This optional parameter may be passed as a literal, or as a variable with or without the template assigned.  See examples.
MODE$inC(1)
"N"Converts file (if necessary), and erases original data file (if it exists).
"Y"Converts file (if necessary), and archives original data file and template with a .YYMMDDX suffix.
blankConverts file (if necessary), and archives original data file only if fields are deleted.
"T"Tests to determine if file conversion is required and returns conversion data in other fields within S034$, but does not define or convert the file nor define or replace the template file.  Valid only when passing a single file name in FILNAM$.
LINEinN(2)If passed as non-zero, then the progress messages will be displayed at this display row, and will be incremented for each file processed. If zero, or not passed, then progress messages will display at the bottom of the display, and cleared when file definition/conversion is complete.
CCinC(2)Company Code for Data Dictionary - optional
DDNAMEinC(10)Data Dictionary File Name - optional
PREFPATHinC(40*)Preferred Path and File Name - optional
ARCFILNAM$outC(15*)Set to the file name that the original data file was archived as when S034.MODE$="Y"
STATUS$outC(15*)Returns information about differences between data dictionary and existing file.  These status fields are concatenated together into S034.STATUS$.  This field only applies when CDS034 is called with a single file name.  STATUS$ will be null when the file exists and no changes are required. See the next field for additional details.
FField changes, + indicates field added, - indicates field deleted, c indicates field changed, i.e., F-3+2c4 means that 3 fields will be deleted. 2 added, and 4 changed.  The deleted fields always appear first so that an application can test for the POS("F-"=S034.STATUS) to know if any fields will be deleted.
KKey changes.  For MKY files, the format is the same as for Field Changes described above.  For SKY files K simply indicates a change in keysize.
RR indicates a change in record size.
Tnindicates n changes in the user defined template title field.
Mnindicates n changes in the user defined template omask field.
Uindicates the file and/or .tpl template file is undefined.
Eindicates that CDS034 encountered an error trying to open the data file, .tpl template file, or access the data dictionary.
Yindicates a change in file type, i.e, DIR to SKY.
Pindicates that no fields have changed type or size, but the fields are not in the same position within the record.
MAXDETAILoutN(2*)Contains the length of the longest entry in S034.DETAILS field below.
DETAILS$outC(50*=0)A complete list of details related to the differences between the data dictionary and the existing file.  There are line feeds ($0A$) between each comment line.  This field only applies when CDS034 is called with a single file name.

Sometimes the template field type is changed.  For example, an N(2) field could be converted to a U(2) field, or an N(10*) field could be converted to a B type field.  CDS034 will attempt to convert all field types, even C type fields to a numeric when possible.  CDS034 will display an error message and abort a file conversion should a field conversion not be possible, or the data does not match the template.

We recommend that you avoid N type fields, especially when they are used in key segments.  BBx left justifies N type fields and is not consistent as shown in the example below.  Another reason to avoid N type fields in key segments is that the BBx SELECT optimization logic used to choose the best KNUM for the file, and to do a position READ within the file only works with C type fields.

BBx N type field issues Note
>DIM REC$:"NO:N(6)"
>?REC.NO$
000000
BBx zero fills N type fields upon a DIM.
>REC.NO=0
>?REC.NO$
0
BBx does not zero fill on a simple assignment.  This can cause problems if the field is used in a key segment.
>REC.NO=15
>?REC.NO$
15
BBx left justifies N type fields within the field.
>REC.NO$=STR(15:"######")
>?"'",REC.NO$,"'"
'   15'
You can right justify N type fields by using STR() but then you have to be careful that every program does it.

Special Field Conversion Notes

Current
Field
Type
New Field
Type
Notes
C N File conversion will abort if you cannot take NUM() of string field.  When new field type is a fixed length such as N(2) not N(2*), and is the same length as the current field type, i.e., C(2), the field will be converted as a string instead of a numeric, so that a field containing " 5" will remain " 5" and not "5 ".  This is especially important when the field is used as a key segment.
N C This field conversion is similar to the C to N conversion described above, in that CDS034 will copy the field as a string retaining any leading spaces in the string version of the original field, when the new field type is a fixed length, and the field sizes are the same.
U C CDS034 converts the U type field to its numeric value, then pads the value with leading spaces, so that a U(2) field with a value of 10, will become "  10" if converted to a C(4) or C(4*) field.  If the field sizes are the same, and you simply want a U(3) field to be copied as a string to a C(3) field, then you should edit the .tpl file, and not use CDS034.
C U This will work properly if the current field simply contains numbers, but if the C type field contains binary data, as a U type field does, then CDS034 will abort with an error message should it be unable to take the NUM() of the current C field.

Examples:

This example will compare the current file structure to that in the data dictionary and return the details in S034$.  No file conversion will take place.  Note that the File Utility (SMU) 'Compare to Data Dictionary' also performs this step and displays the results in a scrolling window.

Test only, no data conversion example
READY
>S034$="T"
>CALL "CDS034","DSVM01",S034$
>?S034.STATUS$
RKc1F+2-27c3T36
>?S034.DETAILS$
Status Codes: RKc1F-2+27c3T36
Change record size from 512 to 472
Change KNUM 2 from FOREIGN+ZIP(1,5)+ALPHASORT+VENDNO
to FOREIGN+ZIP[2](1,5)+ALPHASORT+VENDNO
Deleting FS1
Deleting FS3
Deleting FS5
Deleting UNUSED_F6
Deleting UNUSED_F7
Deleting UNUSED_F8
Deleting UNUSED_F9
Deleting UNUSED_F10
Deleting FS10
Deleting UNUSED_F28
Deleting FS11
Deleting UNUSED_F12
Deleting UNUSED_F13
Deleting UNUSED_F14
Deleting UNUSED_F15
Deleting UNUSED_F16
Deleting UNUSED_F17
Deleting UNUSED_F18
Deleting UNUSED_F19
Deleting UNUSED_F20
Deleting UNUSED_F21
Deleting UNUSED_F22
Deleting UNUSED_F23
Deleting UNUSED_F24
Deleting UNUSED_F25
Deleting UNUSED_F26
Deleting UNUSED_F27
Set title on VENDNO to Vendor#
Change NAME from C(30*) to C(30)
Set title on NAME to Name
Set title on ADDR1 to Address_#1
Set title on ADDR2 to Address_#2
Change ZIP from C(10) to [3]:C(10)
Set title on ALPHASORT to Alpha_Sort
Set title on PHONE to Telephone#
Set title on ALTPHONE to Alt_Phone#
Set title on BUYER to Buyer
Set title on ADDR_VERIFY_DATE to PO_Chg_Date
Set title on CARRIER_ROUTE to Carrier_rt
Change CONTACTS from C(1*) to C(1)
Set title on CONTACTS to Contacts...
Set title on CHK_ADDR1 to Check_Addr1
Set title on CHK_ADDR2 to Check_Addr2
Set title on LOCATION to G/L_Loc'n
Set title on TYPE to Vendor_Type
Set title on MASTERVENDNO to Master_Vnd#
Adding GL_LOC
Set title on SHIPVIA to Ship_Code
Set title on TERMS_CODE to Unused
Set title on TERMSCODE to Terms_Code
Set title on TEN99TYPE to 1099_Info
Set title on TIN to TIN/SSNO
Set title on UNUSED to G/L_Acct#
Set title on PMTCYCLECODE to PmtCycleCod
Set title on HOLD to Hold
Set title on PMTMETH to Pmt_Method
Adding BRANCHACCESS
Set title on TAXABLE to Taxable
Set title on FOB_POINT to F.O.B._Pt
Set title on FREIGHT_CODE to Freight_Cd
Set title on WGHT_MIN_ORD to WghtMin_Ord
Set title on WGHT_MIN_FRT to Weight_Frt
Set title on AMT_MIN_ORD to Amt_Min_Ord
Set title on AMT_MIN_FRT to Amt_Min_Frt
Set title on VOL_MIN_ORD to Vol_Min_Ord
Set title on VOL_MIN_FRT to Vol_Min_Frt
Set title on UNUSED_F11 to Unused
Set title on CUSTNO to Customer#
Define/Revise single file
CALL "CDS034","DSCM01"

Defines file DS/DSCM01 if it did not exist in any prefix.  If it does exist, the data structure including field names, field sizes, and key structure are compared to that contained in the Data Dictionary.  If a conversion is required, then the file and template will be converted to match the specification contained within the Data Dictionary.  If the file exists, it will remain in the same directory it was located in.  For example if the PFX includes PY/ PY/DAT and the file PY/DAT/PYUD10 exists, calling CDS034 with PYUD10 will convert this file and the converted file will remain in the PY/DAT directory.

Template files are typically created in a tpl directory immediately below the data file directory.  In this example, the template file should be PY/DAT/tpl/PYUD10.tpl.  Note that these template files are created by CDS034 and should not normally be edited or altered.  If the template is not found in the preferred location, the tpl directory under the company code is used, i.e., PY/tpl/PYUD10.tpl.  See CDS041 for additional information about templates.

Archive original file
S034$="Y"
CALL "CDS034","DSCM01",S034$
PRINT S034.ARCFILNAM$
DSCM01.041008
Check/Convert all files in company
CALL "CDS034","DS"

Checks each data file contained within the Data Dictionary for company DS, and defines or converts those required.