Skip to main content

 
IBM Power Systems software  >  IBM i  > Software  > 

IBM DB2 for i

  

DB2 Example: Change Remote Journal State
ILE RPG source


 H********************************************************************
    H* This program accepts input from a CMD to Change Journal State.
    H* /COPY is used to reduce the size of the source.  Appropriate
    H*  parts of the includes can also be copied directly to this source
    H*  member.
    H*
    H* This program only supports changing the journal state of local
    H*  journals on the source system and remote journals from the
    H*  source system.  Inactivation of a remote journal from the
    H*  target system is not coded in this example. This is primarily
    H*  due to the fact that this would make the command more confusing
    H*  if this support were added here.  Format CJST0200 is required
    H*  to inactivate a remote journal from a target system.
    H*
    H* CHGJRNSTT command uses selective prompting so that only applicable
    H*  parameters are shown.
    H*
    H********************************************************************
    H* Compile options
    H*
    HDFTACTGRP(*NO) ACTGRP(*CALLER)
    D********************************************************************
    D* Includes for Journal APIs
    D*
    D/COPY QSYSINC/QRPGLESRC,QJOURNAL
    D********************************************************************
    D*
    D********************************************************************
    D* Error code parameter include. Bytes available is set to 0 in *INZSR
    D*  which causes program to function check if any errors are
    D*  encountered. Error handling can be added to this program by
    D*  changing the bytes available parameter to 16, or greater than 16.
    D*  Changing this value without adding any error handling to the
    D*  program will cause the program to appear to complete normally
    D*  even when an error has occured, other than messages logged to
    D*  the joblog.
    D/COPY QSYSINC/QRPGLESRC,QUSEC
    D********************************************************************
    D*
    D********************************************************************
    D* Includes for Retrieve Object Description API
    D*   Used when *LIBL or *CURLIB is used for Journal Name and *JRN
    D*   is used for Remote Journal Name
    D*
    D/COPY QSYSINC/QRPGLESRC,QUSROBJD
    D********************************************************************
    D*
    D********************************************************************
    D* Standalone fields
    D*
    D REQVARLEN       S              9B 0
    D*                                Length of request variable
    D RCVVARLEN       S              9B 0
    D*                                Length of receiver variable
    D REQFMTNAM       S              8A
    D*                                Request format name
    D SNDTSKPRI       S              9B 0
    D*                                Sending task priority
    DJRNOBJTYP        S             10A   INZ('*JRN')
    D*                                Object type of journal
    D********************************************************************
    C********************************************************************
    C* Main Line
    C*
    C     LCLRMT        CASEQ     'L'           LCLJRN
    C*                                            Local Journal
    C     LCLRMT        CASEQ     'R'           RMTJRN
    C*                                            Remote Journal
    C                   ENDCS
    C                   MOVE      *ON           *INLR
    C* End of Main Line
    C********************************************************************
    C********************************************************************
    C* Program Initialization Subroutine
    C*
    C     *INZSR        BEGSR
    C     *ENTRY        PLIST
    C                   PARM                    STATUS            1
    C*                                           New Journal State
    C*                                           I = Inactive
    C*                                           A = Active
    C                   PARM                    LCLRMT            1
    C*                                           Local or Remote
    C*                                           L = Local
    C*                                           R = Remote
    C                   PARM                    JRNNAME          20
    C*                                           Journal Name
    C                   PARM                    RDBDIRE          18
    C*                                           Remote Relational DB
    C*                                             Directory Entry
    C                   PARM                    RMTJRNAME        20
    C*                                           Remote Journal Name
    C                   PARM                    STRJRNRCV        20
    C*                                           Starting Journal Rcvr
    C                   PARM                    PRFINACTYP        1
    C*                                           Preferred Inactive type
    C*                                           C = Controlled
    C*                                           I = Immediate
    C                   PARM                    SYNASY            1
    C*                                           Synch or Asynchronous
    C*                                           S = Synchronous
    C*                                           A = Asynchronous
    C                   PARM                    SNDTSKPRI
    C*                                           Sending task priority
    C*                                            1 = Highest
    C*                                           99 = Lowest
    C*                                            0 = System will choose
    C                   EVAL      QUSBPRV = 0
    C*                              See comments in D specs for
    C*                               error code parameter.
    C*
    C********************************************************************
    C* Check to see if *JRN specified for remote journal.  If so, check to
    C*  see if *LIBL or *CURLIB is specified for local journal name.  If
    C*  so, use Retrieve Object Description API to find local journal and
    C*  change *LIBL or *CURLIB to library name where the journal was
    C*  found.  This is necessary because the API requires a library
    C*  name for the remote journal and does not support *LIBL or *CURLIB
    C*
    C     RMTJRNAME     IFEQ      '*JRN'
    C     '*LIBL'       SCAN      JRNNAME       SCANRESULT        2 0    90
    C     *IN90         IFNE      *ON
    C     '*CURLIB'     SCAN      JRNNAME       SCANRESULT               90
    C                   ENDIF
    C     *IN90         IFEQ      *ON
    C                   EXSR      RTVLIB
    C                   ENDIF
    C                   ENDIF
    C********************************************************************
    C* End program initialization subroutine
    C                   ENDSR
    C********************************************************************
    C* Local Journal Subroutine
    C*
    C     LCLJRN        BEGSR
    C                   EVAL      REQVARLEN = %SIZE(QJO0100R00)
    C                   EVAL      REQFMTNAM = 'CJST0100'
    C                   EVAL      RCVVARLEN = 0
    C     STATUS        IFEQ      'I'
    C*                        Status = Inactive
    C                   EVAL      QJONJS    = '0'
    C                   ENDIF
    C     STATUS        IFEQ      'A'
    C*                        Status = Active
    C                   EVAL      QJONJS    = '1'
    C                   ENDIF
    C                   CALLB     QJOCJS
    C                   PARM                    JRNNAME
    C                   PARM                    QJO0100R00
    C                   PARM                    REQVARLEN
    C                   PARM                    REQFMTNAM
    C                   PARM                    QJO0100R00
    C                   PARM                    RCVVARLEN
    C                   PARM                    QUSEC
    C                   ENDSR
    C********************************************************************
    C* Remote Journal Subroutine
    C*
    C     RMTJRN        BEGSR
    C     STATUS        CASEQ     'I'           RMTINACT
    C*                        Status = Inactive
    C     STATUS        CASEQ     'A'           ACTRMTJRN
    C*                        Status = Active
    C                   ENDCS
    C                   ENDSR
    C********************************************************************
    C* Inactivate Remote Journal Subroutine
    C*
    C*   This is the only call to the QjoChangeJournalState API that
    C*    provides a receiver variable. The use of this receiver is
    C*    not demonstrated in this example, but would be used to
    C*    record information about the inactivation, such as receiver
    C*    name and sequence number which could be used when restarting
    C*    remote journaling.
    C*
    C     RMTINACT      BEGSR
    C                   EVAL      REQVARLEN = %SIZE(QJO0300R)
    C                   EVAL      REQFMTNAM = 'CJST0300'
    C                   EVAL      RCVVARLEN = %SIZE(QJO0300R00)
    C                   EVAL      QJORDBDE  = RDBDIRE
    C     RMTJRNAME     IFEQ      '*JRN'
    C                   EVAL      QJORJ     = JRNNAME
    C*              If RMTJRNNAME = *JRN, set QJORJ = local journal name.
    C*               Otherwise, set to name passed.
    C                   ELSE
    C                   EVAL      QJORJ     = RMTJRNAME
    C                   ENDIF
    C     PRFINACTYP    IFEQ      'C'
    C                   EVAL      QJOPIT    = '0'
    C*                         Preferred Inactive Type Controlled
    C                   ENDIF
    C     PRFINACTYP    IFEQ      'I'
    C                   EVAL      QJOPIT    = '1'
    C*                         Preferred Inactive Type Immediate
    C                   ENDIF
    C                   CALLB     QJOCJS
    C                   PARM                    JRNNAME
    C                   PARM                    QJO0300R
    C                   PARM                    REQVARLEN
    C                   PARM                    REQFMTNAM
    C                   PARM                    QJO0300R00
    C                   PARM                    RCVVARLEN
    C                   PARM                    QUSEC
    C                   ENDSR
    C********************************************************************
    C* Activate Remote Journal Subroutine
    C*
    C     ACTRMTJRN     BEGSR
    C     SYNASY        CASEQ     'S'           ACTRMTSYN
    C*                         Synchronous Maintained Remote Journal
    C     SYNASY        CASEQ     'A'           ACTRMTASY
    C*                         Asynchronous Maintained Remote Journal
    C                   ENDCS
    C                   ENDSR
    C********************************************************************
    C* Activate Remote Journal Synchronously Subroutine
    C*
    C     ACTRMTSYN     BEGSR
    C                   EVAL      REQVARLEN  = %SIZE(QJO0400R)
    C                   EVAL      REQFMTNAM  = 'CJST0400'
    C                   EVAL      RCVVARLEN  = 0
    C                   EVAL      QJORDBDE01 = RDBDIRE
    C     RMTJRNAME     IFEQ      '*JRN'
    C                   EVAL      QJORJ01   = JRNNAME
    C*              If RMTJRNNAME = *JRN, set QJORJ01 = local journal name.
    C*               Otherwise, set to name passed.
    C                   ELSE
    C                   EVAL      QJORJ01    = RMTJRNAME
    C                   ENDIF
    C                   EVAL      QJOSJR     = STRJRNRCV
    C                   CALLB     QJOCJS
    C                   PARM                    JRNNAME
    C                   PARM                    QJO0400R
    C                   PARM                    REQVARLEN
    C                   PARM                    REQFMTNAM
    C                   PARM                    QJO0400R
    C                   PARM                    RCVVARLEN
    C                   PARM                    QUSEC
    C                   ENDSR
    C********************************************************************
    C* Activate Remote Journal Asynchronously Subroutine
    C*
    C     ACTRMTASY     BEGSR
    C                   EVAL      REQVARLEN  = %SIZE(QJO0500R)
    C                   EVAL      REQFMTNAM  = 'CJST0500'
    C                   EVAL      RCVVARLEN  = 0
    C                   EVAL      QJORDBDE02 = RDBDIRE
    C     RMTJRNAME     IFEQ      '*JRN'
    C                   EVAL      QJORJ02   = JRNNAME
    C*              If RMTJRNNAME = *JRN, set QJORJ02 = local journal name.
    C*               Otherwise, set to name passed.
    C                   ELSE
    C                   EVAL      QJORJ02    = RMTJRNAME
    C                   ENDIF
    C                   EVAL      QJOSJR00   = STRJRNRCV
    C                   EVAL      QJOSTP     = SNDTSKPRI
    C                   CALLB     QJOCJS
    C                   PARM                    JRNNAME
    C                   PARM                    QJO0500R
    C                   PARM                    REQVARLEN
    C                   PARM                    REQFMTNAM
    C                   PARM                    QJO0500R
    C                   PARM                    RCVVARLEN
    C                   PARM                    QUSEC
    C                   ENDSR
    C********************************************************************
    C* This subroutine is called when *LIBL or *CURLIB is specified for
    C*   the journal name, and *JRN is specified for the remote journal
    C*   name.  The Retrieve Object Description API is used to find the
    C*   local journal by the library list or current library, and then
    C*   return the name of the library where the local journal was found.
    C*   The returned library is moved to the last 10 positions of the
    C*   JRNNAME field.  This enables other subroutines that deal with
    C*   *JRN to find a library name
    C*
    C     RTVLIB        BEGSR
    C                   EVAL      RCVVARLEN = %SIZE(QUSD0100)
    C                   EVAL      REQFMTNAM  = 'OBJD0100'
    C                   CALL      QUSROBJD
    C                   PARM                    QUSD0100
    C                   PARM                    RCVVARLEN
    C                   PARM                    REQFMTNAM
    C                   PARM                    JRNNAME
    C                   PARM                    JRNOBJTYP
    C                   PARM                    QUSEC
    C                   MOVE      QUSRL01       JRNNAME
    C                   ENDSR