sql codes decoded

Download SQL Codes Decoded

Post on 13-Dec-2014

1.079 views

Category:

Documents

4 download

Embed Size (px)

DESCRIPTION

 

TRANSCRIPT

  • 1.

2. Where Do We Start? Who? What? When? Where? Why? 3. How Do We Debug?

  • Sources of Debug Information
    • CICS Transaction Abends
    • Batch Abend Codes
    • System Codes
    • Message Logs
    • DB2 SQL Codes

4. Batch Abend Codes

    • The system reports abends in the form Sxxx Uxxxx.
      • The S literally means "System"
      • The U literally means "User".
    • One of the most common items mentioned in the table is "subscript out of range".
      • This refers to any access to a COBOL array with a subscript n, where n is the number of OCCURS.
      • If the program stores data in the array with a subscript, memory outside of the array can be destroyed; perhaps causing a later 0C1, 0C4, 0C7 or 04E.

5. Our Agenda

  • SQL Code Basics
    • Where SQL comes from
    • SQLCode vs. SQLState
    • Good & Bad
  • When Should You Check SQL Codes?
  • SQL Code Checking
    • The code
    • The cause
    • Responsible party
    • Corrective actions
  • Common SQL Codes
    • 000
    • 100
    • -117
    • -180 & 181
    • -501
    • -803
    • -805 & -818
    • -811
    • -904
    • -911
  • Where to Go for Help

6. SQLCA Elements

  • COBOL :
  • 01 SQLCA.
  • 05 SQLCAID PIC X(8).
  • 05 SQLCABC PIC S9(9) COMP-4.
  • 05SQLCODEPIC S9(9) COMP-4.
  • 05 SQLERRM.
    • 49 SQLERRML PIC S9(4) COMP-4.
    • 49 SQLERRMC PIC X(70).
  • 05SQLERRPPIC X(8).
  • 05 SQLERRD OCCURS 6 TIMES PIC S9(9) COMP-4.
  • 05 SQLWARN.
    • 10 SQLWARN0 PIC X.
    • 10 SQLWARN1 PIC X.
    • 10 SQLWARN2 PIC X.
    • 10 SQLWARN3 PIC X.
    • 10 SQLWARN4 PIC X.
    • 10 SQLWARN5 PIC X.
    • 10 SQLWARN6 PIC X.
    • 10 SQLWARN7 PIC X.
    • 05 SQLEXT.
    • 10 SQLWARN8 PIC X.
    • 10 SQLWARN9 PIC X.
    • 10 SQLWARNA PIC X.
    • 10SQLSTATEPIC X(5).

An SQLCA is a structure or collection of variables that is updated after each SQL statement executes. An application program that contains executable SQL statements must provide exactly one SQLCA. 7. Get Diagnostics

  • Available in V8
  • Use for Multi Row Operations
  • Use for support long names
  • Use to retrieve additional information

