Generate Data Definition Language (QSQGNDDL) API


  Required Parameter Group:


  Optional Parameter Group 1:


  Default Public Authority: *USE

  Threadsafe: No

The Generate Data Definition Language (QSQGNDDL) API generates the SQL data definition language statements required to recreate a database object. The results are returned in the specified database source file member or source stream file.

Database physical files or logical files that were created using an interface other than SQL may be specified. For example, files created from DDS and the CRTPF or CRTLF commands may be specified. Even if the object was created using SQL, the Standards option may restrict what can be generated. In either of these cases:

If a database object was created using an SQL interface, the resulting SQL statements may be slightly different than the SQL statements that created the object originally. For example:

For more information, see the Severity level field within the SQLR0100 Format.

You can use the QSQGNDDL API with database objects only. DDM files (other than SQL aliases) are not supported. File overrides do not affect the specified object names. File overrides do affect the specified database source file names.


Authorities and Locks

Object Library Authority
*EXECUTE

Source File Library Authority
*EXECUTE

Object Authorities
*EXECUTE and *OBJOPR to the library, and *OBJOPR to the *FILE object for tables, views, constraints, and triggers.
*EXECUTE and *OBJOPR to the library, *OBJOPR to the *FILE object, and *OBJOPR to the base *FILE object for indexes.
*EXECUTE and *OBJOPR to the library, and either *OBJOPR to the *FILE object or QIBM_DB_SECADM function usage for masks and permissions.
*EXECUTE and *OBJOPR to the library, and *OBJOPR to the *FILE object for aliases.
*OBJOPR to the library for functions and procedures.
*EXECUTE and *OBJOPR to the library, and *OBJOPR to the *SQLUDT object for types.
*OBJOPR and either *READ or *EXECUTE to the *LIB object for schemas.
*EXECUTE and *OBJOPR to the library, and *USE to the *DTAARA object for sequences.
*EXECUTE and *OBJOPR to the library, and *OBJOPR to the *SRVPGM object for variables.
*EXECUTE and *OBJOPR to the library, and *OBJOPR to the *SQLXSR object for XSR objects.

Source File Authority
To add a member, *OBJOPR and *ADD.
To replace a member, *OBJOPR, *DLT, *ADD, and either *OBJMGT or *OBJALTER.

Source Stream File Authority
*W (if an existing stream file is specified)
*WX (to the parent directory if the specified stream file does not exist and is to be created)

Note: If a stream file path name is specified, *X authority is required for each directory in the path. Adopted authority is not used to access the stream file.

Object Lock
*SHRRD for *LIB objects.
*SHRNUP for *FILE objects (not including aliases). (See note below.)
*SHRRD to QSYS2/SYSFUNCS for functions.
*SHRRD to QSYS2/SYSPARMS for functions and procedures.
*SHRRD to QSYS2/SYSPROCS for procedures.
*SHRRD to QSYS2/SYSSEQOBJ for sequences.
*SHRRD to QSYS2/SYSTYPES for types.
*SHRRD to QSYS2/SYSTABLES for aliases.
*SHRRD to QSYS2/SYSVARS for global variables.

Note: If the object is a *FILE object, the lock is acquired only on the file definition and not the data. Applications that modify data can run concurrently with this API.

Source File Lock
*EXCLRD.

Required Parameter Group

Input template
INPUT;CHAR(*)

A structure that contains the input options used to generate DDL for the requested database object. For the format of this parameter, see SQLR0100 Format.

Length of input template
INPUT; BINARY(4)

A variable that contains the length of the input template. The length must be greater than zero and large enough to contain all the template fields up to and including the Header Option. The length must not be larger than 32767.

Input template format name
INPUT; CHAR(8)

The format of the input template being used. The possible value is:

For more information, see SQLR0100 Format.

Error code
I/O; CHAR(*)

The structure in which to return error information. For the format of the structure, see Error code parameter. If this parameter is omitted, diagnostic and escape messages are issued to the application.


