Generate Data Definition Language (QSQGNDDL) API


  Required Parameter Group:

1 Input template Input Char(*)
2 Length of input template Input Binary(4)
3 Input template format name Input Char(8)
4 Error code I/O Char(*)

  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.

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 source file names.


Authorities and Locks

Object Library Authority
*EXECUTE

Source File Library Authority
*EXECUTE

Object Authorities
*EXECUTE for *LIB objects.
*USE for the *DTADCT object in a library (if SCHEMA is specified for the object type).
*USE for *FILE objects (not including aliases).
*USE to QSYS2/SYSPARMS for functions and procedures.
*USE to QSYS2/SYSROUTINE for functions and procedures.
*USE to QSYS2/SYSTYPES for types.
*USE to QSYS2/SYSTABLES for aliases.

Source File Authority
*OPER and *ADD.
If replace is specified, *DLT and either *OBJMGT or *OBJALTER is required also.

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/SYSTYPES for types.
*SHRRD to QSYS2/SYSTABLES for aliases.

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:

SQLR0100 Basic template

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.


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.

Offset Type Field
Dec Hex
0 0 CHAR(258) Database object name
258 102 CHAR(258) Database object library name
516 204 CHAR(10) Database object type
526 20E CHAR(10) Database source file name
536 218 CHAR(10) Database source file library name
546 222 CHAR(10) Database source file member name
556 22C BINARY(4) Severity level
560 230 CHAR(1) Replace option
561 231 CHAR(1) Statement formatting option
562 232 CHAR(3) Date format
565 235 CHAR(1) Date separator
566 236 CHAR(3) Time format
569 239 CHAR(1) Time separator
570 23A CHAR(3) Naming option
573 23D CHAR(1) Decimal point
574 23E CHAR(1) Standards option
575 23F CHAR(1) Drop option
576 240 BINARY(4) Message level
580 244 CHAR(1) Comment option
581 245 CHAR(1) Label option
582 246 CHAR(1) Header option
Start of change583 247 CHAR(1) Trigger optionEnd of change
Start of change584 248 CHAR(1) Constraint optionEnd of change
Start of change585 249 CHAR(1) System name optionEnd of change
586 250 CHAR(*) Reserved


Field Descriptions

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:

0 COMMENT ON SQL statements should not be generated.
1 COMMENT ON SQL statements should be generated. If the specified database object type is a table or view, COMMENT ON SQL statements will also be generated for columns of the table or view.

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

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

0 Constraints should not be generated.
1 Constraints should be generated.

The default is '1'.End of change

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:

*CURLIB The job's current library
*LIBL The library list

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:

ALIAS The object is an SQL alias.
If the Standards option is '2', an ALIAS object type is not valid.
CONSTRAINT The object attribute is a constraint.
FUNCTION The object is an SQL function.
INDEX The object is an SQL index.
If the Standards option is '2', an INDEX object type is not valid.
PROCEDURE The object is an SQL procedure.
SCHEMA The object is an SQL schema (collection) or library.
TABLE The object is an SQL table or physical file.
TRIGGER The object attribute is a trigger.
TYPE The object is an SQL type.
VIEW The object is an SQL view or logical file.

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.

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:

*CURLIB The job's current library
*LIBL The library list

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.

*FIRST The first database physical file member found.
*LAST The last database physical file member found.

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, or CREATE PROCEDURE statement. The valid values are:

ISO International Standards Organization (yyyy-mm-dd)

EUR IBM European Standard (dd.mm.yyyy)
If the Standards option is '2', the EUR date format is not valid.
JIS Japanese Industrial standard Christian Era (yyyy-mm-dd)
If the Standards option is '2', the JIS date format is not valid.
USA IBM USA standard (mm/dd/yyyy)
If the Standards option is '2', the USA date format is not valid.
MDY Month/day/year (mm/dd/yy)
If the Standards option is '1' or '2', the MDY date format is not valid.
DMY Day/month/year (dd/mm/yy)
If the Standards option is '1' or '2', the DMY date format is not valid.
YMD Year/month/day (yy/mm/dd)
If the Standards option is '1' or '2', the YMD date format is not valid.
JUL Julian (yy/ddd)
If the Standards option is '1' or '2', the JUL date format is not valid.

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, or CREATE PROCEDURE statement. The date separator is only applicable if the date format is MDY, DMY, YMD, or JUL. The valid values are:

/ Slash separator
. Period separator
, Comma separator
- Dash separator
blank Blank separator

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

. Period separator
, Comma separator
If the Standards option is '1' or '2', the comma separator is not valid.

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:

0 DROP statements should not be generated.
1 DROP statements should be generated.

Note that with the exception of DROP SCHEMA, the DROP statements generated will not include a CASCADE or RESTRICT option even if the standards option is '2'.

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:

0 A header should not be generated.
1 A header should be generated.

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:

0 LABEL ON SQL statements should not be generated.
1 LABEL ON SQL statements should be generated. If the specified database object type is a table or view, LABEL ON SQL statements will also be generated for columns of the table or view.

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

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:

