ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Interractive RPG jobs

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Interractive RPG jobs

    Commitment control STRCMTCTL ENDCMTCTL

    Hello,

    I would like to know if it's possible to use COMMIT or ROLL BACK or some other functions for interactive RPG job to reverse all files back to initial values if interactive job was terminated by the user by closing the window session.

    Thanks.

  • #2
    Galina (i think I know you)

    Okay here goes... (I attached the code as text docs)

    I am not an expert here but this is what I have

    here is my physical file
    Code:
         A          R FILE1R
         A*
         A            F1FLD1        10          COLHDG('Field One')
         A            F1FLD2        10          COLHDG('Field Two')
         A*
         A          K F1FLD1
    Okay now the CL program the start the whole mess

    Code:
                PGM
                 DCL        VAR(&ERROR) TYPE(*CHAR) LEN(1)
                 MONMSG     MSGID(CPF0000)
                 CRTJRNRCV  JRNRCV(QGPL/JRNFILE1)
                 CRTJRN     JRN(QGPL/JRNFILE1) JRNRCV(QGPL/JRNFILE1)
                 STRJRNPF   FILE(FILE1) JRN(QGPL/JRNFILE1) IMAGES(*BOTH)
                 STRCMTCTL  LCKLVL(*ALL)
    
                 CALL       PGM(COMMITR) PARM(&ERROR)
                 IF         COND(&ERROR *EQ 'Y') THEN(DO)
                  ROLLBACK
                  GOTO EXIT
                 ENDDO
    
                 COMMIT
    
      EXIT:      ENDCMTCTL
    
                 ENDPGM
    you only need create the journal and journal reciever once...
    but for this example it tries every time.


    Now the RPG....The error flag defaults to 'Y' meaning when
    you leave the RPG via F3 the records written to file FILE1 will be ROLLEDBACK meaning removed from the file.

    Code:
         fCOMMITD   cf   e             workstn
         fFILE1     uf a e           k disk    commit
         f                                     usropn
    
         d DisplayScrn1    S               n   inz('1')
         d CmdString       S            256
         d CmdLength       S             15  5
         d OutError        S             01
          *
         c                   open      FILE1
          *
         c                   eval      S1ERROR = 'Y'
          *
         c                   dow       DisplayScrn1 = *On
          *
         c                   exfmt     SCRN1
         c                   select
         c                   when      *in03
         c
         c                   eval      DisplayScrn1 = *Off
         c                   other
         c                   eval      F1FLD1 = S1FLD1
         c                   eval      F1FLD2 = S1FLD2
         c                   write     FILE1R
         c                   clear                   S1FLD1
         c                   clear                   S1FLD2
         c                   endsl
          *
         c                   enddo
          *
         c                   eval      OutError = S1ERROR
         c                   eval      *Inlr = *On
          *-----------------------------------------------                      ***
          *   *Inzsr - One time run auto subroutine
          *-----------------------------------------------                      ***
         c     *INZSR        begsr
         c     *entry        plist
         c                   parm                    OutError
         c                   endsr


    So write three or so records...Leave the display up(do not press F3)

    open a second session and use DBU/DFU/WRKDBF/QUERY...
    to check the file....You will see your records.
    Now F3 Outta the program and the records will be removed.

    Call the CL again this time change error flag to 'N'
    records will be written then commited in the CL.


    Hope this helps

    Jamie
    Attached Files
    All my answers were extracted from the "Big Dummy's Guide to the As400"
    and I take no responsibility for any of them.

    www.code400.com

    Comment


    • #3
      Thanks.

      Thanks Jamie.

      I'm going to try this. I hope it will work.

      Galina.

      Comment


      • #4
        Re: Thanks.

        STRPFJRN commit rollback commitment control

        just wanted to refresh this and add the link to the code definitions of the journals.



        jamie
        All my answers were extracted from the "Big Dummy's Guide to the As400"
        and I take no responsibility for any of them.

        www.code400.com

        Comment


        • #5
          Re: Interractive RPG jobs

          Ok, I'm all new to journals... what do they do? How does it work?

          Comment


          • #6
            Re: Interractive RPG jobs

            Thats what this entire thread tells you.
            Your gonna have to create some more "stuff" above and give it a test

            then decide which is the better tool for what you are doing.
            All my answers were extracted from the "Big Dummy's Guide to the As400"
            and I take no responsibility for any of them.

            www.code400.com

            Comment


            • #7
              Re: Interractive RPG jobs

              Just a side note to the above there are also rpg opcodes
              commit and rolbk

              Using them in an RPG program instead of cl will allow an entire transaction set (multiple files) to be written or not without the need to return to the cl calling program. This may be particularly useful in the event of a power outtage.

              Hope this helps someone
              GLS
              The problem with quotes on the internet is that it is hard to verify their authenticity.....Abraham Lincoln

              Comment

              Working...
              X