Given a starting customer table definition, you must have already performed a -sqlize or otherwise embedded the XDD definition for the table. -sqlinfo custmast.xdd can also be used if you do not require the table to be available in SQL:
ctutil -make customer custmast.xdd
cutil -sqlize customer custmast.xdd ctreeSQL
custmad.xdd
<?xml version="1.0" encoding="US-ASCII"?>
<table name="CUSTMAST-FILE" minRecLen="4" maxRecLen="1024">
<key duplicate="false">
<segment offset="0" size="4"/>
<part name="CM_CUSTNUMB" offset="0" size="4"/>
</key>
<schema name="CUSTMAST-FILE" size="157">
<field name="CM_CUSTNUMB" size="4" type="Alphanum" digits="4" scale="0"/>
<field name="CM_CUSTZIPC" size="9" type="Alphanum" digits="9" scale="0"/>
<field name="CM_CUSTSTAT" size="2" type="Alphanum" digits="2" scale="0"/>
<field name="CM_CUSTRTNG" size="1" type="Alphanum" digits="1" scale="0"/>
<field name="CM_CUSTNAME" size="47" type="Alphanum" digits="47" scale="0"/>
<field name="CM_CUSTADDR" size="47" type="Alphanum" digits="47" scale="0"/>
<field name="CM_CUSTCITY" size="47" type="Alphanum" digits="47" scale="0"/>
</schema>
</table>
A new “country” field is desired and added to the existing custmast definition.
custmast2.xdd
<?xml version="1.0" encoding="US-ASCII"?>
<table name="CUSTMAST-FILE" minRecLen="4" maxRecLen="1071">
<key duplicate="false">
<segment offset="0" size="4"/>
<part name="CM_CUSTNUMB" offset="0" size="4"/>
</key>
<schema name="CUSTMAST-FILE" size="204">
<field name="CM_CUSTNUMB" size="4" type="Alphanum" digits="4" scale="0"/>
<field name="CM_CUSTZIPC" size="9" type="Alphanum" digits="9" scale="0"/>
<field name="CM_CUSTSTAT" size="2" type="Alphanum" digits="2" scale="0"/>
<field name="CM_CUSTRTNG" size="1" type="Alphanum" digits="1" scale="0"/>
<field name="CM_CUSTNAME" size="47" type="Alphanum" digits="47" scale="0"/>
<field name="CM_CUSTADDR" size="47" type="Alphanum" digits="47" scale="0"/>
<field name="CM_CUSTCITY" size="47" type="Alphanum" digits="47" scale="0"/>
<field name="CM_CUSTCTRY" size="47" type="Alphanum" digits="47" scale="0" defaultvalue="USA"/>
</schema>
</table>
A “defaultvalue” attribute is required for all altered fields, as default field content must be provided:
ctutil -alter customer custmast2.xdd -hot
A default value is defined with a <field default=""/> attribute. Its value can be specified in multiple formats depending on field content requirements:
To specify a character string that starts with a backslash, prepend it with another backslash: <field default="\\000"/>
The new record lengths are updated and reported after a successful alter:
ctutil -info customer
Version 4.0.3.169-240601 - Micro Focus COBOL and ExtFH Edition
Initialized from 'ctree.conf'
Record length : 4 bytes
Variable : yes
Max length : 1071 bytes
Operation completed successfully.
Note: You must re-sqlize the table after an alter for changes to be reflected in the SQL system tables:
ctutil -sqlize customer custmast2.xdd ctreeSQL
Review your changes after updating your table with ctutil:
./ctutil -sqlinfo altertest
Version 4.0.3.169-240601 - Micro Focus COBOL and ExtFH Edition
Initialized from 'ctree.conf'
<?xml version="1.0" encoding="US-ASCII"?>
<table minRecLen="4" maxRecLen="1071">
<key duplicate="false" primary="true">
<segment offset="0" size="4" type="String"/>
</key>
<schema >
<field name="CM_CUSTNUMB" size="4" type="Alphanum" digits="4" scale="0" />
<field name="CM_CUSTZIPC" size="9" type="Alphanum" digits="9" scale="0" />
<field name="CM_CUSTSTAT" size="2" type="Alphanum" digits="2" scale="0" />
<field name="CM_CUSTRTNG" size="1" type="Alphanum" digits="1" scale="0" />
<field name="CM_CUSTNAME" size="47" type="Alphanum" digits="47" scale="0" />
<field name="CM_CUSTADDR" size="47" type="Alphanum" digits="47" scale="0" />
<field name="CM_CUSTCITY" size="47" type="Alphanum" digits="47" scale="0" />
<field name="CM_CUSTCTRY" size="47" type="Alphanum" digits="47" scale="0" bindefault="\6VVNBICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICA=" />
</schema>
</table>
The default value defined by “defaultvalue” is reported as a base64 encoded value:
ISQL> table altertest;
COLNAME NULL ? TYPE LENGTH CHARSET NAME COLLATION
------- ------ ---- ------ ------------ ---------
cm_custnumb NOT NULL CHAR 4
cm_custzipc NOT NULL CHAR 9
cm_custstat NOT NULL CHAR 2
cm_custrtng NOT NULL CHAR 1
cm_custname NOT NULL CHAR 47
cm_custaddr NOT NULL CHAR 47
cm_custcity NOT NULL CHAR 47
cm_custctry CHAR 47