SQL collection.table syntax
SYS library/file syntax

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

If the object type is a FUNCTION, PROCEDURE, TRIGGER, or VIEW, and a column name is qualified by a qualified table name in the SQL body of the function, procedure, trigger, or view (that is, schema-name.table-name.column-name), the generated statement will not be valid because this type of column name qualification is not allowed in SYS naming.

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

0 The resulting SQL statements are appended to the end of the database source file member.
1 The database source file member is cleared prior to adding the resulting SQL statements. If this option is chosen, the file may be cleared even if an error is returned from the API.

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.

0 No errors or warnings.
10 The following attributes will result in messages with this severity level:
  • Schema ASP and WITH DATA DICTIONARY

    If the Standards option is 1 or 2, these clauses will be ignored.

  • Test libraries

    A CREATE SCHEMA statement will be generated to create the schema. Schemas are production libraries.

  • Libraries with a CRTAUT parameter value

    Under SQL naming, schemas are always created with CRTAUT(*EXCLUDE). Under SYS naming, schemas are always created with CRTAUT(*SYSVAL).

  • NODEGROUPs

    If the Standards option is 1 or 2, the NODEGROUP clause will beignored.

  • LABEL ON TEXT

    If the Standards option is 1, the text will be ignored.

  • COMMENT ON parameters

    If the Standards option is 1, the comment will be ignored.

  • System file names

    If the Standards option is 1 or 2, only the SQL names are generated. Otherwise, a RENAME statement is generated after the CREATE statement to assign the system name.

  • System column names

    If the Standards option is 1 or 2, only the SQL names are generated. Otherwise, a FOR COLUMN clause will be generated to assign each system column name.

  • BIGINT data types

    If the Standards option is 1 or 2, a DECIMAL(19,0) will be generated.

  • DBCS-open data types

    If the Standards option is 1 or 2, a character field will be generated.

    • Binary with non-zero scale

      A decimal data type will be generated.

    • Files whose format name is different from the file name

      The format name will be the same as the file name.

    • Files with a REUSEDLT(*NO) attribute

      REUSEDLT(*YES) will be used.

    • Physical or logical files that use any of the following keywords: CHECK, CHKMSGID, CMP, DATFMT, EDTCDE, EDTWRD, TIMFMT, RANGE, REFSHIFT, VALUES

      These keywords will be ignored.

    • Logical files that use any of the following keywords: CCSID or TRNTBL

      These keywords will be ignored.

    • Join logical files with JDFTVAL or JDUPSEQ

      A LEFT OUTER JOIN clause will be generated, but the join default value will be the null value and the JDUPSEQ keyword will be ignored.

    • Logical files with SST function

      If the Standards option is 2, SUBSTRING is generated instead of SUBSTR.

    • COBOLLE and C++ languages in external functions and procedures

      If the Standards option is 1 or 2, COBOL or C is generated.

    • RPGLE language in external functions and procedures

      If the Standards option is 1, RPG is generated.


20 The following attributes will result in messages with this severity level:
  • Multiple member files, files with no members, or files with MAXMBRS greater than one

    The resulting file will contain one member.

  • Single format logical files with a member built over multiple physical file members

    The resulting file will be based on the first physical file member.

  • Logical files that contain input/output fields that map an underlying physical file field to a different data type, length, precision or scale.

    A CAST scalar function will be generated to map the data to the correct attributes, but the resulting column is input-only.

  • Keyed logical files that do not share the based on physical file's format, have more than one based on file, or have select/omit specifications

    If INDEX is specified, the format and select/omit will be ignored.

  • Triggers with MODE DB2ROW

    If the Standards option is 1 or 2, MODE DB2SQL will be used.

30 The following attributes will result in messages with this severity level:
  • CHAR or VARCHAR CCSID 65535

    If the Standards option is 2, a character field is generated.

  • GRAPHIC, VARGRAPHIC, or DBCLOB

    If the Standards option is 2, a character field is generated.

  • DataLinks or Row IDs

    If the Standards option is 1 or 2, a character field is generated.

  • Identity columns

    If the Standards option is 2, the IDENTITY attribute is ignored.

  • Open, Only, or Either fields

    If the Standards option is 0, the CCSID clause will result in an open field. Only and Either fields will result in a warning. If the Standards option is 1, FOR MIXED DATA is generated. If the Standards option is 2, character fields will be generated.

  • Keyed logical files

    If VIEW is specified, the key specifications will be ignored, because all views are non-keyed.

  • Keyed physical files whose key is not a primary key

    A CREATE TABLE will be generated without a primary key. The key specifications will be ignored, however, because only tables with a primary key are keyed.

  • Files that use any of the following keywords: ALTSEQ, DIGIT, FCFO, FIFO, LIFO, UNSIGNED, ZONE

    These keywords will be ignored.

  • SRTSEQ

    The sort sequence will be ignored.

  • Non-SQL triggers if TABLE object is specified.

    The triggers will be ignored.

  • NO EXTERNAL ACTION, SCRATCHPAD, FINAL CALL, ALLOW PARALLEL, or DBINFO, keywords in functions and procedures

    If the standards option is 2, these attributes will be ignored.

  • COMMIT ON RETURN YES, NOT FENCED, or NEW SAVEPOINT LEVEL clauses in functions and procedures

    If the standards option is 1 or 2, these attributes will be ignored.

  • Functions and procedures with parameter style GENERAL WITH NULLS, DB2SQL, or DB2GENERAL

    If the Standards option is 2, PARAMETER STYLE SQL is used.

  • JAVA, REXX, RPG, and RPGLE language in functions and procedures

    If the Standards option is 2, the C language is used instead.

  • CL language in functions and procedures

    If the Standards option is 1 or 2, the C language is used instead.