Optional Parameter Group 1

Source stream file path name
INPUT; CHAR(*)

The source stream file name, specified as a path name, that contains the SQL statements generated by the API. This parameter is ignored unless the Database source file name field has a value of *STMF. This parameter is assumed to be represented in the coded character set identifier (CCSID) currently in effect for the job. If the CCSID of the job is 65535, this parameter is assumed to be represented in the default CCSID of the job.

If the length of the source stream file path name is -1, then this parameter is assumed to be a Qlg_Path_Name_T structure that contains a path name or a pointer to a path name. For more information on the Qlg_Path_Name_T structure, see Path name format.

If the source stream file does not exist, it will be created with the CCSID specified in the Source stream file CCSID field. When a source stream file is created, the default authority for the parent directory is used. Writing to the QSYS.LIB file system is not supported.

Length of source stream file path name
INPUT; BINARY(4)

The length of the source stream file path name in bytes. If the length is -1, the source stream file path name parameter is assumed to be a Qlg_Path_name_T structure. This value must be zero if no source stream file path name is specified.


SQLR0100 Format

The following table shows the format of the input template parameter for the SQLR0100 format. For detailed descriptions of the fields in the table, see Field Descriptions.



Field Descriptions

Activate row and column access control option. The activate row and column access control option specifies whether an ALTER TABLE to activate row and column access control should be generated when the object type is a TABLE. The valid values are:

If the Standards option is '2', activate row and column access control option ‘1’ is ignored.

The default is '1'.

Additional index option. The additional index option specifies whether additional CREATE INDEX statements will be generated for DDS-created keyed physical or logical files. The valid values are:

If the Standards option is '2', additional index option ‘1’ is not valid.

The default is '0'.

Comment option. The comment option specifies whether COMMENT ON SQL statements should be generated if a comment exists on the specified database object. If comments are not supported by the specified database object, the comment option is ignored. The valid values are:

If the Standards option is '2', comment option '1' is not valid.

Constraint option. The constraint option specifies whether constraints should be generated when the object type is a TABLE. The valid values are:

The default is '1'.

CCSID option. The CCSID option specifies whether the CCSID attribute should be generated for column definitions when the object type is a TABLE. The valid values are:

If the standards option is '0' and '0' is specified, the CCSID clause, FOR MIXED DATA, FOR SBCS DATA, or FOR BIT DATA is not generated for the column definition.

If the standards option is '1' and '0' is specified, FOR MIXED DATA, FOR SBCS DATA, or FOR BIT DATA is not generated for the column definition.

If the standards opttion is '2' the CCSID option is ignored.

The default is '1'.

Create or Replace option. The Create or Replace option specifies whether CREATE OR REPLACE should be generated for the specified database object on the CREATE statement. This option is ignored if the specified database object does not support CREATE OR REPLACE. The valid values are:

If the Standards option is '1' or '2', the CREATE OR REPLACE option is not valid.

Database object name. The name of the database object for which DDL will be generated. Either the SQL name or the system name may be specified. The name is case sensitive. If delimiters are required for the name to be valid, they must be specified. For example, a file with a name of "abc" must be specified with the surrounding quotes. A file with a name of ABC must be specified in upper case.

If the object type is a FUNCTION or PROCEDURE, this name must be the specific name of the function or procedure.

If TABLE or VIEW is specified for the object type, the object name may identify an alias. In this case, the object that the alias points to will be generated. A CREATE ALIAS statement will be generated only if ALIAS is specified for the object type.

Database object library name. The name of the library containing the object for which DDL will be generated. The name is case sensitive. If delimiters are required for the name to be valid, they must be specified. This name is ignored if the specified object type is SCHEMA. You can use these special values for the library name:

Database object type. The type of the database object or object attribute for which DDL is generated. You can use these special values for the object type:

Database source file name. The name of the source file that contains the SQL statements generated by the API. The name must be a valid system name. The name is case sensitive. If delimiters are required for the name to be valid, they must be specified. For example, a file with a name of "abc" must be specified with the surrounding quotes. A file with a name of ABC must be specified in upper case.

