Last active
March 30, 2016 21:15
-
-
Save phpdave/5773a4c20bfad025c01083d7465d61a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Declare the resultset | |
| D rsTable1 S SQLTYPE(RESULT_SET_LOCATOR) | |
| // Declare data structures for data from cursors | |
| D rows DS Qualified Dim(500) | |
| D KEY1 3I 0 | |
| D KEY2 4I 0 | |
| D TOTAL_FIELD3 31I 2 | |
| D TOTAL_FIELD4 31I 2 | |
| D PARM1 S 8I 0 | |
| D PARM2 S 8I 0 | |
| D NumberOfRows S 10I 0 | |
| D CurrentRowNum S 10I 0 | |
| /Free | |
| // Invoke procedure | |
| Exec SQL | |
| CALL SCHEMA.STOREDPROC(:PARM1,:PARM2); | |
| Exec SQL | |
| ASSOCIATE RESULT SET LOCATORS | |
| (:rsTable1) | |
| WITH PROCEDURE SCHEMA.STOREDPROC; | |
| Exec SQL | |
| ALLOCATE C1 CURSOR | |
| FOR RESULT SET :rsTable1; | |
| Exec SQL | |
| Exec SQL FETCH C1 FOR 9999 ROWS INTO :rows; | |
| Exec SQL | |
| CLOSE C1; | |
| //use rows | |
| //Handle errors | |
| select; | |
| when %subst(sqlstt:1:2)='00' or %subst(sqlstt:1:2)='01'; | |
| NumberOfRows = sqlerrd(3); | |
| when %subst(Sqlstt:1:2)='02'; | |
| NumberOfRows = 0; | |
| other; | |
| ErrMsg = 'Error: SQL State ' + SQLSTT; | |
| // show error message to user | |
| endsl; | |
| //Process rows | |
| for CurrentRowNum = 1 to NumberOfRows; | |
| dsply '------------------------'; | |
| dsply rows(CurrentRowNum).KEY1; | |
| dsply rows(CurrentRowNum).KEY2; | |
| dsply rows(CurrentRowNum).TOTAL_FIELD3; | |
| dsply rows(CurrentRowNum).TOTAL_FIELD4; | |
| endfor; | |
| *InLR=*On; | |
| Return; | |
| /End-Free |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment