Difference between revisions of "Sql convert from dds"
(Added an example) |
|||
Line 4: | Line 4: | ||
− | SQL described tables | + | SQL-described tables offer more functionality than DDS-described files. |
How to convert from DDS to SQL without breaking existing programs... | How to convert from DDS to SQL without breaking existing programs... |
Latest revision as of 20:32, 8 March 2016
WORK IN PROGRESS - please help by editing this document - include code/specific commands where needed
SQL-described tables offer more functionality than DDS-described files.
How to convert from DDS to SQL without breaking existing programs...
Big picture...create a new SQL table to hold the data, build indexes across this new table, rebuild the physical file DDS as a logical file, change the logicals to point at new physical.
- Retrieve the SQL for your physical table using API or iNavigator.
- change the name of the table to match your company standards
- for example, physical file MSPMP100, new SQL name MSPMP100SQ
- use old format name for new table
- change the name of the table to match your company standards
- Retrieve list of key fields used across the file
- Build indexes using longest number of key fields to shortest
- Rebuild the physical file DDS to be a logical file
- Change the logical files to point to new physical
- if logical uses select/omit change to use dynslt
- include a index across select/omit fields
- Compile all logical files (including the "old physical")
Stored Procedure GENERATE_SQL()
Beginning with Release 7.1 TR8 (and Release 7.2) the GENERATE_SQL()stored procedure is integrated in the QSYS2 schema. This procedure allows DDS sources to be converted into SQL and stored either as stream file or in a source physical file member. Detailed Information can be found under the following Link: QSYS2.GENERATE_SQL() procedure
It has two modes of operations. It can write SQL to a source member or return it as a recordset, which creates a source member in QTEMP behind the scenes. Here is an example usage of common parameters:
CALL QSYS2.GENERATE_SQL( 'TABLEPF', 'BARLIB', 'TABLE', -- We want to script out the object TABLEPF from schema (libary) BAR of type table (physical file) -- 'QSQLSRC', 'BAR', 'TABLEPF', -- Uncoment to write this to a source member instead of outputing as a resultset STATEMENT_FORMATTING_OPTION => 0, -- Setting to 1 will cause SEU's syntax highlighting to be confused. REPLACE_OPTION => 1, -- Set to 0 to append to the source member as opposed to overwriting it. CREATE_OR_REPLACE_OPTION => 1, -- If the system supports CREATE OR REPLACE syntax on this object, generate it. CONSTRAINT_OPTION => 1, -- Script out constraints DROP_OPTION => 1, -- Precede the CREATE statement with a DROP DDL statement. NAMING_OPTION => 'SQL', QUALIFIED_NAME_OPTION => 0 -- Set to 1 to fully qualify all objects in the generated DDL );
It should be noted that you may use the % wildcard in the object and library parameter to generate DDL for multiple objects. However, you will need to set the REPLACE_OPTION parameter to 0 in that case or you will only get the last object generated. Also, the source member you intend to write to must exist.
Troubleshooting
If QSYS2.GENERATE_SQL() returns an error, its usually not helpful. However the joblog generates helpful messages. You can retrieve the joblog via the usual greenscreen methods or select * from table(qsys2.joblog_info('*')) a.
Categories
This article is a stub. You can help by editing it.