Copy SQL Database

From MidrangeWiki
Jump to: navigation, search

The following CL program can be used to automatically copy a SQL database from one library to another.

This program requires V5R4 or higher.

/*  Copy SQL database to a new library on a single system.                 */
/*                                                                         */
/*  Copyright 2010 David Gibbs (david@midrange.com)                        */
/*                                                                         */
/*  This program is licensed under the Creative Commons Attribution        */
/*  3.0 Unported license  http://creativecommons.org/licenses/by-sa/3.0/   */

PGM        PARM(&FROMLIB &TOLIB)

DCL        VAR(&FROMLIB) TYPE(*CHAR) LEN(10)
DCL        VAR(&TOLIB) TYPE(*CHAR) LEN(10)

DCL        VAR(&QSHCMD) TYPE(*CHAR) LEN(80)

CRTSAVF    FILE(QTEMP/CPYSQLDB)
MONMSG     MSGID(CPF0000)

CLRSAVF    FILE(QTEMP/CPYSQLDB)

SAVLIB     LIB(&FROMLIB) DEV(*SAVF) SAVF(QTEMP/CPYSQLDB) +
             TGTRLS(*CURRENT) ACCPTH(*YES)

CHGVAR     VAR(&QSHCMD) VALUE('db2 "CREATE SCHEMA ' || &TOLIB |< +
             '"')

QSH        CMD(&QSHCMD)

CRTDTAARA  DTAARA(&TOLIB/QDFTJRN) TYPE(*CHAR) LEN(40) +
             VALUE('XXXXXXXXXXQSQJRN    *ALL      *RSTOVRJRN')

CHGDTAARA  DTAARA(&TOLIB/QDFTJRN (1 10)) VALUE(&TOLIB)

RSTLIB     SAVLIB(&FROMLIB) DEV(*SAVF) SAVF(QTEMP/CPYSQLDB) +
             OPTION(*NEW) ALWOBJDIF(*OWNER) RSTLIB(&TOLIB)
MONMSG     MSGID(CPF3773)

DLTF       FILE(QTEMP/CPYSQLDB)

endpgm
 
 

This program is based on an article written by Kent Milligan for Developerworks.