The record length of the specified source file must be greater than or equal to 92.

If you want to use a source stream file then use this special value for the database source file name:

Database source file library name. The name of the library containing the source file that contains the SQL statements generated by the API. The name must be a valid system name. The name is case sensitive. If delimiters are required for the name to be valid, they must be specified. You can use these special values for the library name:

Database source file member name. The name of the source file member that contains the SQL statements generated by the API. The name must be a valid system name. The name is case sensitive. If delimiters are required for the name to be valid, they must be specified. You can use these special values for the member name.

Date format. The date format used for date constants in a generated SQL CREATE TABLE statement. The date format may not apply to date constants that are in ISO, EUR, USA, or JIS format in a CREATE VIEW, CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE, CREATE MASK, or CREATE PERMISSION statement. The valid values are:

Date separator. The date separator used for date constants in a generated SQL CREATE TABLE statement. The date separator may not apply to date constants that are in ISO, EUR, USA, or JIS format in a CREATE VIEW, CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE, CREATE MASK, or CREATE PERMISSION statement. The date separator is only applicable if the date format is MDY, DMY, YMD, or JUL. The valid values are:

Decimal point. The decimal point used for numeric constants. The valid values are:

Drop option. The drop option specifies whether DROP (or ALTER) SQL statements should be generated prior to the CREATE statement to drop the specified object. The valid values are:

Header option. The header option specifies whether a header should be generated prior to the CREATE statement. The header consists of comments that describe the version, date and time, the relational database, and some of the options used to generate the SQL statements. The valid values are:

Index instead of view option. The index instead of view option specifies whether a CREATE INDEX or CREATE VIEW statement will be generated for a DDS-created keyed logical file. The valid values are:

If the Standards option is '2', index instead of view option ‘1’ is not valid.

The default is '0'.

Label option. The label option specifies whether LABEL ON SQL statements should be generated if a label exists on the specified database object. If labels are not supported by the specified database object, the label option is ignored. The valid values are:

If the Standards option is '1' or '2', label option '1' is not valid.

Mask and permission option. The mask and permission option specifies whether row permissions and column masks should be generated when the object type is a TABLE. The valid values are:

If the Standards option is '2', mask and permission option ‘1’ is ignored.

The default is '1'.

Message level. The severity level at which the messages are generated. If errors occur that have a severity level greater than this value, a message is generated in the output. The valid values are in the range 0 through 39 inclusive.

The message level must be less than or equal to the severity level.

Naming option. The naming convention used for qualified names in the generated SQL statements. The valid values are:

Obfuscate option. The obfuscate option specifies whether an obfuscated SQL statement should be returned for SQL functions, SQL procedures, or SQL triggers that were not created using obfuscated statements. This option is ignored if the standards option is not ‘0’. This option is also ignored if the object is not an SQL function, procedure, or trigger. This option is ignored if the object is already obfuscated. Setting Obfuscate option = 0 cannot be used as a means of obtaining the unobfuscated SQL statement for an obfuscated object. The valid values are:

The default is '0'.

Privileges option. The privileges option specifies whether GRANT SQL statements should be generated on the specified database object. If privileges are not supported by the specified database object, the privileges option is ignored. The valid values are:

To generate privileges for an external routine, the external routine must exist.

Only SQL privileges will be generated for the specified database object. Authorities acquired through a group user profile, authorization list, special authority (such as *ALLOBJ) or any authority granted through GRTOBJAUT that does not map directly to an SQL privilege are not generated.

Qualified name option. The qualified name option specifies whether qualified or unqualified names should be generated for the specified database object. The valid values are:

The default is '0'.

Replace option. The replace option for the database source file member or source stream file. The valid values are:

Reserved. A reserved field. It must contain hexadecimal zeroes.

