Converting To  Anthony Tichonoff Florida Hospital MIS January 2007 With Ease   Multi-Row Fetch
Multi-Row Fetch  <ul><li>Agenda </li></ul><ul><ul><li>Why use multi-row fetching </li></ul></ul><ul><ul><li>What I need to...
Why use multi-row fetching? Converting To Multi-row Fetching With Ease
Why use multi-row fetch <ul><li>Performance Advantages </li></ul><ul><ul><li>Improves Throughput </li></ul></ul><ul><ul><u...
Advantages: Performance Single – Row Fetch Multi – Row Fetch fetch Application DBM1 MSTR IRLM Application DBM1 MSTR IRLM d...
CPU Consumption
Return on Upgrade <ul><li>What does V8 cost you? </li></ul><ul><ul><li>Performance objective is less than 10% average regr...
What you need to know. Converting To Multi-row Fetching With Ease
Requirements for Multi-row <ul><li>Understanding the foundation </li></ul><ul><ul><li>What is a rowset </li></ul></ul><ul>...
What is a rowset? <ul><li>A group of rows for the result table of a query that are returned by a single fetch statement. <...
Declare Syntax Changes rowset-positioning: Default is  WITHOUT ROWSET POSITIONING DECLARE CURSOR Syntax NO SCROLL DECLARE ...
Declare Syntax Example <ul><li>SQL Declare with rowset positioning </li></ul>Declare C1 as the cursor of a query to retrie...
Fetch Syntax Changes fetch-orientation: multiple-row-fetch: rowset-positioned: , FETCH Syntax FETCH INSENSITIVE SENSITIVE ...
Fetch Syntax Example <ul><li>SQL Fetch with rowset positioning </li></ul>Fetch the next rowset <ul><li>Exec SQL </li></ul>...
Host variable arrays <ul><li>Fetching into arrays will return multiple rows in a single API call. </li></ul>PayRoll Row 1 ...
Host variable arrays <ul><ul><li>EXEC SQL DECLARE TEST.PAYROLL TABLE </li></ul></ul><ul><ul><li>( Column_01  CHAR(1)  NOT ...
Error handling multi-row fetch <ul><li>Handling multi-row SQL RC </li></ul><ul><ul><li>SQL RC is the result for the  rowse...
Error handling multi-row fetch <ul><li>Handling multi-row SQL RC  (continue) </li></ul><ul><ul><li>If SQL RC = 0 then  all...
Information from the SQLCA <ul><li>Useful data within the SQLCA after the rowset Fetch. </li></ul><ul><ul><li>SQLCODE </li...
Extras about multi-row fetching. Converting To Multi-row Fetching With Ease
Helpful Extras Tips <ul><li>Keeping track of your multi-row  cursors information </li></ul><ul><ul><li>SQLCODE - per curso...
Helpful Extras Tips <ul><li>How big do we make the arrays </li></ul><ul><ul><li>Appropriate array size your  </li></ul></u...
Helpful Extras Tips <ul><li>Simple error checking for multi-row fetching </li></ul>Fetch Next Rowset From CS1  For :row-li...
How to bridge into multi-row fetching with ease. Converting To Multi-row Fetching With Ease
Bridging to Multi-row fetching <ul><li>Steps to discuss </li></ul><ul><ul><li>Our Plan </li></ul></ul><ul><ul><li>Our Desi...
Bridging to Multi-row fetching <ul><li>Our Plan </li></ul><ul><ul><li>Limit the amount of coding necessary to convert to m...
Bridging to Multi-row fetching <ul><li>Our Design  (Limit the changes) </li></ul><ul><ul><li>What we have </li></ul></ul><...
Bridging to Multi-row fetching <ul><li>Our Design </li></ul><ul><ul><li>Modifying the Declare with a simple syntax change ...
Coding the Working Storage Table Working Storage Cursor Working Storage Don't forget to code your Host Variable Arrays
Coding the Prefetch Check array boundaries Get Next Array Row At the end reset SQL return code Fetch next rowset
Coding the Fetch Before After
Coding the Post-Fetch Just executed the fetch Store rows returned & SQL RC per cursor If RC = 0 or (+100 & no array rows) ...
Coding the Data Moves Let eliminate code changes by using our existing host variables.
Bridging to Multi-row fetching <ul><li>Automation </li></ul><ul><ul><li>The technique, method, or system of operating or c...
Multi-Row Fetch  <ul><li>Points to remember </li></ul><ul><ul><li>Use multi-row fetching for a Return on Upgrade </li></ul...
Questions? Converting To Multi-row Fetching With Ease Thanks for attending. Anthony Tichonoff [email_address] Florida Hosp...
Upcoming SlideShare
Loading in...5
×

Converting to Multi-Row Fetch

2,229

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,229
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
54
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide
  • Multi-row FETCH requires a proper understanding of how to set up the environment in terms of declaring the cursor, setting up the host variable arrays, and performing the FETCH operations. Using multi-row FETCH not only has an impact on how you handle FETCH operations in your application, but also has repercussions on how the positioned UPDATE and positioned DELETE statements are handled. We discuss the details in the following visuals.
  • Converting to Multi-Row Fetch

    1. 1. Converting To Anthony Tichonoff Florida Hospital MIS January 2007 With Ease Multi-Row Fetch
    2. 2. Multi-Row Fetch <ul><li>Agenda </li></ul><ul><ul><li>Why use multi-row fetching </li></ul></ul><ul><ul><li>What I need to know using multi-row fetching </li></ul></ul><ul><ul><li>Extras about multi-row fetching </li></ul></ul><ul><ul><li>How to bridge into multi-row fetching with ease </li></ul></ul>
    3. 3. Why use multi-row fetching? Converting To Multi-row Fetching With Ease
    4. 4. Why use multi-row fetch <ul><li>Performance Advantages </li></ul><ul><ul><li>Improves Throughput </li></ul></ul><ul><ul><ul><li>Fewer database access calls </li></ul></ul></ul><ul><ul><ul><li>Lower network operations </li></ul></ul></ul><ul><ul><li>Lowers CPU consumption </li></ul></ul><ul><ul><li>V8 ROU ( Return On Upgrade ) </li></ul></ul>
    5. 5. Advantages: Performance Single – Row Fetch Multi – Row Fetch fetch Application DBM1 MSTR IRLM Application DBM1 MSTR IRLM declare cursor open cursor close cursor commit declare cursor open cursor close cursor commit fetch
    6. 6. CPU Consumption
    7. 7. Return on Upgrade <ul><li>What does V8 cost you? </li></ul><ul><ul><li>Performance objective is less than 10% average regression. </li></ul></ul><ul><ul><li>Typical customer workload regression is expected to be 5 to 10% higher on average, differing by work load: </li></ul></ul><ul><ul><li>Options with significant potential to offset an expected increase include multi-row fetch, multi-row insert, long term page fix and rebind. </li></ul></ul><ul><li>Return on Upgrade </li></ul>+15% +10% +15% +15% +20% +5% +20% +10% +15% -20% query -5% utility -20% batch DRDA -10% batch data sharing +5% fetch, select, update -5% insert -5% batch -5% transaction in data sharing 0% online transaction
    8. 8. What you need to know. Converting To Multi-row Fetching With Ease
    9. 9. Requirements for Multi-row <ul><li>Understanding the foundation </li></ul><ul><ul><li>What is a rowset </li></ul></ul><ul><ul><li>New SQL syntax </li></ul></ul><ul><ul><ul><li>Declare </li></ul></ul></ul><ul><ul><ul><li>Fetch </li></ul></ul></ul><ul><ul><li>Host variable arrays </li></ul></ul><ul><ul><li>Error handling </li></ul></ul>
    10. 10. What is a rowset? <ul><li>A group of rows for the result table of a query that are returned by a single fetch statement. </li></ul><ul><li>The maximum size of the rowset is 32767 </li></ul><ul><li>The program fetch call controls how many rows are returned in a rowset. </li></ul><ul><li>It is possible to intertwine single-row and multi-row fetches within the same program. </li></ul>Single Fetch Single Row Multiple Fetch Multiple Rows
    11. 11. Declare Syntax Changes rowset-positioning: Default is WITHOUT ROWSET POSITIONING DECLARE CURSOR Syntax NO SCROLL DECLARE cursor-name ASENSITIVE INSENSITIVE SENSITIVE STATIC DYNAMIC SCROLL CURSOR FOR Select-Statement select-name rowset-positioning WITH HOLD WITH RETURN WITHOUT ROWSET POSITIONING WITH ROWSET POSITIONING
    12. 12. Declare Syntax Example <ul><li>SQL Declare with rowset positioning </li></ul>Declare C1 as the cursor of a query to retrieve a rowset from table PayRoll <ul><li>Exec SQL </li></ul><ul><ul><li>Declare C1 Cursor </li></ul></ul><ul><ul><li>With Rowset Positioning For </li></ul></ul><ul><ul><li>Select * </li></ul></ul><ul><ul><li>From PayRoll </li></ul></ul><ul><ul><li>Where …. </li></ul></ul><ul><li>End Exec </li></ul>With Rowset Positioning specifies whether multiple rows of data can be accessed as a rowset on a single Fetch statement
    13. 13. Fetch Syntax Changes fetch-orientation: multiple-row-fetch: rowset-positioned: , FETCH Syntax FETCH INSENSITIVE SENSITIVE fetch-orientation FROM cursor-name single-row-fetch multiple-row fetch rowset-positioned BEFORE AFTER row-positioned NEXT ROWSET PRIOR ROWSET FIRST ROWSET LAST ROWSET CURRENT ROWSET ROWSET STARTING AT ABSOLUTE RELATIVE host-variable integer-constant FOR host-variable integer-constant ROWS INTO INTO DESCRIPTOR host-variable-array descriptor-name
    14. 14. Fetch Syntax Example <ul><li>SQL Fetch with rowset positioning </li></ul>Fetch the next rowset <ul><li>Exec SQL </li></ul><ul><ul><li>Fetch Next Rowset From C1 </li></ul></ul><ul><ul><li>For :Rowset-Limit Rows </li></ul></ul><ul><ul><li>Into </li></ul></ul><ul><ul><ul><li>:HA_C1 </li></ul></ul></ul><ul><ul><ul><li>,:HA_C2 </li></ul></ul></ul><ul><ul><ul><li>,:HA_C3 </li></ul></ul></ul><ul><li>End Exec </li></ul>For :HV Rows is not required. The fetch statement will default to the row limit from the previous fetch statement.
    15. 15. Host variable arrays <ul><li>Fetching into arrays will return multiple rows in a single API call. </li></ul>PayRoll Row 1 Multiple Fetch Fetching Multiple Rows Row 2 Row 3 Row 4 HA 1 HA 2 HA 3 HA 4 HA 5 HA 6 Each host variable array can only point to a single DB2 column Arrays may not be arrays of structures
    16. 16. Host variable arrays <ul><ul><li>EXEC SQL DECLARE TEST.PAYROLL TABLE </li></ul></ul><ul><ul><li>( Column_01 CHAR(1) NOT NULL, </li></ul></ul><ul><ul><li>Column_02 TIMESTAMP NOT NULL, </li></ul></ul><ul><ul><li>Column_03 CHAR(8) NOT NULL, </li></ul></ul><ul><ul><li>Column_04 CHAR(1) NOT NULL, </li></ul></ul><ul><ul><li>Column_05 CHAR(8) NOT NULL, </li></ul></ul><ul><ul><li>) END-EXEC. </li></ul></ul><ul><ul><li>01 DCLHVA. </li></ul></ul><ul><ul><ul><li>05 HVA-Column-01 PIC X(1) OCCURS 100 TIMES. </li></ul></ul></ul><ul><ul><ul><li>05 HVA-Column-02 PIC X(26) OCCURS 100 TIMES. </li></ul></ul></ul><ul><ul><ul><li>05 HVA-Column-03 PIC X(8) OCCURS 100 TIMES. </li></ul></ul></ul><ul><ul><ul><li>05 HVA-Column-04 PIC X(1) OCCURS 100 TIMES. </li></ul></ul></ul><ul><ul><ul><li>05 HVA-Column-05 PIC X(8) OCCURS 100 TIMES. </li></ul></ul></ul><ul><li>Host variable array declaration </li></ul>Arrays may not be arrays of structures
    17. 17. Error handling multi-row fetch <ul><li>Handling multi-row SQL RC </li></ul><ul><ul><li>SQL RC is the result for the rowset not for the row . </li></ul></ul><ul><ul><li>Use the Get Diagnostics statement to return each row’s SQL RC </li></ul></ul>EXEC SQL GET DIAGNOSTICS :rows-returned = Row_Count ,:err-count = Number END-EXEC returns statement information EXEC SQL GET DIAGNOSTICS CONDITION :cond :sqlcode = DB2_Returned_SQLCode ,:sqlstate = Returned_SQLState END-EXEC returns condition information
    18. 18. Error handling multi-row fetch <ul><li>Handling multi-row SQL RC (continue) </li></ul><ul><ul><li>If SQL RC = 0 then all rows within the rowset have a SQL RC = 0. (Get Diagnostics is not necessary) </li></ul></ul><ul><ul><li>If SQL RC = +100 then the EOT has been found, but rows could possibly exists within the host variable array to process. (Get Diagnostics is not necessary) </li></ul></ul><ul><ul><li>Any other RC not equal to 0 or +100 on a rowset we must treat as you have in the past or use Get Diagnostics. </li></ul></ul>
    19. 19. Information from the SQLCA <ul><li>Useful data within the SQLCA after the rowset Fetch. </li></ul><ul><ul><li>SQLCODE </li></ul></ul><ul><ul><li>SQLSTATE </li></ul></ul><ul><ul><li>SQLERRD(3) contains the actual number of row returned. </li></ul></ul><ul><ul><li>SQLWARN flags are set to represent all warnings accumulated while processing the Fetch. </li></ul></ul>
    20. 20. Extras about multi-row fetching. Converting To Multi-row Fetching With Ease
    21. 21. Helpful Extras Tips <ul><li>Keeping track of your multi-row cursors information </li></ul><ul><ul><li>SQLCODE - per cursor </li></ul></ul><ul><ul><li>Rows Returned - per cursor </li></ul></ul><ul><ul><li>Current array position - per cursor </li></ul></ul><ul><ul><li>Max array limits - per table </li></ul></ul><ul><li>Create ways to prevent exceeding your host variable array boundaries </li></ul>
    22. 22. Helpful Extras Tips <ul><li>How big do we make the arrays </li></ul><ul><ul><li>Appropriate array size your </li></ul></ul><ul><ul><ul><li>online apps </li></ul></ul></ul><ul><ul><ul><li>batch apps </li></ul></ul></ul><ul><li>Creating standard host variable array copybooks. </li></ul><ul><ul><li>Add max limits for the array </li></ul></ul>
    23. 23. Helpful Extras Tips <ul><li>Simple error checking for multi-row fetching </li></ul>Fetch Next Rowset From CS1 For :row-limt Rows Into :HVA-1 ,:HVA-2 ,:HVA-3 If (SQLCode = 0 Or SQLCode = 100) And SQLERRD(3) > 0 - Process SQLERRD(3) rows Else If SQLCode = 100 and SQLERRD(3) = 0 - Close Cursor Else Handle SQL Error
    24. 24. How to bridge into multi-row fetching with ease. Converting To Multi-row Fetching With Ease
    25. 25. Bridging to Multi-row fetching <ul><li>Steps to discuss </li></ul><ul><ul><li>Our Plan </li></ul></ul><ul><ul><li>Our Design </li></ul></ul><ul><ul><li>Coding </li></ul></ul><ul><ul><li>Automation </li></ul></ul><ul><ul><li>Execution </li></ul></ul>
    26. 26. Bridging to Multi-row fetching <ul><li>Our Plan </li></ul><ul><ul><li>Limit the amount of coding necessary to convert to multi-row fetch. </li></ul></ul><ul><ul><li>Limit the changes to our error handling. </li></ul></ul><ul><ul><li>Make the changes fit our current program’s architecture framework. </li></ul></ul><ul><ul><li>Keep the changes few and simple. </li></ul></ul>
    27. 27. Bridging to Multi-row fetching <ul><li>Our Design (Limit the changes) </li></ul><ul><ul><li>What we have </li></ul></ul><ul><ul><li>What we want </li></ul></ul><ul><li>Our Goals: </li></ul><ul><ul><li>limit change </li></ul></ul><ul><ul><li>keep it simple </li></ul></ul><ul><li>Declare </li></ul><ul><li>Open </li></ul><ul><li>Fetch </li></ul><ul><li>Loop Until Done </li></ul><ul><ul><li>Process Work </li></ul></ul><ul><ul><li>Fetch Next </li></ul></ul><ul><li>Close </li></ul><ul><li>Declare (syntax changes) </li></ul><ul><li>Open </li></ul><ul><li>Fetch (syntax changes and wrapper) </li></ul><ul><li>Loop Until Done </li></ul><ul><ul><li>Process Work </li></ul></ul><ul><ul><li>Fetch Next </li></ul></ul><ul><li>Close </li></ul>
    28. 28. Bridging to Multi-row fetching <ul><li>Our Design </li></ul><ul><ul><li>Modifying the Declare with a simple syntax change </li></ul></ul><ul><ul><li>Modifying the Fetch… </li></ul></ul>Fetch SQL Statement (Changes made to acquire multi-row fetch) Add Pre-Fetch Code (Handles decision where to get next row) Add Post-Fetch Code (Handles RCs and array positioning) Add Variable Assignments (Move :HVA elements into :HV)
    29. 29. Coding the Working Storage Table Working Storage Cursor Working Storage Don't forget to code your Host Variable Arrays
    30. 30. Coding the Prefetch Check array boundaries Get Next Array Row At the end reset SQL return code Fetch next rowset
    31. 31. Coding the Fetch Before After
    32. 32. Coding the Post-Fetch Just executed the fetch Store rows returned & SQL RC per cursor If RC = 0 or (+100 & no array rows) reset array pointer & SQL code
    33. 33. Coding the Data Moves Let eliminate code changes by using our existing host variables.
    34. 34. Bridging to Multi-row fetching <ul><li>Automation </li></ul><ul><ul><li>The technique, method, or system of operating or controlling a process by highly automatic means, as by electronic devices, reducing human intervention to a minimum. </li></ul></ul><ul><li>My definition </li></ul><ul><ul><li>Lets minimize human error </li></ul></ul><ul><ul><li>Built a Rexx program with ISPF macros to alter existing Cobol code. </li></ul></ul>
    35. 35. Multi-Row Fetch <ul><li>Points to remember </li></ul><ul><ul><li>Use multi-row fetching for a Return on Upgrade </li></ul></ul><ul><ul><li>Know the basics for utilizing multi-row fetch </li></ul></ul><ul><ul><li>Extras about multi-row fetching </li></ul></ul><ul><ul><li>Find ways to quickly convert with little code changes to gain back resources. </li></ul></ul>
    36. 36. Questions? Converting To Multi-row Fetching With Ease Thanks for attending. Anthony Tichonoff [email_address] Florida Hospital MIS Converting To Multi-Row Fetch With Ease
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×