Disable all constraints in a library

When refreshing our development database with "live" production data, I always have to disable all the referential constraints before copying in the data. The following CL program makes that MUCH easier by changing the status on all constraints in the specified library to *DISABLED.

Before compiling the CLLE, create the data-file so that the compile will work. (Of course, substitute your library name for <mylib> .)

 
DSPFD FILE(<mylib>/*ALL) TYPE(*CST)
     OUTPUT(*OUTFILE) FILEATR(*PF) 
     OUTFILE(Qtemp/ALLCST)

It's a VERY easy modification to create the program to enable all the constraints.

  /***********************************************************/
/** Program: EnableIt                                     **/
/** Author:  Dave Ford                                    **/
/** Date:    2001/03/08                                   **/
/** Purpose: Disable all referential constraints and      **/
/**          check constraints on all physical tables in  **/
/**          the specified library                        **/
/***********************************************************/
PGM  PARM(&DBLIB)     
DCL VAR(&DBLIB) TYPE(*CHAR) LEN(10)
DCL VAR(&CNAME) TYPE(*CHAR) LEN(258)
DCLF FILE(Qtemp/ALLCST) ALWVARLEN(*YES)
DSPFD FILE(&DBLIB/*ALL) TYPE(*CST) + 
     OUTPUT(*OUTFILE) FILEATR(*PF) + 
     OUTFILE(Qtemp/ALLCST)
NEXT: RCVF
MONMSG MSGID(CPF0864) EXEC(GOTO CMDLBL(END))
CHGVAR VAR(&CNAME) VALUE(%SST(&PHCSTN 3 256))
CHGPFCST FILE(&DBLIB/&CSFILE) CST(&CNAME) + 
STATE(*DISABLED)
GOTO NEXT
END:         ENDPGM
  
  

==================================
MORE INFORMATION ON THIS TOPIC
==================================

The Best Web Links: tips, tutorials and more.

Ask your programming questions--or help out your peers by answering them--in our live discussion forums.

Ask the Experts yourself: Our application development gurus are waiting to answer your programming questions.


This was first published in April 2003

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.