40 The following attributes will result in messages with this severity level:
  • Physical file if either VIEW or INDEX object type is specified.
  • Logical file if TABLE object type is specified.
  • Non-keyed file if INDEX object type is specified.
  • Non-alias file if ALIAS object type is specified.
  • Function if PROCEDURE object type is specified.
  • Procedure if FUNCTION object type is specified.
  • Device files
  • Program described physical files
  • Multiple format logical files
  • Indexes if the Standards option is 2.
  • Aliases if the Standards option is 2.
  • EVI Indexes if the Standards option is 1.
  • UNIQUE WHERE NOT NULL if the Standards option is 1.
  • Aliases that contain a member name if the Standards option is 1.
  • System-generated UDFs
  • Built-in data types
  • SQL UDFs, if the Standards option is 1.
  • Sourced UDFs, if the Standards option is 2.
  • User-defined table functions, if the Standards option is 2.
  • Non-SQL triggers if TRIGGER object is specified.

Standards option. The standards option specifies whether the generated SQL statements should contain DB2 UDB for iSeries extensions or whether the statements should conform to the DB2 Universal Database Family SQL or to the ANS and ISO SQL standards. The valid values are:

0 DB2 Universal Database for iSeries extensions may be generated in SQL statements.
1 The generated SQL statements must conform to SQL statements common to the DB2 Universal Database Family.
2 The generated SQL statements must conform to the following ANSI and ISO SQL standards:
  • ISO (International Standards Organization) 9075-1: 1999, Database Language SQL
  • ANSI (American National Standards Institute) X3.135-1-1999, Database Language SQL

If option 1 or 2 is chosen, the SQL statements generated may not completely represent the object in DB2 UDB for iSeries; 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 UDB for iSeries 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 that those on DB2 Universal Database for iSeries.

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:

0 No additional formatting characters are added to the generated SQL statements.
1 Additional end-of-line characters and tab characters are added to the generated SQL statements.

Start of changeSystem 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:

0 A RENAME statement should not be generated.
1 A RENAME statement should be generated.

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

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

ISO International Standards Organization (hh.mm.ss)
EUR IBM European Standard (hh.mm.ss)
If the Standards option is '2', the EUR time format is not valid.
JIS Japanese Industrial standard Christian Era (hh:mm:ss)
If the Standards option is '2', the JIS time format is not valid.
USA IBM USA standard (hh:mm AM, hh:mm PM)
If the Standards option is '2', the USA time format is not valid.
HMS Hour/minute/second (hh:mm:ss)
If the Standards option is '1' or '2', the HMS time format is not valid.

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

: Colon separator
. Period separator
, Comma separator
blank Blank separator

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

0 Triggers should not be generated.
1 Triggers should be generated.

The default is '1'.End of change

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

Message ID Error Message Text
CPF24B4 E Severe error while addressing parameter list.
CPF3C21 E Format name &1 is not valid.
CPF3C23 Object &1 is not a file of the correct type.
CPF3C26 File &1 has no members.
CPF3C39 E Value for reserved field not valid.
CPF3C3A E Value for parameter &2 for API &1 not valid.
CPF3C90 E Literal value cannot be changed.
CPF3CF1 E Error code parameter not valid.
CPF8100 E All CPF81xx messages could be returned. xx is from 01 to FF.
CPF9800 E All CPF98xx messages could be signaled. xx is from 01 to FF.
SQL0113 Name &1 not allowed.
SQL7001 File &1 in &2 not database file.
SQL7003 File &1 in &2 has more than one format.
SQL7011 &1 in &2 not table, view, or physical file.
SQL7039 QSQGNDDL API input template field values not compatible.
SQL7040 Message severity &1 exceeds specified severity level &2.
SQL7041 &1 in &2 not valid for object type &3.
SQL7042 Value not valid for QSQGNDDL API input template.
SQL7043 System-generated function or built-in data type &1 in &2 not allowed.
SQL7044 &3 not supported by the standards option for &1 in &2.
SQL7045 Function &1 in &2 not allowed.
SQL7046 Generate SQL for &1 in &2 object type &3 failed.
SQL7047 System trigger &1 in &2 not allowed.


API introduced: V5R1
Top | Database and File APIs | APIs by category