RPGIV @ Work

A unique site for RPG and System i Lovers

Welcome!

Hi, this site will provide all what you need in System i and RPG developments.

My Name is Chamara Withanachchi, System i Expert and RPG Developer. And in the field for last 11 years.

I hope you will find lot of valuable information from this site

Error Handling Example Print E-mail
User Rating: / 1
PoorBest 
Written by Chamara Withanachchi   
     FCustomer  UF A E           K Disk

     D CustomerData  E DS                  ExtName(Customer:CustRec)
     D CustData        S                   Like(CustomerData)
     D Valid           S               N
     D Total           S              5S 0 Inz(0)
     D StatusCode      S              5S 0 Inz(0)
     D RecordLock      C                   Const(01218)
     D Result2Big      C                   Const(00103)

     C     *Entry        Plist
     C                   Parm                    CustData

      /free

           Monitor;

           CustomerID = %SubSt(CustomerData:1:8);

           DoU %Status <> RecordLock;
              Chain CustomerID Customer;
           EndDo;
              
              If %Found;
                 ExSr Validate;
                 If Valid;
                    Total = Total + 1;  // Accumulate number of udates
                    Update Custrec;     // update record format
                 EndIf;
              Else;
                 ExSr Validate;
                 If Valid;
                 Write Custrec;         // write to record format
                 EndIf;
              Endif;

       // Begin error trapping for any error with Monitor group

              On-Error RecordLock;        // Record Lock
                 Dsply 'Record Locked - Sorry Charlie';

              On-Error *FILE;             // Any other file error
                 StatusCode = %Status;
                 Dsply StatusCode;
                 Dsply 'Some File Error';

              On-Error Result2Big;        // Field not large enough
                 Dsply 'Define the result big enough, goofy';

              On-Error *PROGRAM;          // Any other program error
                 StatusCode = %Status;
                 Dsply StatusCode;
                 Dsply 'Some Program Error';

              On-Error *ALL;              // Any error not already trapped
                 Dsply 'Already trapping *FILE and *PROGRAM - do not need';

           EndMon;

           *InLr = *On;

        // ****************************************************************
        // Validate subroutine - validate data before updating
        // ****************************************************************

           BegSr Validate;

              CustomerData = CustData;
              Valid = *on;   // Some validation, eh?

           EndSr;

      /end-free


User Comments

Please login or register to add comments

<Previous   Next>