Problem solve Get help with specific problems with your technologies, process and projects.

Disable all constraints in a library

Here's a program to 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.


Dig Deeper on iSeries CL programming

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

Close