ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Error Handling in CBLLE

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

  • Error Handling in CBLLE

    We have some Proof of Concept things going on here and I need some help from the BEST source on the WWW... you guys!!

    I'm going over DataQueues with the Development staff here (Remember, they're COBOL'ers). They are convinced they can't trap Error Messages from within COBOL. I know that you can use the "QlnSetCobolErrorHandler" and the QUS-EC etc... but, I really need a working example of how this is used.

    What's the chance someone here might have a tidbit I can load/compile and prove they can do this?

    Thanks in Advance!!

  • #2
    Re: Error Handling in CBLLE

    What kind of errors are they attempting to trap? If its an error on the api call itself, they can be trapped by passing the API Error data structure to the api call for dataqueues.



    I dont have an example for cobol, but here's an example of the error data structure in RPG.

    Code:
     /if defined(ApiError)                                           
     /eof                                                            
     /endif                                                          
     
     /define ApiError                                                
     
    d ApiError        DS                  Inz Qualified              
    d  Bytes                        10i 0 Inz( %Size( ApiError ))    
    d  BytesAvailable...                                             
    d                               10i 0 Inz                        
    d  ErrorID                       7a   Inz                        
    d  Reserved                      1a   Inz( x'00' )               
    d  MessageData                 128a   Inz
    You would trap for the error in cobol in the same manner, by testing the value of "BytesAvailable" to see if its greater than 0. If it is, then the value of ErrorID will contain the error itself. (They can create this same data structure in cobol. And this data structuer is used for many of the api's, not just data queues. )

    So they can specify this error api data structure on their api calls, and trap for the errors that way.

    Also, this error data structure should be "reset" to its initial state before each api call. In RPG, we do this with the reset opcode

    ie:

    reset ApiError;
    Last edited by MichaelCatalani; April 14, 2011, 04:26 PM.
    Michael Catalani
    IS Director, eCommerce & Web Development
    Acceptance Insurance Corporation
    www.AcceptanceInsurance.com
    www.ProvatoSys.com

    Comment


    • #3
      Re: Error Handling in CBLLE

      Rick,

      You'll get an example of this API in COBOL on this page.
      Philippe

      Comment


      • #4
        Re: Error Handling in CBLLE

        Nice work Philippe I searched for that everywhere but there.
        who would have thought it would be in an IBM COBOL document ???

        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: Error Handling in CBLLE

          Philippe,

          I actually found that one, loaded it and found it doesn't compile without changing

          If Bytes-Available > 0

          To

          If Bytes-Available of QUS-EC > 0

          Then, every time I run it .. I always get the "Error Setting Handler" error message and it stops.

          Should there be a Set Error Handler for the "Old-Error-Handler"?

          ARGH!! (Have I mentioned how much I dislike COBOL??)
          Last edited by FaStOnE; April 15, 2011, 09:48 AM.

          Comment


          • #6
            Re: Error Handling in CBLLE

            For data queue api's, they really should be using the error data structure and passing this to the call of the api. That's why I was asking what kind of errors they were wanting to trap. If it's for the api's, they should use the api error data structure. It is much simpler than using the QlnSetCobolErrorHandler.
            Michael Catalani
            IS Director, eCommerce & Web Development
            Acceptance Insurance Corporation
            www.AcceptanceInsurance.com
            www.ProvatoSys.com

            Comment


            • #7
              Re: Error Handling in CBLLE

              That's just it.. they aren't trapping ANY errors from within their COBOL programs. They're wanting to start using CL Calls to run the jobs, trap for errors then return back to the COBOL program.

              Comment


              • #8
                Re: Error Handling in CBLLE

                Originally posted by FaStOnE View Post
                That's just it.. they aren't trapping ANY errors from within their COBOL programs. They're wanting to start using CL Calls to run the jobs, trap for errors then return back to the COBOL program.
                Ah ,got it. Yea, we probably need to wake up Tom and see if he has an example. I just didnt want you all to use an error handler for data queue api's when the function was performed automatically by the api call itself.
                Michael Catalani
                IS Director, eCommerce & Web Development
                Acceptance Insurance Corporation
                www.AcceptanceInsurance.com
                www.ProvatoSys.com

                Comment


                • #9
                  Re: Error Handling in CBLLE

                  Originally posted by FaStOnE
                  That's just it.. they aren't trapping ANY errors from within their COBOL programs.
                  Yes actually they'd be better off using an error structure defined as
                  Code:
                  COPY QUSEC OF QSYSINC-QCBLLESRC.                           
                      05  EXCEPTION-DATA                      PIC  X(00256).
                  for lack of anything better and initialized as :
                  Code:
                  INITIALIZE QUS-EC.                   
                  MOVE 272 TO BYTES-PROVIDED of qus-ec.
                  at the beginning of the Procedure Division.

                  Originally posted by FaStOnE
                  Then, every time I run it .. I always get the "Error Setting Handler" error message and it stops...
                  You get this message because the software error logging system value is not active on your system. Debug the programs and look at the value of QUS-EC.EXCEPTION-ID field when the message is ready to be displayed. The value is 'CPF93C0'. Display the message text using DSPMSGD CPF93C0. Then as mentionned in the message file if you want the error to be reported in the system log file use CHGSYSVAL QSFWERRLOG(*YES) then run the program again and check what the error handling COBOL program reported in the system log file using WRKPRB.
                  Philippe

                  Comment


                  • #10
                    Re: Error Handling in CBLLE

                    Glad to know we have another Cobol person on the forums.

                    I'm not, by the way, as I last used it in the late '80s. I do have the cobol compiler on my machine though.
                    Michael Catalani
                    IS Director, eCommerce & Web Development
                    Acceptance Insurance Corporation
                    www.AcceptanceInsurance.com
                    www.ProvatoSys.com

                    Comment


                    • #11
                      Re: Error Handling in CBLLE

                      From our system:
                      Code:
                      System value . . . . . :   QSFWERRLOG                        
                      Description  . . . . . :   Software error logging            
                                                                                   
                                                                                   
                      Software errors  . . . . . . :   *LOG           *LOG, *NOLOG
                      Here's the CBLERR2 program as I have it compiled on my system

                      PHP Code:
                             PROCESS NOMONOPRC.
                             
                      IDENTIFICATION DIVISION.
                            ***************************************************************
                            ***************************************************************
                            *
                            *  
                      Program:      Register an ILE COBOL Error Handler
                            
                      *                Cause a decimal data exception to demonstrate
                            
                      *                   logging of software errors
                            
                      *
                            *  
                      Language:     ILE COBOL
                            
                      *
                            *  
                      Description:  This program registers an ILE COBOL Error
                            
                      *                Handler.  After the successful completion of
                            
                      *                the registration of the error handlerthis     ,
                            *                
                      program creates a decimal data errorThis
                            
                      *                exception causes the error handler to be
                            
                      *                called which then logs the software error.
                            *
                            *  
                      APIs Used:    QlnSetCobolErrorHandler
                            
                      *
                            *
                            ***************************************************************
                            *
                            ***************************************************************
                             
                      PROGRAM-IDCBLERR2.
                             
                      ENVIRONMENT DIVISION.
                             
                      CONFIGURATION SECTION.
                               
                      SOURCE-COMPUTERIBM-AS400.
                               
                      OBJECT-COMPUTERIBM-AS400.
                               
                      SPECIAL-NAMES.
                               
                      LINKAGE TYPE PROCEDURE FOR "QlnSetCobolErrorHandler".
                             
                      INPUT-OUTPUT SECTION.
                             
                      FILE-CONTROL.
                             
                      DATA DIVISION.
                             
                      WORKING-STORAGE SECTION.
                            *
                            * 
                      Error Code parameter include.  As this sample program
                            
                      uses COPY to include the error code structureonly the first
                            
                      16 bytes of the error code structure are available.  If the
                            
                      application program needs to access the variable length
                            
                      exception data for the errorthe developer should physically
                            
                      copy the QSYSINC include and modify the copied include to
                            
                      define additional storage for the exception data.
                            *
                             
                      COPY QUSEC OF QSYSINC-QCBLLESRC.
                            *
                            * 
                      Miscellaneous elements
                            
                      *
                             
                      01  MISC.
                                 
                      05  Y               PIC S9(09VALUE 0.
                             01  ERROR
                      -HANDLER       PROCEDURE-POINTER.
                             
                      01  OLD-ERROR-HANDLER   PROCEDURE-POINTER.
                             
                      01  NUMERIC-GROUP.
                                 
                      05  X               PIC  9(03).
                            *
                            * 
                      Beginning of mainline
                            
                      *
                             
                      PROCEDURE DIVISION.
                             
                      MAIN-LINE.
                            *
                            * 
                      Register the COBOL Error Handler.
                            *
                            * 
                      Initialize the error code parameter.  To signal exceptions to
                            
                      this program by the APIyou need to set the bytes provided
                            
                      field of the error code to zero.  Because this program has
                            
                      exceptions sent back through the error code parameterit sets
                            
                      the bytes provided field to the number of bytes it gives the
                            
                      API for the parameter.
                            *
                                 
                      MOVE 16 TO BYTES-PROVIDED of QUS-EC.
                            *
                            * 
                      Set ERROR-HANDLER procedure pointer to entry point of
                            
                      ERRHDL1 *PGM
                            
                      *
                                 
                      SET ERROR-HANDLER TO ENTRY LINKAGE PROGRAM "ERRHDL2".
                            *
                            *
                            * 
                      Call the API to register the exit point.
                            *
                                 
                      CALL "QlnSetCobolErrorHandler" USING ERROR-HANDLER,
                                                                
                      OLD-ERROR-HANDLER,
                                                                
                      QUS-EC.
                            *
                            * If 
                      an exception occursthe API returns the exception in the
                            
                      error code parameter.  The bytes available field is set to
                            
                      zero if no exception occurs and greater than zero if an
                            
                      exception does occur.
                            *
                                 IF 
                      BYTES-AVAILABLE of QUS-EC 0
                                                        DISPLAY 
                      "Error setting handler",
                                                        
                      STOP RUN.
                            *
                            * If 
                      the call to register an error handler is successfulthen
                            
                      cause a the data decimal error (X is initialized to blanks).
                            *
                                 
                      ADD X TO Y.
                            *
                            * 
                      Should not get here due to data decimal error
                            
                      *
                                 
                      STOP RUN.
                            *
                            * 
                      End of MAINLINE
                            

                      Here's the ErrHdl2 program as compiled on my system:

                      PHP Code:
                             PROCESS NOMONOPRC.
                             
                      IDENTIFICATION DIVISION.
                            ***************************************************************
                            ***************************************************************
                            *
                            *  
                      Program:      Log a software error
                            
                      *
                            *  
                      Language:     ILE COBOL
                            
                      *
                            *  
                      Description:  This program receives control for exceptions
                            
                      *                within a COBOL run unit.  This program is used
                            
                      *                in conjunction with CBLERR2.                     ,
                            *                
                      Any exception causes this error handler to be
                            
                      *                called which then logs the software error.
                            *
                            *  
                      APIs Used:    QpdReportSoftwareError
                            
                      *
                            ***************************************************************
                            *
                            ***************************************************************
                             
                      PROGRAM-IDERRHDL2.
                             
                      ENVIRONMENT DIVISION.
                             
                      CONFIGURATION SECTION.
                               
                      SOURCE-COMPUTERIBM-AS400.
                               
                      OBJECT-COMPUTERIBM-AS400.
                               
                      SPECIAL-NAMES.
                               
                      LINKAGE TYPE PROCEDURE FOR "QpdReportSoftwareError".
                             
                      INPUT-OUTPUT SECTION.
                             
                      FILE-CONTROL.
                             
                      DATA DIVISION.
                             
                      WORKING-STORAGE SECTION.
                            *
                            * 
                      Error Code parameter include.  As this sample program
                            
                      uses COPY to include the error code structureonly the first
                            
                      16 bytes of the error code structure are available.  If the
                            
                      application program needs to access the variable length
                            
                      exception data for the errorthe developer should physically
                            
                      copy the QSYSINC include and modify the copied include to
                            
                      define additional storage for the exception data.
                            *
                             
                      COPY QUSEC OF QSYSINC-QCBLLESRC.
                            *
                            * 
                      QpdReportSoftwareError include
                            *
                             
                      COPY QPDSRVPG OF QSYSINC-QCBLLESRC.
                            *
                            * 
                      Miscellaneous elements
                            
                      *
                             
                      01  MISC.
                                 
                      05  NBR-OF-RECORDS   PIC S9(09BINARY VALUE 0.
                                 05  MSG
                      -KEYWORD      PIC  X(03VALUE "MSG".
                             
                      01  PROBLEM-RECORDS.
                                 
                      05  PROBLEM-POINTER  POINTER OCCURS 100 TIMES.
                             
                      LINKAGE SECTION.
                             
                      01  CBL-EXCEPTION-ID     PIC  X(07).
                             
                      01  VALID-RESPONSES      PIC  X(06).
                             
                      01  PGM-IN-ERROR.
                                 
                      05  PGM-NAME         PIC  X(10).
                                 
                      05  LIB-NAME         PIC  X(10).
                             
                      01  SYS-EXCEPTION-ID     PIC  X(07).
                             
                      01  MESSAGE-TEXT         PIC  X(01).
                             
                      01  MESSAGE-LENGTH       PIC S9(09BINARY.
                             
                      01  SYS-OPTION           PIC  X(01).
                             
                      01  ERR-MODULE-NAME      PIC  X(10).
                             
                      01  CBL-PGM-NAME         PIC X(256).
                            *
                            * 
                      Beginning of mainline
                            
                      *
                             
                      PROCEDURE DIVISION USING CBL-EXCEPTION-ID,
                                                      
                      VALID-RESPONSES,
                                                      
                      PGM-IN-ERROR,
                                                      
                      SYS-EXCEPTION-ID,
                                                      
                      MESSAGE-LENGTH,
                                                      
                      SYS-OPTION,
                                                      
                      MESSAGE-TEXT,
                                                      
                      ERR-MODULE-NAME,
                                                      
                      CBL-PGM-NAME.
                             
                      MAIN-LINE.
                            *
                            * 
                      Initialize the error code parameter.  To signal exceptions to
                            
                      this program by the APIyou need to set the bytes provided
                            
                      field of the error code to zero.  Because this program has
                            
                      exceptions sent back through the error code parameterit sets
                            
                      the bytes provided field to the number of bytes it gives the
                            
                      API for the parameter.
                            *
                                 
                      MOVE 16 TO BYTES-PROVIDED of QUS-EC.
                            *
                            * 
                      Record the COBOL Program and Library names
                            
                      *
                                 
                      MOVE 101 TO KEY-FIELD OF QPD-SUSPECTED-PROGRAM.
                                 
                      MOVE 10 TO PROGRAM-NAME-LENGTH OF QPD-SUSPECTED-PROGRAM.
                                 
                      MOVE 10 TO LIBRARY-NAME-LENGTH OF QPD-SUSPECTED-PROGRAM.
                                 
                      SET PROGRAM-NAME OF QPD-SUSPECTED-PROGRAM                       (2)
                                                  
                      TO ADDRESS OF PGM-NAME OF PGM-IN-ERROR.
                                 
                      SET LIBRARY-NAME OF QPD-SUSPECTED-PROGRAM
                                                  TO ADDRESS OF LIB
                      -NAME OF PGM-IN-ERROR.
                                 
                      ADD 1 TO NBR-OF-RECORDS.
                                 
                      SET PROBLEM-POINTER (NBR-OF-RECORDSTO
                                                     ADDRESS OF QPD
                      -SUSPECTED-PROGRAM.
                            *
                            * 
                      Record the message id
                            
                      *
                                 
                      MOVE 200 TO KEY-FIELD OF QPD-SYMPTOM.
                                 
                      MOVE 3 TO KEYWORD-LENGTH OF QPD-SYMPTOM.
                                 
                      MOVE 7 TO DATA-LENGTH OF QPD-SYMPTOM.
                                 
                      MOVE "C" TO DATA-TYPE OF QPD-SYMPTOM.
                                 
                      SET KEYWORD OF QPD-SYMPTOM TO ADDRESS OF MSG-KEYWORD.
                                 
                      SET DATA-FIELD OF QPD-SYMPTOM TO ADDRESS OF SYS-EXCEPTION-ID.
                                 
                      ADD 1 TO NBR-OF-RECORDS.
                                 
                      SET PROBLEM-POINTER (NBR-OF-RECORDSTO
                                                     ADDRESS OF QPD
                      -SYMPTOM.
                            *
                            * For 
                      illustration purposesdump the program object
                            
                      *
                                 
                      MOVE 302 TO KEY-FIELD OF QPD-NAMED-SYSTEM-OBJECT.
                                 
                      MOVE PGM-NAME OF PGM-IN-ERROR
                                               TO OBJECT
                      -NAME OF QPD-NAMED-SYSTEM-OBJECT.
                                 
                      MOVE LIB-NAME OF PGM-IN-ERROR
                                               TO OBJECT
                      -LIBRARY OF QPD-NAMED-SYSTEM-OBJECT.
                                 
                      MOVE "*PGM" TO OBJECT-TYPE OF QPD-NAMED-SYSTEM-OBJECT.
                                 
                      ADD 1 TO NBR-OF-RECORDS.
                                 
                      SET PROBLEM-POINTER (NBR-OF-RECORDSTO
                                                     ADDRESS OF QPD
                      -NAMED-SYSTEM-OBJECT.
                            *
                            * 
                      Call the API to log the software error.
                            *
                                 
                      CALL "QpdReportSoftwareError" USING PROBLEM-RECORDS,
                                                                     
                      NBR-OF-RECORDS,
                                                                     
                      QUS-EC.
                            *
                            * If 
                      an exception occursthe API returns the exception in the
                            
                      error code parameter.  The bytes available field is set to
                            
                      zero if no exception occurs and greater than zero if an
                            
                      exception does occur.
                            *
                                 IF 
                      BYTES-AVAILABLE of QUS-EC 0
                                    DISPLAY 
                      "Cannot log error".
                            *
                            * 
                      End the current run unit
                            
                      *
                                 
                      MOVE "C" TO SYS-OPTION.
                                 
                      STOP RUN.
                            *
                            * 
                      End of MAINLINE
                            

                      A call to CBLERR2 gives:
                      Code:
                      Job 439929/RELLIOTT/QPADEV004M started on 04/18/11 at 06:58:48 in subsystem
                      Error setting handler
                      That's about as far as I can get for testing this....

                      Am I just not holding my mouth right?

                      Comment


                      • #12
                        Re: Error Handling in CBLLE

                        BTW, at V5R4, the IBM copybook QPDSRVPG contains the reserved word OBJECT. This should probably be reported to IBM via a support line call. In the meantime, use the REPLACING keyword to get past the compiler error:

                        Code:
                        COPY QPDSRVPG OF QSYSINC-QCBLLESRC                                                          
                            replacing == OBJECT == by == QPD-OBJECT ==.
                        Since none of the following variables are used within the program...you should be safe:
                        Code:
                        01  QPD-SYSTEM-OBJECT.  
                            05  KEY-FIELD       
                            05  RESERVED        
                            05  OBJECT
                        Terry
                        Last edited by Terry Wincheste; April 19, 2011, 05:25 AM.

                        Comment


                        • #13
                          Re: Error Handling in CBLLE

                          OK, tried this:

                          PHP Code:
                                 COPY QUSEC OF QSYSINC-QCBLLESRC.
                                *
                                * 
                          QpdReportSoftwareError include
                                *
                                 
                          COPY QPDSRVPG OF QSYSINC-QCBLLESRC
                                     Replacing 
                          == Object == by == QPD-OBJECT ==. 
                          But still got the same error as above...

                          Comment


                          • #14
                            Re: Error Handling in CBLLE

                            Replace this statement (in CBLERR2):

                            Code:
                                 MOVE 16 TO BYTES-PROVIDED of QUS-EC.
                            with these two statements:
                            Code:
                                 initialize QUS-EC                                
                                 move length of QUS-EC to BYTES-PROVIDED of QUS-EC
                            Works for me

                            This ensures that the return code area is initialized properly. My personal preference is to cut/paste the QUSEC structure into any of my API programs so that I can define the EXCEPTION-DATA to be whatever is required for a given API. Using the LENGTH OF function to set the BYTES-PROVIDED guarantees that your exception data variable(s) will be included when the API returns its error information.

                            Terry
                            Last edited by Terry Wincheste; April 20, 2011, 04:15 AM.

                            Comment

                            Working...
                            X