Severity level. The severity level at which the operation fails. If errors occur that have a severity level greater than this value, the operation ends. The valid values are in the range 0 through 39 inclusive. Any severity 40 error will cause the API to fail.

Source stream file CCSID. If a source stream file is specified and the source stream file does not exist, it will be created with this CCSID value. If a source stream file is specified and the source stream file already exists, this value will not be used. A value of 0 can be specified to indicate that the default job CCSID is to be used. A CCSID of 65535 cannot be specified.

The default is 0.

Source stream file end of line. The end of line character(s) which will be appended to the end of each line within the source stream file. The carriage return character is always X'0D'. Based on the CCSID of the source stream file, the line feed character is X'25' for an EBCDIC CCSID and X'0A' for ASCII and UTF-8 CCSIDs. The valid values are:

The default is CRLF.

Standards option. The standards option specifies whether the generated SQL statements should contain DB2 for i extensions or whether the statements should conform to the DB2 family SQL or to the ANS and ISO SQL standards. The valid values are:

If option 1 or 2 is chosen, the SQL statements generated may not completely represent the object in DB2 for i; however, the statements will be compatible with the specified DB2 Family or ANSI and ISO standards option.

If the object is an SQL function, SQL procedure, SQL trigger, or SQL view, the SQL statements in the body of the object are included in the generated SQL statement. Hence, if the option 1 or 2 is chosen, the generated SQL statement may not conform to the specified standards option since the statements within the body of the SQL object may not conform to the specified standard. For example, if a CREATE INDEX statement exists in the body of an SQL procedure, the generated CREATE PROCEDURE statement will contain the CREATE INDEX statement even if option 1 or 2 is chosen.

There is no attempt to take product specific limits into account. For example, a table name in DB2 for i can be 128 bytes, but other products may not support table names that are that long. Thus, even if the generated SQL statement is standard, it still may not work on other products if they have smaller limits than those on DB2 for i.

If option 1 is specified,

If option 2 is specified,

Statement formatting option. The formatting option used in the generated SQL statements. The valid values are:

System name option. The system name option specifies whether a RENAME statement should be generated for the system name when it is different from the SQL name and the object type is an INDEX, TABLE, or VIEW. The valid values are:

If the Standards option is '1' or '2', system name option '1' is not valid. The default is '0'.

Temporal option. The temporal option specifies whether an ALTER TABLE to add versioning should be generated when the object type is a TABLE and the table is a temporal table. The valid values are:

If the object is not a temporal table or if the Standards option is '2', temporal options '1' and '2' are ignored.

The default is '0'.

Time format. The format used for time constants in a generated SQL CREATE TABLE statement. The time format may not apply to time constants that are in ISO, EUR, USA, or JIS format in a CREATE VIEW, CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE, CREATE MASK, or CREATE PERMISSION statement. in the generated SQL statements. The valid values are:


Time separator. The time separator used for time constants in a generated SQL CREATE TABLE statement. The time separator may not apply to time constants that are in ISO, EUR, USA, or JIS format in a CREATE VIEW, CREATE TRIGGER, CREATE FUNCTION, CREATE PROCEDURE, CREATE MASK, or CREATE PERMISSION statement. The time separator is only applicable if the time format is HMS. in the generated SQL statements. The valid values are:


Trigger option. The trigger option specifies whether triggers should be generated when the object type is a TABLE or VIEW. The valid values are:

The default is '1'.

Usage Notes

If the value of the statement formatting option is 0, the generated SQL statements will be minimally formatted by adding blanks. For example:

CREATE TABLE mjatst.table_one (
  column_one INTEGER,
  column_two INTEGER,
  column_three CHAR(4000));

If the value of the statement formatting option is 1, the generated SQL statements will be formatted by inserting end-of-line characters, tab characters, and spaces. For example:

CREATE TABLE mjatst.table_one (
        column_one INTEGER,
        column_two INTEGER,
        column_three CHAR(4000));

Error Messages



API introduced: V5R1

[ Back to top | Database and File APIs | APIs by category ]