ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

RPG Update operation and *in51 pointer

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

  • RPG Update operation and *in51 pointer

    Hello eveyboby,

    I have this problem:

    I must update a record of a table named DATA

    The update of the record could be made by more user at the same time.

    The code that I use is this:


    Code:
    §USRCD        Chain(n)  DATA
                              ++++++++++++++HiLoEq+++++
    	    Update    DATA            51                  
    	    if        *in51 = *on              
    	    Eval      WMSG = ErrCod            
    	    Endif
    My problem is that the UPDATE operation gives always "*in51 = *on" and the record is never updated. But shouldn't it give me "*in51 = *on" only if the update operation fails?

    Can someone give me help?

    Thankk you in advance!

  • #2
    Re: RPG Update operation and *in51 pointer

    You must remove the (n) in order to update the record
    PHP Code:
    §USRCD        Chain  DATA           51 (Hi)
    *
    In51           Ifeq    *Off
                       Update Data
                       
    Else
                       
    Wmsg Errcod
                       
    Endif 
    Bill
    "A good friend will bail you out of jail,
    A true friend would be sitting beside you saying,
    'Wow, that was fun.'"

    Comment


    • #3
      Re: RPG Update operation and *in51 pointer

      use monitor

      Like this

      PHP Code:
                                                                   
          monitor
      ;                                                 
           
      workPrice  = %dech(K@VFAC * (cdfact fdgpri):5:2);     
          
      on-error;                                                
           
      workPrice  9999999.9999;                              
          
      endmon
      of after the chain without indicator use

      PHP Code:
       if %error 
      endif; 
      here is more on monitor this is a great function and can handle a gaggle of errors using status codes.
      PHP Code:
                                                                                 
                                                                                 
           d alreadylocked   s               n                                   
           d cmdstring       s            256                                    
           d cmdlength       s             15  5                                 
           d somefield       s              5  0                                 
                                                                                 
           D Locked          C                   00202                           
                                                                                 
             
      //                                                                  
             //  external calls                                                  
             //                                                                  
                                                                                 
           
      d $command        pr                  extpgm('QCMDEXC')               
           
      d   command                    256                                    
           d   Length                      15  5                                 
                                                                                 
            
      /Free                                                                
             
             
      //--------------------------------------------------------                
             // MAIN PROGRAM                                                           
             //--------------------------------------------------------                
                                                                                       
             // create data area to test with                                          
              
      cmdstring 'CRTDTAARA DTAARA(QTEMP/TESTLOCK) TYPE(*CHAR) LEN(10)';      
              
      cmdlength = %len(%trim(cmdstring));                                      
              
      monitor;                                                                 
               
      $command(cmdstringcmdlength);                                         
              
      on-error;                                                                
              
      endmon;                                                                  
                                                                                       
             
      // *Lock it in!                                                           
              
      cmdstring 'ALCOBJ OBJ((QTEMP/TESTLOCK *DTAARA *EXCL))';                
              
      cmdlength = %len(%trim(cmdstring));                                      
                                                                                       
              
      dou Alreadylocked = *off;                                                
              
      monitor;                                                                 
              
      AlreadyLocked = *off;                                                    
              
      $command(cmdstringcmdlength);                 On-error Locked;                                                            
                
      somefield =  %Status;                                                      
                
      AlreadyLocked = *on;                                                       
               
      endmon;                                                                     
               
      enddo;                                                                      
                                                                                           
               *
      inlr = *on;                                                                
                                                                                           
                                                                                           
                                                                                           
            /
      End-Free 
      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


      • #4
        Re: RPG Update operation and *in51 pointer

        Thank you Billw,

        I already tried your solution, but if I use it when an user attemps to update a record already blocked by another user, he waits many seconds before the in*51 pointer of the Chain instruction become *OFF and I would avoit it.

        So, may I put a message on the screen? How may I can make it?

        Thank you!

        BarbaC

        Comment


        • #5
          Re: RPG Update operation and *in51 pointer

          What am I chopped liver

          try here


          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


          • #6
            Re: RPG Update operation and *in51 pointer

            Originally posted by jamief View Post
            What am I chopped liver
            more like a wet noodle LOL
            I'm not anti-social, I just don't like people -Tommy Holden

            Comment


            • #7
              Re: RPG Update operation and *in51 pointer

              Originally posted by barbaC View Post
              Thank you Billw,

              I already tried your solution, but if I use it when an user attemps to update a record already blocked by another user, he waits many seconds before the in*51 pointer of the Chain instruction become *OFF and I would avoit it.

              So, may I put a message on the screen? How may I can make it?

              Thank you!

              BarbaC
              The reason for the wait is because of the default value of WAITRCD on the file description, which is normally set for 60 seconds. If you want to have the record lock condition to report back to the program faster, override the file wait time to something less than this.

              Also, I would seriously look into the error monitors that Jamie posted. Just because you get an error on an update doesnt mean that the record is locked. Using the %status op code will allow you to quickly determine if its a record lock, or some other error.
              Michael Catalani
              IS Director, eCommerce & Web Development
              Acceptance Insurance Corporation
              www.AcceptanceInsurance.com
              www.ProvatoSys.com

              Comment


              • #8
                Re: RPG Update operation and *in51 pointer

                If this is the only program that is updating your file, then try unlocking the file after update.

                §USRCD Chain DATA 51 (Hi)
                *In51 Ifeq *Off
                Update Data
                Unlock Data
                Else
                Wmsg = Errcod
                Endif

                Comment


                • #9
                  Re: RPG Update operation and *in51 pointer

                  no need to Unlock...Update will do that. When you need unlock is when you DON"T update after reading for update.

                  PHP Code:
                  §USRCD        Chain  DATA           51 (Hi)
                  *
                  In51           Ifeq    *Off
                  Fld               Ifeq 
                  'A'                                              I want to update
                                     Update Data
                                     
                  Else
                                     
                  Unlock  Data                                      I don't want to update
                                     Endif
                                     Else
                                     Wmsg = Errcod
                                     Endif 
                  Bill
                  "A good friend will bail you out of jail,
                  A true friend would be sitting beside you saying,
                  'Wow, that was fun.'"

                  Comment

                  Working...
                  X