Use the GET DIAGNOSTICS statement to handle multiple SQL errors that might result from the execution of a single SQL statement. First, check SQLSTATE (or SQLCODE) to determine whether diagnostic information should be retrieved by using GET DIAGNOSTICS. 8. What Does It Look Like? EXEC SQL BEGIN DECLARE SECTION ;long row_count, num_condns, i; long ret_sqlcode, row_num; char ret_sqlstate[6]; ...EXEC SQL END DECLARE SECTION ; ... EXEC SQL INSERT INTO DSN8810.ACT (ACTNO, ACTKWD, ACTDESC) VALUES (:hva1, :hva2, :hva3)FOR 10 ROWS NOT ATOMIC CONTINUE ON SQLEXCEPTION;EXEC SQL GET DIAGNOSTICS:row_count = ROW_COUNT, :num_condns = NUMBER; printf("Number of rows inserted = %d ", row_count);for (i=1; i 0 Execution WasSuccessful If SQLCODE = 0 11. Typical SQL Code History 12. When to Check SQL Codes

  • Check SQL Codes (cont.)
    • Misc
      • GET DIAGNOSTICS
      • CALL
      • CONNECT
      • SET
  • Skip SQL Code Checks
    • BEGIN DECLARE SECTION
    • DECLARE STATEMENT
    • DECLARE TABLE
    • END DECLARE SECTION
    • INCLUDE
    • WHENEVER
  • Check SQL Codes
    • Cursors
      • OPEN
      • FETCH
      • CLOSE
    • Basic I/O
      • SELECT
      • INSERT
      • UPDATE
      • DELETE
    • UOW
      • COMMIT
      • ROLLBACK

13. Matching SQLCODEs to SQL Commonly Handled Could occur but not commonly handled 14. Overview of SQL Calls

    • SQL is transformed to COBOL calls in precompile
    • Host variables loaded before the call
    • DB2 Call is executed
    • SQLCODE gives feedback
      • 0 - OK
      • 0 - warning

0 - Successful Call 0 - Unsuccessful Call EXEC SQL ~~~~~ ~~~~~ ~~~~~ END-EXEC SQLCODE Checks Load Host Variables Call Feedback Static SQL Call Before Call 15. SQL Code Checking

    • Hows It Done
      • Handle expected codes before call
      • Call UT97894P-CHECK-SQLCODE after every SQL call
      • Catch handled codes after
    • Inconsistent SQL Code Checking Leads To
      • breaks program logic
      • weird program errors
      • can extend debugging time

SET WS960-HANDLE-NOTFND TO TRUE EXEC SQL ~~~~~~ ~~~~~~ END-EXEC PERFORM UT97894P-CHECK-SQLCODE THRU UT97894P-CHECK-SQLCODE-EXIT IF WS960-R-NOTFND PERFORM ~~~~~~ THRU ~~~~~~-EXIT END-IF 16. SQL Code Normal SQL Code: 000 17. Standard SQL Code Checking SELECT SQL Code 0 0 ERROR It's All Simple When You Get a Zero 18. Not Found SQL Code: +100 19. Fetch Loop OPEN CURSOR SQL Code FETCH CLOSE SQL Code 0 0 0 0 ERROR = 0

    • If SQLCODE fails (0);
      • 1) existence of no rows
        • SQLCODE = +100
        • INDICATOR-VAR < 0
      • 2) other failure
        • SQLCODE < 0

SET WS960-HANDLE-NOTFND TO TRUE EXEC SQL SELECT COUNT(*) INTO :WS400-NUMB :WS400-INDICATOR-VARIABLE FROM VCP97160 WHERE I_CLIE= :CP160-I-CLIEAND I_CODE = :CP160-I-CODE END-EXEC PERFORM UT97894P-CHECK-SQLCODE THRU UT97894P-CHECK-SQLCODE-EXIT IF (WS960-R-NORMALAND WS400-INDICATOR-VARIABLE >= 0) MOVE WS400-NUMB TO . END-IF This will NEVER return a -811 SQLCODE! 36. #4 Checking for MULTROWs with aSingleton SELECT

  • If SQLCODE is OK (=0);
      • 1) existence of 1 row
        • SQLCODE = 0
    • If SQLCODE fails (0);
      • 1) existence of no rows
        • SQLCODE = +100
      • 2) existence of +1 rows
        • SQLCODE=-811
      • 3) other failure
        • SQLCODE < 0

SET WS960-HANDLE-NOTFND TO TRUE SETWS960-HANDLE-MULTROWTO TRUE EXEC SQL SELECT 1 INTO :WS400-NUMB FROM VCP97160 WHERE I_CLIE= :CP160-I-CLIEAND I_CODE = :CP160-I-CODE END-EXEC PERFORM UT97894P-CHECK-SQLCODE THRU UT97894P-CHECK-SQLCODE-EXIT EVALUATE TRUE WHEN WS960-R-NOTFND . WHENWS960-R-MULTROW . END-EVALUATE 37. #5Returning a Value From Any Row