Skip to main content

 
IBM Power Systems software  >  IBM i  > Software  > 

IBM DB2 for i

  

DB2 Example: Application simulation before Referential Integrity

*========================================================*
      * This program is intended to illustrate a program       *
      * that prior to using a referential integrity            *
      * RESTRICT rule verified that an employee added to the   *
      * EMPLOYEE file was assigned to a valid department.      *
      *                                                        *
      * This program will only work of files that do not       *
      * contain null values. If a field contains null values,  *
      * SQL must be used to update the file.                   *
      *                                                        *
      *                                                        *
      * CRTBNDRPG PGM(CORPDATA/RI02) SRCFILE(MJASRC/RPG)       *
      *           DBGVIEW(*SOURCE) ALWNULL(*YES)               *
      *                                                        *
      * ADDPFCST FILE(CORPDATA/DEPARTMENT)                     *
      *          TYPE(*PRIKEY) KEY(DEPTNO)                     *
      *                                                        *
      * ADDPFCST FILE(CORPDATA/EMPLOYEE)                       *
      *          TYPE(*REFCST) KEY(WORKDEPT)                   *
      *          CST(VERIFY_WORKDEPT)                          *
      *          PRNFILE(CORPDATA/DEPARTMENT) PRNKEY(DEPTNO)   *
      *          DLTRULE(*RESTRICT) UPDRULE(*RESTRICT)         *
      *                                                        *
      *                                                        *
      *========================================================*
      *
      *========================================================*
      * File definition used for insert.                       *
      *========================================================*
     FEMPDSP    CF   E             WORKSTN
     FEMPLOYEE  O    E           K DISK    RENAME(EMPLOYEE:EMPFMT)
      *========================================================*
      * File definition used to check for an existing          *
      * departement.                                           *
      *========================================================*
     FDEPARTMENTIF   E           K DISK    RENAME(DEPARTMENT:DEPT)
      *
      *========================================================*
      * Get a new employee record from the display.            *
      * Loop until the department is valid.                    *
      *========================================================*
     C                   MOVE      *ON           *IN61
     C                   DOW       *IN61
     C                   EXFMT     A
      *========================================================*
      * Check to see if a department for the employee exists   *
      * If it does not, return a message to the screen.        *
      *========================================================*
     C     WORKDEPT      CHAIN     DEPT                               6161
     C     *IN61         IFEQ      *ON
     C                   MOVE      *ON           *IN60
     C                   ELSE
     C                   MOVE      *OFF          *IN60
      *========================================================*
      * Write to the EMPOLOYEE file.                           *
      *========================================================*
     C                   WRITE     EMPFMT                               61
     C                   ENDIF
     C                   ENDDO
      *
     C                   RETURN